Skip to content

Commit 33672b4

Browse files
committed
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.
1 parent 22acfbf commit 33672b4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

tools/build_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
import re
1919
import tempfile
20-
2120
from types import ListType
2221
from shutil import rmtree
2322
from os.path import join, exists, basename, abspath, normpath
24-
from os import linesep
23+
from os import linesep, remove
2524
from time import time
2625

2726
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,
489488
dependencies_paths=None, options=None, name=None, clean=False,
490489
archive=True, notify=None, verbose=False, macros=None,
491490
inc_dirs=None, jobs=1, silent=False, report=None,
492-
properties=None, extra_verbose=False, project_id=None):
491+
properties=None, extra_verbose=False, project_id=None,
492+
remove_config_header_file=False):
493493
""" Build a library
494494
495495
Positional arguments:
@@ -515,6 +515,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
515515
properties - UUUUHHHHH beats me
516516
extra_verbose - even more output!
517517
project_id - the name that goes in the report
518+
remove_config_header_file - delete config header file when done building
518519
"""
519520

520521
# Convert src_path to a list if needed
@@ -582,6 +583,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
582583
toolchain.copy_files(resources.objects, build_path, resources=resources)
583584
toolchain.copy_files(resources.libraries, build_path,
584585
resources=resources)
586+
toolchain.copy_files(resources.json_files, build_path,
587+
resources=resources)
585588
if resources.linker_script:
586589
toolchain.copy_files(resources.linker_script, build_path,
587590
resources=resources)
@@ -598,6 +601,11 @@ def build_library(src_paths, build_path, target, toolchain_name,
598601
if archive:
599602
toolchain.build_library(objects, build_path, name)
600603

604+
if remove_config_header_file:
605+
config_header_path = toolchain.get_config_header()
606+
if config_header_path:
607+
remove(config_header_path)
608+
601609
if report != None:
602610
end = time()
603611
cur_result["elapsed_time"] = end - start

tools/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@
177177
macros=options.macros,
178178
verbose=options.verbose,
179179
notify=notify,
180-
archive=False)
180+
archive=False,
181+
remove_config_header_file=True)
181182

182183
library_build_success = True
183184
except ToolException, e:

0 commit comments

Comments
 (0)