From 2870ee4bfcde4bdebdd4df23e7b06c112f5bb35e Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Tue, 16 Aug 2016 16:59:33 -0500 Subject: [PATCH] Copying JSON files to pick up config for built libraries This came up when building tests, but affects any library that's built that uses config and included as "source" with the mbed tools. JSON files are not copied by default when building a library, so when this is built it loses the config data associated with the library. This commit copies all JSON files into the build directory when building libraries. This leads to two mbed_config.h files existing if the build directories are different between the library and application build. This is the case when building tests, so an option build_library was added to remove the mbed_config.h file when compilation is done. This disabled by default when building libraries, but it is enabled when building tests. --- tools/build_api.py | 14 +++++++++++--- tools/test.py | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/build_api.py b/tools/build_api.py index 8b6184ffc8..be116eb851 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -17,11 +17,10 @@ limitations under the License. import re import tempfile - from types import ListType from shutil import rmtree from os.path import join, exists, basename, abspath, normpath -from os import linesep +from os import linesep, remove from time import time from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException,\ @@ -489,7 +488,8 @@ def build_library(src_paths, build_path, target, toolchain_name, dependencies_paths=None, options=None, name=None, clean=False, archive=True, notify=None, verbose=False, macros=None, inc_dirs=None, jobs=1, silent=False, report=None, - properties=None, extra_verbose=False, project_id=None): + properties=None, extra_verbose=False, project_id=None, + remove_config_header_file=False): """ Build a library Positional arguments: @@ -515,6 +515,7 @@ def build_library(src_paths, build_path, target, toolchain_name, properties - UUUUHHHHH beats me extra_verbose - even more output! project_id - the name that goes in the report + remove_config_header_file - delete config header file when done building """ # Convert src_path to a list if needed @@ -582,6 +583,8 @@ def build_library(src_paths, build_path, target, toolchain_name, toolchain.copy_files(resources.objects, build_path, resources=resources) toolchain.copy_files(resources.libraries, build_path, resources=resources) + toolchain.copy_files(resources.json_files, build_path, + resources=resources) if resources.linker_script: toolchain.copy_files(resources.linker_script, build_path, resources=resources) @@ -598,6 +601,11 @@ def build_library(src_paths, build_path, target, toolchain_name, if archive: toolchain.build_library(objects, build_path, name) + if remove_config_header_file: + config_header_path = toolchain.get_config_header() + if config_header_path: + remove(config_header_path) + if report != None: end = time() cur_result["elapsed_time"] = end - start diff --git a/tools/test.py b/tools/test.py index 6cf205ca11..9b568a5d93 100644 --- a/tools/test.py +++ b/tools/test.py @@ -177,7 +177,8 @@ if __name__ == '__main__': macros=options.macros, verbose=options.verbose, notify=notify, - archive=False) + archive=False, + remove_config_header_file=True) library_build_success = True except ToolException, e: