Skip to content

Commit 89bb38f

Browse files
committed
Fixed exporters to support features
Unified how resources are loaded into the configuration system (Config.load_resources) and applied it to build_api and exporters
1 parent 1e18ea2 commit 89bb38f

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

tools/build_api.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,8 @@ def build_project(src_path, build_path, target, toolchain_name,
214214
else:
215215
resources.inc_dirs.append(inc_dirs)
216216

217-
# Update configuration files until added features creates no changes
218-
prev_features = set()
219-
while True:
220-
# Update the configuration with any .json files found while scanning
221-
config.add_config_files(resources.json_files)
222-
223-
# Add features while we find new ones
224-
features = config.get_features()
225-
if features == prev_features:
226-
break
227-
228-
for feature in features:
229-
if feature in resources.features:
230-
resources.add(resources.features[feature])
231-
232-
prev_features = features
233-
config.validate_config()
217+
# Load resources into the config system which might expand/modify resources based on config data
218+
resources = config.load_resources(resources)
234219

235220
# Set the toolchain's config header with the config data
236221
toolchain.set_config_header_content(config.get_config_data_header())
@@ -373,23 +358,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
373358
# Handle configuration
374359
config = Config(target)
375360

376-
# Update configuration files until added features creates no changes
377-
prev_features = set()
378-
while True:
379-
# Update the configuration with any .json files found while scanning
380-
config.add_config_files(resources.json_files)
381-
382-
# Add features while we find new ones
383-
features = config.get_features()
384-
if features == prev_features:
385-
break
386-
387-
for feature in features:
388-
if feature in resources.features:
389-
resources.add(resources.features[feature])
390-
391-
prev_features = features
392-
config.validate_config()
361+
# Load resources into the config system which might expand/modify resources based on config data
362+
resources = config.load_resources(resources)
393363

394364
# Set the toolchain's config header with the config data
395365
toolchain.set_config_header_content(config.get_config_data_header())

tools/config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,30 @@ def validate_config(self):
396396
raise self.config_errors[0]
397397
return True
398398

399+
400+
# Loads configuration data from resources. Also expands resources based on defined features settings
401+
def load_resources(self, resources):
402+
# Update configuration files until added features creates no changes
403+
prev_features = set()
404+
while True:
405+
# Add/update the configuration with any .json files found while scanning
406+
self.add_config_files(resources.json_files)
407+
408+
# Add features while we find new ones
409+
features = self.get_features()
410+
if features == prev_features:
411+
break
412+
413+
for feature in features:
414+
if feature in resources.features:
415+
resources.add(resources.features[feature])
416+
417+
prev_features = features
418+
self.validate_config()
419+
420+
return resources
421+
422+
399423
# Return the configuration data converted to the content of a C header file,
400424
# meant to be included to a C/C++ file. The content is returned as a string.
401425
# If 'fname' is given, the content is also written to the file called "fname".

tools/export/exporters.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
129129
# Copy only the file for the required target and toolchain
130130
lib_builds = []
131131
# Create the configuration object
132-
cfg = Config(self.target, prj_paths)
132+
config = Config(self.target, prj_paths)
133133
for src in ['lib', 'src']:
134134
resources = reduce(add, [self.__scan_and_copy(join(path, src), trg_path) for path in prj_paths])
135135
lib_builds.extend(resources.lib_builds)
@@ -155,15 +155,20 @@ def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
155155

156156
if not relative:
157157
# Final scan of the actual exported resources
158-
self.resources = self.toolchain.scan_resources(trg_path)
159-
self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
158+
resources = self.toolchain.scan_resources(trg_path)
159+
resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
160160
else:
161161
# use the prj_dir (source, not destination)
162-
self.resources = reduce(add, [self.toolchain.scan_resources(path) for path in prj_paths])
163-
# Add all JSON files discovered during scanning to the configuration object
164-
cfg.add_config_files(self.resources.json_files)
165-
# Get data from the configuration system
166-
self.config_macros = cfg.get_config_data_macros()
162+
resources = self.toolchain.scan_resources(prj_paths[0])
163+
for path in prj_paths[1:]:
164+
resources.add(toolchain.scan_resources(path))
165+
166+
# Loads the resources into the config system which might expand/modify resources based on config data
167+
self.resources = config.load_resources(resources)
168+
169+
# And add the configuration macros to the toolchain
170+
self.config_macros = config.get_config_data_macros()
171+
167172
# Check the existence of a binary build of the mbed library for the desired target
168173
# This prevents exporting the mbed libraries from source
169174
# if not self.toolchain.mbed_libs:

0 commit comments

Comments
 (0)