diff --git a/tools/build_api.py b/tools/build_api.py index 31944e910f..30ede6c4e8 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -122,7 +122,7 @@ def add_result_to_report(report, result): result_wrap = {0: result} report[target][toolchain][id_name].append(result_wrap) -def get_config(src_paths, target, toolchain_name, app_config=None): +def get_config(src_paths, target, toolchain_name=None, app_config=None): """Get the configuration object for a target-toolchain combination Positional arguments: @@ -134,16 +134,20 @@ def get_config(src_paths, target, toolchain_name, app_config=None): if not isinstance(src_paths, list): src_paths = [src_paths] - # Pass all params to the unified prepare_resources() - toolchain = prepare_toolchain(src_paths, None, target, toolchain_name, - app_config=app_config) + res = Resources(MockNotifier()) + if toolchain_name: + toolchain = prepare_toolchain(src_paths, None, target, toolchain_name, + app_config=app_config) + config = toolchain.config + res.scan_with_toolchain(src_paths, toolchain, exclude=False) + else: + config = Config(target, src_paths, app_config=app_config) + res.scan_with_config(src_paths, config, exclude=False) + if config.has_regions: + _ = list(config.regions) - res = Resources(MockNotifier()).scan_with_toolchain(src_paths, toolchain, exclude=False) - if toolchain.config.has_regions: - _ = list(toolchain.config.regions) - - cfg, macros = toolchain.config.get_config_data() - features = toolchain.config.get_features() + cfg, macros = config.get_config_data() + features = config.get_features() return cfg, macros, features def is_official_target(target_name, version): diff --git a/tools/get_config.py b/tools/get_config.py index 9a3bb0155b..1cc55c67ef 100644 --- a/tools/get_config.py +++ b/tools/get_config.py @@ -54,9 +54,7 @@ if __name__ == '__main__': target = extract_mcus(parser, options)[0] # Toolchain - if options.tool is None: - args_error(parser, "argument -t/--toolchain is required") - toolchain = options.tool[0] + toolchain = options.tool[0] if options.tool is not None else None options.prefix = options.prefix or [""] diff --git a/tools/resources/__init__.py b/tools/resources/__init__.py index b29a2aa1a9..33884509bc 100644 --- a/tools/resources/__init__.py +++ b/tools/resources/__init__.py @@ -373,6 +373,9 @@ class Resources(object): self.labels.setdefault(prefix, []) self.labels[prefix].extend(labels) + def add_target_labels(self, target): + self._add_labels("TARGET_", target.labels) + def add_toolchain_labels(self, toolchain): for prefix, value in toolchain.get_labels().items(): self._add_labels(prefix, value) @@ -586,3 +589,15 @@ class Resources(object): toolchain.set_config_data(toolchain.config.get_config_data()) return self + + def scan_with_config(self, src_paths, config, exclude=True, base_path=None): + if config.target: + self.add_target_labels(config.target) + for path in src_paths: + if exists(path): + if exclude: + self.add_directory(path, base_path, exclude_paths=[toolchain.build_dir]) + else: + self.add_directory(path, base_path) + config.load_resources(self) + return self diff --git a/tools/test_api.py b/tools/test_api.py index 123c07daab..e2f6bfa255 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -2228,7 +2228,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, else: target_name = target target = TARGET_MAP[target_name] - cfg, _, _ = get_config(base_source_paths, target_name, toolchain_name, app_config=app_config) + cfg, _, _ = get_config(base_source_paths, target, app_config=app_config) baud_rate = 9600 if 'platform.stdio-baud-rate' in cfg: