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.
pull/8982/head
Brian Daniels 2018-12-05 15:26:58 -06:00
parent 1c201b4628
commit 5957ffd306
1 changed files with 33 additions and 14 deletions

View File

@ -1092,17 +1092,37 @@ class Config(object):
"' doesn't have a value") "' doesn't have a value")
@staticmethod @staticmethod
def parameters_to_macros(params): def _parameters_and_config_macros_to_macros(params, macros):
""" Encode the configuration parameters as C macro definitions. """ Return the macro definitions generated for a dictionary of
ConfigParameters and a dictionary of ConfigMacros (as returned by
get_config_data). The ConfigMacros override any matching macros set by
the ConfigParameters.
Positional arguments: Positional arguments:
params - a dictionary mapping a name to a ConfigParameter params - a dictionary mapping a name to a ConfigParameter
macros - a dictionary mapping a name to a ConfigMacro
Return: a list of strings that encode the configuration parameters as Return: a list of strings that are the C pre-processor macros
C pre-processor macros
""" """
return ['%s=%s' % (m.macro_name, m.value) for m in params.values() all_macros = {
if m.value is not None] p.macro_name: p.value for p in params.values() if p.value is not None
}
config_macros = {
m.macro_name: m.macro_value for m in macros.values()
}
all_macros.update(config_macros)
macro_list = []
for name, value in all_macros.items():
# If the macro does not have a value, just append the name.
# Otherwise, append the macro as NAME=VALUE
if value is None:
macro_list.append(name)
else:
macro_list.append("%s=%s" % (name, value))
return macro_list
@staticmethod @staticmethod
def config_macros_to_macros(macros): def config_macros_to_macros(macros):
@ -1126,8 +1146,7 @@ class Config(object):
""" """
params, macros = config[0], config[1] params, macros = config[0], config[1]
Config._check_required_parameters(params) Config._check_required_parameters(params)
return Config.config_macros_to_macros(macros) + \ return Config._parameters_and_config_macros_to_macros(params, macros)
Config.parameters_to_macros(params)
def get_config_data_macros(self): def get_config_data_macros(self):
""" Convert a Config object to a list of C macros """ Convert a Config object to a list of C macros