From e3d29fe5d25f4c375fb15dd7438275ac578d905c Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Tue, 5 Jul 2016 15:40:12 +0300 Subject: [PATCH 1/3] Improve configuration handling in build_project The configuration object is now created early in the build_project function. This way, if there's a mbed_app.json that contains a custom target, that target is taken into account. This is useful (for example) when compiling tests for an application that defines a custom target. --- tools/build_api.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/build_api.py b/tools/build_api.py index 9ef249f963..f8afdc513b 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -282,6 +282,16 @@ def build_library(src_paths, build_path, target, toolchain_name, # We will use default project name based on project folder name name = project_name + # If the configuration object was not yet created, create it now + config = Config(target, src_paths) + + # If the 'target' argument is a string, convert it to a target instance + if isinstance(target, str): + try: + target = TARGET_MAP[target] + except KeyError: + raise KeyError("Target '%s' not found" % target) + if report != None: start = time() @@ -355,9 +365,6 @@ def build_library(src_paths, build_path, target, toolchain_name, else: tmp_path = build_path - # Handle configuration - config = Config(target) - # Load resources into the config system which might expand/modify resources based on config data resources = config.load_resources(resources) From 36a577e1ef971f08b6012b0ed80723dc2e00d973 Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Tue, 5 Jul 2016 15:47:26 +0300 Subject: [PATCH 2/3] Make build_tests work with target names, not just Target instances With this change, custom targets defined by the application being tested in its mbed_app.json file can be used with tests. Note that `build_project` already accepts both target names and instances, so the call to `build_project` inside `build_tests` will still work. --- tools/test_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/test_api.py b/tools/test_api.py index 6f3494af3f..06ee67612a 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -2030,9 +2030,11 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, execution_directory = "." base_path = norm_relative_path(build_path, execution_directory) + + target_name = target if isinstance(target, str) else target.name test_build = { - "platform": target.name, + "platform": target_name, "toolchain": toolchain_name, "base_path": base_path, "baud_rate": 9600, @@ -2086,7 +2088,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, print 'Image: %s'% bin_file test_builds = {} - test_builds["%s-%s" % (target.name, toolchain_name)] = test_build + test_builds["%s-%s" % (target_name, toolchain_name)] = test_build return result, test_builds From fbb26a405cb8fce5320189f849883e5c5588e3de Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Tue, 5 Jul 2016 15:52:53 +0300 Subject: [PATCH 3/3] Fix tests.py so it can work with application defined targets With this patch in place, tests.py uses targets names instead of target instances, which makes it possible to use application defined targets with tests. --- tools/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index bdc9bb9c9d..4189650286 100644 --- a/tools/test.py +++ b/tools/test.py @@ -132,7 +132,7 @@ if __name__ == '__main__': base_source_paths = ['.'] - target = TARGET_MAP[options.mcu] + target = options.mcu build_report = {} build_properties = {}