Skip to content

Commit 36904fa

Browse files
committed
[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
1 parent e3bde44 commit 36904fa

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

tools/config.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,8 @@ 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-
+ [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]),
146+
"library": set(["name", "config", "target_overrides", "macros", "__config_path"]),
147+
"application": set(["config", "custom_targets", "target_overrides", "macros", "__config_path"])
152148
}
153149

154150
# The initialization arguments for Config are:
@@ -226,6 +222,22 @@ def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
226222
for label, overrides in data.get("target_overrides", {}).items():
227223
# If the label is defined by the target or it has the special value "*", process the overrides
228224
if (label == '*') or (label in self.target_labels):
225+
# Parse out cumulative attributes
226+
for attr in Target._Target__cumulative_attributes:
227+
attrs = getattr(self.target_instance, attr)
228+
229+
if attr+'_add' in overrides:
230+
attrs.extend(overrides[attr+'_add'])
231+
del overrides[attr+'_add']
232+
233+
if attr+'_remove' in overrides:
234+
for a in overrides[attr+'_remove']:
235+
attrs.remove(a)
236+
del overrides[attr+'_remove']
237+
238+
setattr(self.target_instance, attr, attrs)
239+
240+
# Consider the others as overrides
229241
for name, v in overrides.items():
230242
# Get the full name of the parameter
231243
full_name = ConfigParameter.get_full_name(name, unit_name, unit_kind, label)
@@ -277,20 +289,6 @@ def _process_macros(self, mlist, macros, unit_name, unit_kind):
277289
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))
278290
macros[m.macro_name] = m
279291

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-
294292
# Read and interpret configuration data defined by libs
295293
# It is assumed that "add_config_files" above was already called and the library configuration data
296294
# exists in self.lib_config_data
@@ -301,7 +299,6 @@ def get_lib_config_data(self):
301299
if unknown_keys:
302300
raise ConfigException("Unknown key(s) '%s' in %s" % (",".join(unknown_keys), lib_name))
303301
all_params.update(self._process_config_and_overrides(lib_data, {}, lib_name, "library"))
304-
self._process_attributes(lib_data, lib_name, "library")
305302
self._process_macros(lib_data.get("macros", []), macros, lib_name, "library")
306303
return all_params, macros
307304

@@ -313,8 +310,6 @@ def get_app_config_data(self, params, macros):
313310
app_cfg = self.app_config_data
314311
# The application can have a "config_parameters" and a "target_config_overrides" section just like a library
315312
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")
318313
# The application can also defined macros
319314
self._process_macros(app_cfg.get("macros", []), macros, "app", "application")
320315

0 commit comments

Comments
 (0)