@@ -354,7 +354,8 @@ def get_config_data(self):
354
354
return all_params , macros
355
355
356
356
# Helper: verify if there are any required parameters without a value in 'params'
357
- def _check_required_parameters (self , params ):
357
+ @staticmethod
358
+ def _check_required_parameters (params ):
358
359
for p in params .values ():
359
360
if p .required and (p .value is None ):
360
361
raise ConfigException ("Required parameter '%s' defined by '%s' doesn't have a value" % (p .name , p .defined_by ))
@@ -371,11 +372,18 @@ def parameters_to_macros(params):
371
372
def config_macros_to_macros (macros ):
372
373
return [m .name for m in macros .values ()]
373
374
375
+ # Return the configuration data converted to a list of C macros
376
+ # config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
377
+ # (as returned by get_config_data())
378
+ @staticmethod
379
+ def config_to_macros (config ):
380
+ params , macros = config [0 ], config [1 ]
381
+ Config ._check_required_parameters (params )
382
+ return Config .config_macros_to_macros (macros ) + Config .parameters_to_macros (params )
383
+
374
384
# Return the configuration data converted to a list of C macros
375
385
def get_config_data_macros (self ):
376
- params , macros = self .get_config_data ()
377
- self ._check_required_parameters (params )
378
- return self .config_macros_to_macros (macros ) + self .parameters_to_macros (params )
386
+ return self .config_to_macros (self .get_config_data ())
379
387
380
388
# Returns any features in the configuration data
381
389
def get_features (self ):
@@ -419,14 +427,16 @@ def load_resources(self, resources):
419
427
420
428
return resources
421
429
422
-
423
430
# Return the configuration data converted to the content of a C header file,
424
431
# meant to be included to a C/C++ file. The content is returned as a string.
425
432
# If 'fname' is given, the content is also written to the file called "fname".
426
433
# WARNING: if 'fname' names an existing file, that file will be overwritten!
427
- def get_config_data_header (self , fname = None ):
428
- params , macros = self .get_config_data ()
429
- self ._check_required_parameters (params )
434
+ # config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
435
+ # (as returned by get_config_data())
436
+ @staticmethod
437
+ def config_to_header (config , fname = None ):
438
+ params , macros = config [0 ], config [1 ]
439
+ Config ._check_required_parameters (params )
430
440
header_data = "// Automatically generated configuration file.\n "
431
441
header_data += "// DO NOT EDIT, content will be overwritten.\n \n "
432
442
header_data += "#ifndef __MBED_CONFIG_DATA__\n "
@@ -459,3 +469,10 @@ def get_config_data_header(self, fname = None):
459
469
with open (fname , "wt" ) as f :
460
470
f .write (header_data )
461
471
return header_data
472
+
473
+ # Return the configuration data converted to the content of a C header file,
474
+ # meant to be included to a C/C++ file. The content is returned as a string.
475
+ # If 'fname' is given, the content is also written to the file called "fname".
476
+ # WARNING: if 'fname' names an existing file, that file will be overwritten!
477
+ def get_config_data_header (self , fname = None ):
478
+ return self .config_to_header (self .get_config_data (), fname )
0 commit comments