Skip to content

Commit 5812ae7

Browse files
bridadanCruz Monrreal II
authored andcommitted
Ensure macros and parameters with the same name are not repeated.
This covers the case when a macro is set with the same name as a parameter. Previously, the macro would be repeated on the command line, which causes certain toolchains to break (ex. IAR assembler). Now the config system will override the parameter's value with the macro's value.
1 parent ef7df31 commit 5812ae7

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

tools/config/__init__.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -650,21 +650,21 @@ def _get_mem_specs(self, memories, cmsis_part, exception_text):
650650
raise ConfigException(exception_text)
651651

652652
def get_all_active_memories(self, memory_list):
653-
"""Get information of all available rom/ram memories in the form of dictionary
654-
{Memory: [start_addr, size]}. Takes in the argument, a list of all available
653+
"""Get information of all available rom/ram memories in the form of dictionary
654+
{Memory: [start_addr, size]}. Takes in the argument, a list of all available
655655
regions within the ram/rom memory"""
656656
# Override rom_start/rom_size
657657
#
658658
# This is usually done for a target which:
659659
# 1. Doesn't support CMSIS pack, or
660660
# 2. Supports TrustZone and user needs to change its flash partition
661-
661+
662662
available_memories = {}
663663
# Counter to keep track of ROM/RAM memories supported by target
664664
active_memory_counter = 0
665665
# Find which memory we are dealing with, RAM/ROM
666666
active_memory = 'ROM' if any('ROM' in mem_list for mem_list in memory_list) else 'RAM'
667-
667+
668668
try:
669669
cmsis_part = self._get_cmsis_part()
670670
except ConfigException:
@@ -683,7 +683,7 @@ def get_all_active_memories(self, memory_list):
683683

684684
present_memories = set(cmsis_part['memory'].keys())
685685
valid_memories = set(memory_list).intersection(present_memories)
686-
686+
687687
for memory in valid_memories:
688688
mem_start, mem_size = self._get_mem_specs(
689689
[memory],
@@ -709,7 +709,7 @@ def get_all_active_memories(self, memory_list):
709709
mem_start = int(mem_start, 0)
710710
mem_size = int(mem_size, 0)
711711
available_memories[memory] = [mem_start, mem_size]
712-
712+
713713
return available_memories
714714

715715
@property
@@ -1078,17 +1078,37 @@ def _check_required_parameters(params):
10781078
"' doesn't have a value")
10791079

10801080
@staticmethod
1081-
def parameters_to_macros(params):
1082-
""" Encode the configuration parameters as C macro definitions.
1081+
def _parameters_and_config_macros_to_macros(params, macros):
1082+
""" Return the macro definitions generated for a dictionary of
1083+
ConfigParameters and a dictionary of ConfigMacros (as returned by
1084+
get_config_data). The ConfigMacros override any matching macros set by
1085+
the ConfigParameters.
10831086
10841087
Positional arguments:
10851088
params - a dictionary mapping a name to a ConfigParameter
1089+
macros - a dictionary mapping a name to a ConfigMacro
10861090
1087-
Return: a list of strings that encode the configuration parameters as
1088-
C pre-processor macros
1091+
Return: a list of strings that are the C pre-processor macros
10891092
"""
1090-
return ['%s=%s' % (m.macro_name, m.value) for m in params.values()
1091-
if m.value is not None]
1093+
all_macros = {
1094+
p.macro_name: p.value for p in params.values() if p.value is not None
1095+
}
1096+
1097+
config_macros = {
1098+
m.macro_name: m.macro_value for m in macros.values()
1099+
}
1100+
1101+
all_macros.update(config_macros)
1102+
macro_list = []
1103+
for name, value in all_macros.items():
1104+
# If the macro does not have a value, just append the name.
1105+
# Otherwise, append the macro as NAME=VALUE
1106+
if value is None:
1107+
macro_list.append(name)
1108+
else:
1109+
macro_list.append("%s=%s" % (name, value))
1110+
1111+
return macro_list
10921112

10931113
@staticmethod
10941114
def config_macros_to_macros(macros):
@@ -1112,8 +1132,7 @@ def config_to_macros(config):
11121132
"""
11131133
params, macros = config[0], config[1]
11141134
Config._check_required_parameters(params)
1115-
return Config.config_macros_to_macros(macros) + \
1116-
Config.parameters_to_macros(params)
1135+
return Config._parameters_and_config_macros_to_macros(params, macros)
11171136

11181137
def get_config_data_macros(self):
11191138
""" Convert a Config object to a list of C macros

0 commit comments

Comments
 (0)