@@ -143,8 +143,12 @@ class Config:
143
143
# Allowed keys in configuration dictionaries
144
144
# (targets can have any kind of keys, so this validation is not applicable to them)
145
145
__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 ]),
148
152
}
149
153
150
154
# The initialization arguments for Config are:
@@ -176,6 +180,7 @@ def __init__(self, target, top_level_dirs = []):
176
180
self .processed_configs = {}
177
181
self .target = target if isinstance (target , str ) else target .name
178
182
self .target_labels = Target .get_target (self .target ).get_labels ()
183
+ self .target_instance = Target .get_target (self .target )
179
184
180
185
# Add one or more configuration files
181
186
def add_config_files (self , flist ):
@@ -272,6 +277,20 @@ def _process_macros(self, mlist, macros, unit_name, unit_kind):
272
277
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 ))
273
278
macros [m .macro_name ] = m
274
279
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
+
275
294
# Read and interpret configuration data defined by libs
276
295
# It is assumed that "add_config_files" above was already called and the library configuration data
277
296
# exists in self.lib_config_data
@@ -282,6 +301,7 @@ def get_lib_config_data(self):
282
301
if unknown_keys :
283
302
raise ConfigException ("Unknown key(s) '%s' in %s" % ("," .join (unknown_keys ), lib_name ))
284
303
all_params .update (self ._process_config_and_overrides (lib_data , {}, lib_name , "library" ))
304
+ self ._process_attributes (lib_data , lib_name , "library" )
285
305
self ._process_macros (lib_data .get ("macros" , []), macros , lib_name , "library" )
286
306
return all_params , macros
287
307
@@ -293,6 +313,8 @@ def get_app_config_data(self, params, macros):
293
313
app_cfg = self .app_config_data
294
314
# The application can have a "config_parameters" and a "target_config_overrides" section just like a library
295
315
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" )
296
318
# The application can also defined macros
297
319
self ._process_macros (app_cfg .get ("macros" , []), macros , "app" , "application" )
298
320
0 commit comments