Skip to content

Commit 5957ffd

Browse files
committed
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 1c201b4 commit 5957ffd

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
@@ -1092,17 +1092,37 @@ def _check_required_parameters(params):
10921092
"' doesn't have a value")
10931093

10941094
@staticmethod
1095-
def parameters_to_macros(params):
1096-
""" Encode the configuration parameters as C macro definitions.
1095+
def _parameters_and_config_macros_to_macros(params, macros):
1096+
""" Return the macro definitions generated for a dictionary of
1097+
ConfigParameters and a dictionary of ConfigMacros (as returned by
1098+
get_config_data). The ConfigMacros override any matching macros set by
1099+
the ConfigParameters.
10971100
10981101
Positional arguments:
10991102
params - a dictionary mapping a name to a ConfigParameter
1103+
macros - a dictionary mapping a name to a ConfigMacro
11001104
1101-
Return: a list of strings that encode the configuration parameters as
1102-
C pre-processor macros
1105+
Return: a list of strings that are the C pre-processor macros
11031106
"""
1104-
return ['%s=%s' % (m.macro_name, m.value) for m in params.values()
1105-
if m.value is not None]
1107+
all_macros = {
1108+
p.macro_name: p.value for p in params.values() if p.value is not None
1109+
}
1110+
1111+
config_macros = {
1112+
m.macro_name: m.macro_value for m in macros.values()
1113+
}
1114+
1115+
all_macros.update(config_macros)
1116+
macro_list = []
1117+
for name, value in all_macros.items():
1118+
# If the macro does not have a value, just append the name.
1119+
# Otherwise, append the macro as NAME=VALUE
1120+
if value is None:
1121+
macro_list.append(name)
1122+
else:
1123+
macro_list.append("%s=%s" % (name, value))
1124+
1125+
return macro_list
11061126

11071127
@staticmethod
11081128
def config_macros_to_macros(macros):
@@ -1126,8 +1146,7 @@ def config_to_macros(config):
11261146
"""
11271147
params, macros = config[0], config[1]
11281148
Config._check_required_parameters(params)
1129-
return Config.config_macros_to_macros(macros) + \
1130-
Config.parameters_to_macros(params)
1149+
return Config._parameters_and_config_macros_to_macros(params, macros)
11311150

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

0 commit comments

Comments
 (0)