Skip to content

Commit e3bde44

Browse files
committed
[build tools] Added support for cumulative attributes in configs directly
in mbed_lib.json: { "name": "cmsis-nodejs-SQL-x86", "features_add": ["SMELLS_FUNNY"], "features_remove": ["SMELLS_NICE"], "device_has": ["SILLY_STRING", "FIRE"] }
1 parent 52e93ae commit e3bde44

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tools/config.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,12 @@ class Config:
143143
# Allowed keys in configuration dictionaries
144144
# (targets can have any kind of keys, so this validation is not applicable to them)
145145
__allowed_keys = {
146-
"library": set(["name", "config", "target_overrides", "macros", "__config_path"]),
147-
"application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"])
146+
"library": set(["name", "config", "target_overrides", "macros", "__config_path"]
147+
+ [a+'_add' for a in Target._Target__cumulative_attributes]
148+
+ [a+'_remove' for a in Target._Target__cumulative_attributes]),
149+
"application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"]
150+
+ [a+'_add' for a in Target._Target__cumulative_attributes]
151+
+ [a+'_remove' for a in Target._Target__cumulative_attributes]),
148152
}
149153

150154
# The initialization arguments for Config are:
@@ -176,6 +180,7 @@ def __init__(self, target, top_level_dirs = []):
176180
self.processed_configs = {}
177181
self.target = target if isinstance(target, str) else target.name
178182
self.target_labels = Target.get_target(self.target).get_labels()
183+
self.target_instance = Target.get_target(self.target)
179184

180185
# Add one or more configuration files
181186
def add_config_files(self, flist):
@@ -272,6 +277,20 @@ def _process_macros(self, mlist, macros, unit_name, unit_kind):
272277
raise ConfigException("Macro '%s' defined in both '%s' and '%s' with incompatible values" % (m.macro_name, macros[m.macro_name].defined_by, full_unit_name))
273278
macros[m.macro_name] = m
274279

280+
# Helper function: process target attributes in config files
281+
# data: dict of cumulative attributes
282+
# unit_name: the unit (library/application) that defines this macro
283+
# unit_kind: the kind of the unit ("library" or "application")
284+
def _process_attributes(self, data, unit_name, unit_kind):
285+
for attr in Target._Target__cumulative_attributes:
286+
attrs = getattr(self.target_instance, attr)
287+
288+
attrs.extend(data.get(attr+'_add', []))
289+
for a in data.get(attr+'_remove', []):
290+
attrs.remove(a)
291+
292+
setattr(self.target_instance, attr, attrs)
293+
275294
# Read and interpret configuration data defined by libs
276295
# It is assumed that "add_config_files" above was already called and the library configuration data
277296
# exists in self.lib_config_data
@@ -282,6 +301,7 @@ def get_lib_config_data(self):
282301
if unknown_keys:
283302
raise ConfigException("Unknown key(s) '%s' in %s" % (",".join(unknown_keys), lib_name))
284303
all_params.update(self._process_config_and_overrides(lib_data, {}, lib_name, "library"))
304+
self._process_attributes(lib_data, lib_name, "library")
285305
self._process_macros(lib_data.get("macros", []), macros, lib_name, "library")
286306
return all_params, macros
287307

@@ -293,6 +313,8 @@ def get_app_config_data(self, params, macros):
293313
app_cfg = self.app_config_data
294314
# The application can have a "config_parameters" and a "target_config_overrides" section just like a library
295315
self._process_config_and_overrides(app_cfg, params, "app", "application")
316+
# The application can also defined attributes
317+
self._process_attributes(app_cfg, "app", "application")
296318
# The application can also defined macros
297319
self._process_macros(app_cfg.get("macros", []), macros, "app", "application")
298320

0 commit comments

Comments
 (0)