From 7678a16b39bcb81e5af8d1c833b4ea4e034b0d17 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 10 Jun 2016 06:36:17 -0500 Subject: [PATCH 1/3] [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"] } --- tools/config.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/config.py b/tools/config.py index a152e62cd1..0fc1719753 100644 --- a/tools/config.py +++ b/tools/config.py @@ -143,8 +143,12 @@ class Config: # Allowed keys in configuration dictionaries # (targets can have any kind of keys, so this validation is not applicable to them) __allowed_keys = { - "library": set(["name", "config", "target_overrides", "macros", "__config_path"]), - "application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"]) + "library": set(["name", "config", "target_overrides", "macros", "__config_path"] + + [a+'_add' for a in Target._Target__cumulative_attributes] + + [a+'_remove' for a in Target._Target__cumulative_attributes]), + "application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"] + + [a+'_add' for a in Target._Target__cumulative_attributes] + + [a+'_remove' for a in Target._Target__cumulative_attributes]), } # The initialization arguments for Config are: @@ -176,6 +180,7 @@ class Config: self.processed_configs = {} self.target = target if isinstance(target, str) else target.name self.target_labels = Target.get_target(self.target).get_labels() + self.target_instance = Target.get_target(self.target) # Add one or more configuration files def add_config_files(self, flist): @@ -272,6 +277,20 @@ class Config: 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)) macros[m.macro_name] = m + # Helper function: process target attributes in config files + # data: dict of cumulative attributes + # unit_name: the unit (library/application) that defines this macro + # unit_kind: the kind of the unit ("library" or "application") + def _process_attributes(self, data, unit_name, unit_kind): + for attr in Target._Target__cumulative_attributes: + attrs = getattr(self.target_instance, attr) + + attrs.extend(data.get(attr+'_add', [])) + for a in data.get(attr+'_remove', []): + attrs.remove(a) + + setattr(self.target_instance, attr, attrs) + # Read and interpret configuration data defined by libs # It is assumed that "add_config_files" above was already called and the library configuration data # exists in self.lib_config_data @@ -282,6 +301,7 @@ class Config: if unknown_keys: raise ConfigException("Unknown key(s) '%s' in %s" % (",".join(unknown_keys), lib_name)) all_params.update(self._process_config_and_overrides(lib_data, {}, lib_name, "library")) + self._process_attributes(lib_data, lib_name, "library") self._process_macros(lib_data.get("macros", []), macros, lib_name, "library") return all_params, macros @@ -293,6 +313,8 @@ class Config: app_cfg = self.app_config_data # The application can have a "config_parameters" and a "target_config_overrides" section just like a library self._process_config_and_overrides(app_cfg, params, "app", "application") + # The application can also defined attributes + self._process_attributes(app_cfg, "app", "application") # The application can also defined macros self._process_macros(app_cfg.get("macros", []), macros, "app", "application") From 2fa2e715fc392ebceb9af2b25a270e2ec75106f3 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 11 Jun 2016 15:26:42 -0500 Subject: [PATCH 2/3] [build tools] Moved cumulative attributes into target overrides Attributes now get the filtering provided by target_overrides: { "name": "cmsis-nodejs-SQL-x86", "target_overrides": { "*": { "device_has": ["SILLY_STRING", "FIRE"] }, "SHOE": { "features_add": ["SMELLS_FUNNY"], "features_remove": ["SMELLS_NICE"], } } } per @screamerbg --- tools/config.py | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/tools/config.py b/tools/config.py index 0fc1719753..8ed96964ae 100644 --- a/tools/config.py +++ b/tools/config.py @@ -143,12 +143,8 @@ class Config: # Allowed keys in configuration dictionaries # (targets can have any kind of keys, so this validation is not applicable to them) __allowed_keys = { - "library": set(["name", "config", "target_overrides", "macros", "__config_path"] - + [a+'_add' for a in Target._Target__cumulative_attributes] - + [a+'_remove' for a in Target._Target__cumulative_attributes]), - "application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"] - + [a+'_add' for a in Target._Target__cumulative_attributes] - + [a+'_remove' for a in Target._Target__cumulative_attributes]), + "library": set(["name", "config", "target_overrides", "macros", "__config_path"]), + "application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"]) } # The initialization arguments for Config are: @@ -226,6 +222,22 @@ class Config: for label, overrides in data.get("target_overrides", {}).items(): # If the label is defined by the target or it has the special value "*", process the overrides if (label == '*') or (label in self.target_labels): + # Parse out cumulative attributes + for attr in Target._Target__cumulative_attributes: + attrs = getattr(self.target_instance, attr) + + if attr+'_add' in overrides: + attrs.extend(overrides[attr+'_add']) + del overrides[attr+'_add'] + + if attr+'_remove' in overrides: + for a in overrides[attr+'_remove']: + attrs.remove(a) + del overrides[attr+'_remove'] + + setattr(self.target_instance, attr, attrs) + + # Consider the others as overrides for name, v in overrides.items(): # Get the full name of the parameter full_name = ConfigParameter.get_full_name(name, unit_name, unit_kind, label) @@ -277,20 +289,6 @@ class Config: 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)) macros[m.macro_name] = m - # Helper function: process target attributes in config files - # data: dict of cumulative attributes - # unit_name: the unit (library/application) that defines this macro - # unit_kind: the kind of the unit ("library" or "application") - def _process_attributes(self, data, unit_name, unit_kind): - for attr in Target._Target__cumulative_attributes: - attrs = getattr(self.target_instance, attr) - - attrs.extend(data.get(attr+'_add', [])) - for a in data.get(attr+'_remove', []): - attrs.remove(a) - - setattr(self.target_instance, attr, attrs) - # Read and interpret configuration data defined by libs # It is assumed that "add_config_files" above was already called and the library configuration data # exists in self.lib_config_data @@ -301,7 +299,6 @@ class Config: if unknown_keys: raise ConfigException("Unknown key(s) '%s' in %s" % (",".join(unknown_keys), lib_name)) all_params.update(self._process_config_and_overrides(lib_data, {}, lib_name, "library")) - self._process_attributes(lib_data, lib_name, "library") self._process_macros(lib_data.get("macros", []), macros, lib_name, "library") return all_params, macros @@ -313,8 +310,6 @@ class Config: app_cfg = self.app_config_data # The application can have a "config_parameters" and a "target_config_overrides" section just like a library self._process_config_and_overrides(app_cfg, params, "app", "application") - # The application can also defined attributes - self._process_attributes(app_cfg, "app", "application") # The application can also defined macros self._process_macros(app_cfg.get("macros", []), macros, "app", "application") From 177f2930c255f151f499863682748bc6eda1117b Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 11 Jun 2016 15:43:59 -0500 Subject: [PATCH 3/3] [build tools] Added support for completely overriding cumulative attributes --- tools/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/config.py b/tools/config.py index 8ed96964ae..66b1035036 100644 --- a/tools/config.py +++ b/tools/config.py @@ -226,6 +226,11 @@ class Config: for attr in Target._Target__cumulative_attributes: attrs = getattr(self.target_instance, attr) + if attr in overrides: + del attrs[:] + attrs.extend(overrides[attr]) + del overrides[attr] + if attr+'_add' in overrides: attrs.extend(overrides[attr+'_add']) del overrides[attr+'_add']