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.
pull/2471/head
Brian Daniels 2016-08-16 16:59:33 -05:00
parent 22acfbf077
commit 33672b483f
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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: