Skip to content

Commit a48647f

Browse files
theotherjimmyadbridge
authored andcommitted
Ignore build directory from scan resources
This is a bug fix for the following bug (Github issue #437): If two builds were run specifying a non-default build folder, the second build would fail to link with duplicate symbols and may not fit on the device. The root of this problem is that these non-default build folders are not ignored by scan-resources, and therefore included in the build. We fix this bug by ignoring the build directory passed into the tools.
1 parent 404b58c commit a48647f

File tree

7 files changed

+44
-38
lines changed

7 files changed

+44
-38
lines changed

tools/build_api.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def get_config(src_paths, target, toolchain_name):
121121
src_paths = [src_paths]
122122

123123
# Pass all params to the unified prepare_resources()
124-
toolchain = prepare_toolchain(src_paths, target, toolchain_name)
124+
toolchain = prepare_toolchain(src_paths, None, target, toolchain_name)
125125

126126
# Scan src_path for config files
127127
resources = toolchain.scan_resources(src_paths[0])
@@ -299,7 +299,7 @@ def add_regions_to_profile(profile, config, toolchain_class):
299299
% (region.name, region.size, region.start))
300300

301301

302-
def prepare_toolchain(src_paths, target, toolchain_name,
302+
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
303303
macros=None, clean=False, jobs=1,
304304
notify=None, silent=False, verbose=False,
305305
extra_verbose=False, config=None,
@@ -339,7 +339,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
339339
add_regions_to_profile(build_profile, config, cur_tc)
340340

341341
# Toolchain instance
342-
toolchain = cur_tc(target, notify, macros, silent,
342+
toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir,
343343
extra_verbose=extra_verbose, build_profile=build_profile)
344344

345345
toolchain.config = config
@@ -475,8 +475,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
475475

476476
# Pass all params to the unified prepare_toolchain()
477477
toolchain = prepare_toolchain(
478-
src_paths, target, toolchain_name, macros=macros, clean=clean,
479-
jobs=jobs, notify=notify, silent=silent, verbose=verbose,
478+
src_paths, build_path, target, toolchain_name, macros=macros,
479+
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
480480
extra_verbose=extra_verbose, config=config, app_config=app_config,
481481
build_profile=build_profile)
482482

@@ -509,8 +509,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
509509
resources.linker_script = linker_script
510510

511511
# Compile Sources
512-
objects = toolchain.compile_sources(resources, build_path,
513-
resources.inc_dirs)
512+
objects = toolchain.compile_sources(resources, resources.inc_dirs)
514513
resources.objects.extend(objects)
515514

516515
# Link Program
@@ -629,9 +628,9 @@ def build_library(src_paths, build_path, target, toolchain_name,
629628

630629
# Pass all params to the unified prepare_toolchain()
631630
toolchain = prepare_toolchain(
632-
src_paths, target, toolchain_name, macros=macros, clean=clean,
633-
jobs=jobs, notify=notify, silent=silent, verbose=verbose,
634-
extra_verbose=extra_verbose, app_config=app_config,
631+
src_paths, build_path, target, toolchain_name, macros=macros,
632+
clean=clean, jobs=jobs, notify=notify, silent=silent,
633+
verbose=verbose, extra_verbose=extra_verbose, app_config=app_config,
635634
build_profile=build_profile)
636635

637636
# The first path will give the name to the library
@@ -687,8 +686,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
687686
resources=resources)
688687

689688
# Compile Sources
690-
objects = toolchain.compile_sources(resources, abspath(tmp_path),
691-
resources.inc_dirs)
689+
objects = toolchain.compile_sources(resources, resources.inc_dirs)
692690
resources.objects.extend(objects)
693691

694692
if archive:
@@ -815,6 +813,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
815813
toolchain.VERBOSE = verbose
816814
toolchain.jobs = jobs
817815
toolchain.build_all = clean
816+
toolchain.build_dir = build_path
818817

819818
toolchain.info("Building library %s (%s, %s)" %
820819
(name.upper(), target.name, toolchain_name))
@@ -869,8 +868,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
869868
# Compile Sources
870869
objects = []
871870
for resource in resources:
872-
objects.extend(toolchain.compile_sources(resource, tmp_path,
873-
dependencies_include_dir))
871+
objects.extend(toolchain.compile_sources(resource, dependencies_include_dir))
874872

875873
needed_update = toolchain.build_library(objects, bin_path, name)
876874

@@ -962,6 +960,11 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
962960
toolchain.jobs = jobs
963961
toolchain.build_all = clean
964962

963+
tmp_path = join(MBED_LIBRARIES, '.temp', toolchain.obj_path)
964+
mkdir(tmp_path)
965+
966+
toolchain.build_dir = tmp_path
967+
965968
# Take into account the library configuration (MBED_CONFIG_FILE)
966969
config = Config(target)
967970
toolchain.config = config
@@ -973,8 +976,6 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
973976
build_toolchain = join(build_target, "TOOLCHAIN_" + toolchain.name)
974977
mkdir(build_toolchain)
975978

976-
tmp_path = join(MBED_LIBRARIES, '.temp', toolchain.obj_path)
977-
mkdir(tmp_path)
978979

979980
# CMSIS
980981
toolchain.info("Building library %s (%s, %s)" %
@@ -1015,7 +1016,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
10151016
toolchain.copy_files(hal_implementation.linker_script, build_toolchain)
10161017
toolchain.copy_files(hal_implementation.bin_files, build_toolchain)
10171018
incdirs = toolchain.scan_resources(build_target).inc_dirs
1018-
objects = toolchain.compile_sources(hal_implementation, tmp_path,
1019+
objects = toolchain.compile_sources(hal_implementation,
10191020
library_incdirs + incdirs)
10201021
toolchain.copy_files(objects, build_toolchain)
10211022

@@ -1024,7 +1025,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
10241025
for dir in [MBED_DRIVERS, MBED_PLATFORM, MBED_HAL]:
10251026
mbed_resources += toolchain.scan_resources(dir)
10261027

1027-
objects = toolchain.compile_sources(mbed_resources, tmp_path,
1028+
objects = toolchain.compile_sources(mbed_resources,
10281029
library_incdirs + incdirs)
10291030

10301031
# A number of compiled files need to be copied as objects as opposed to

tools/project_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
186186
_, toolchain_name = get_exporter_toolchain(ide)
187187

188188
# Pass all params to the unified prepare_resources()
189-
toolchain = prepare_toolchain(paths, target, toolchain_name, macros=macros,
190-
jobs=jobs, notify=notify, silent=silent,
191-
verbose=verbose, extra_verbose=extra_verbose,
192-
config=config, build_profile=build_profile)
189+
toolchain = prepare_toolchain(
190+
paths, export_path, target, toolchain_name, macros=macros, jobs=jobs,
191+
notify=notify, silent=silent, verbose=verbose,
192+
extra_verbose=extra_verbose, config=config, build_profile=build_profile)
193193
# The first path will give the name to the library
194194
if name is None:
195195
name = basename(normpath(abspath(src_paths[0])))

tools/test/build_api/build_api_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,16 @@ def tearDown(self):
5858
@patch('tools.utils.run_cmd', return_value=("", "", 0))
5959
def test_always_complete_build(self, *_):
6060
with MagicMock() as notify:
61-
toolchain = prepare_toolchain(self.src_paths, self.target,
61+
toolchain = prepare_toolchain(self.src_paths, self.build_path, self.target,
6262
self.toolchain_name, notify=notify)
6363

6464
res = scan_resources(self.src_paths, toolchain)
6565

6666
toolchain.RESPONSE_FILES=False
6767
toolchain.config_processed = True
6868
toolchain.config_file = "junk"
69-
toolchain.compile_sources(res, self.build_path)
69+
toolchain.compile_sources(res)
7070

71-
print notify.mock_calls
7271
assert any('percent' in msg[0] and msg[0]['percent'] == 100.0
7372
for _, msg, _ in notify.mock_calls if msg)
7473

@@ -90,7 +89,7 @@ def test_prepare_toolchain_app_config(self, mock_config_init):
9089
mock_target,
9190
False)
9291

93-
prepare_toolchain(self.src_paths, self.target, self.toolchain_name,
92+
prepare_toolchain(self.src_paths, None, self.target, self.toolchain_name,
9493
app_config=app_config)
9594

9695
mock_config_init.assert_called_once_with(self.target, self.src_paths,
@@ -112,7 +111,7 @@ def test_prepare_toolchain_no_app_config(self, mock_config_init):
112111
mock_target,
113112
False)
114113

115-
prepare_toolchain(self.src_paths, self.target, self.toolchain_name)
114+
prepare_toolchain(self.src_paths, None, self.target, self.toolchain_name)
116115

117116
mock_config_init.assert_called_once_with(self.target, self.src_paths,
118117
app_config=None)

tools/toolchains/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ class mbedToolchain:
256256

257257
profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
258258

259-
def __init__(self, target, notify=None, macros=None, silent=False, extra_verbose=False, build_profile=None):
259+
def __init__(self, target, notify=None, macros=None, silent=False,
260+
extra_verbose=False, build_profile=None, build_dir=None):
260261
self.target = target
261262
self.name = self.__class__.__name__
262263

@@ -295,7 +296,7 @@ def __init__(self, target, notify=None, macros=None, silent=False, extra_verbose
295296
self.build_all = False
296297

297298
# Build output dir
298-
self.build_dir = None
299+
self.build_dir = build_dir
299300
self.timestamp = time()
300301

301302
# Output build naming based on target+toolchain combo (mbed 2.0 builds)
@@ -580,7 +581,8 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
580581
self.add_ignore_patterns(root, base_path, lines)
581582

582583
# Skip the whole folder if ignored, e.g. .mbedignore containing '*'
583-
if self.is_ignored(join(relpath(root, base_path),"")):
584+
if (self.is_ignored(join(relpath(root, base_path),"")) or
585+
self.build_dir == join(relpath(root, base_path))):
584586
dirs[:] = []
585587
continue
586588

@@ -773,7 +775,7 @@ def get_arch_file(self, objects):
773775

774776
# THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
775777
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
776-
def compile_sources(self, resources, build_path, inc_dirs=None):
778+
def compile_sources(self, resources, inc_dirs=None):
777779
# Web IDE progress bar for project build
778780
files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
779781
self.to_be_compiled = len(files_to_compile)
@@ -790,8 +792,6 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
790792
inc_paths = sorted(set(inc_paths))
791793
# Unique id of all include paths
792794
self.inc_md5 = md5(' '.join(inc_paths)).hexdigest()
793-
# Where to store response files
794-
self.build_dir = build_path
795795

796796
objects = []
797797
queue = []
@@ -804,7 +804,8 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
804804
# Sort compile queue for consistency
805805
files_to_compile.sort()
806806
for source in files_to_compile:
807-
object = self.relative_object_path(build_path, resources.file_basepath[source], source)
807+
object = self.relative_object_path(
808+
self.build_dir, resources.file_basepath[source], source)
808809

809810
# Queue mode (multiprocessing)
810811
commands = self.compile_command(source, object, inc_paths)

tools/toolchains/arm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def check_executable():
4040
return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
4141

4242
def __init__(self, target, notify=None, macros=None,
43-
silent=False, extra_verbose=False, build_profile=None):
43+
silent=False, extra_verbose=False, build_profile=None,
44+
build_dir=None):
4445
mbedToolchain.__init__(self, target, notify, macros, silent,
46+
build_dir=build_dir,
4547
extra_verbose=extra_verbose,
4648
build_profile=build_profile)
4749

tools/toolchains/gcc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class GCC(mbedToolchain):
2929
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
3030

3131
def __init__(self, target, notify=None, macros=None,
32-
silent=False, extra_verbose=False, build_profile=None):
32+
silent=False, extra_verbose=False, build_profile=None,
33+
build_dir=None):
3334
mbedToolchain.__init__(self, target, notify, macros, silent,
3435
extra_verbose=extra_verbose,
35-
build_profile=build_profile)
36+
build_profile=build_profile, build_dir=build_dir)
3637

3738
tool_path=TOOLCHAIN_PATHS['GCC_ARM']
3839
# Add flags for current size setting

tools/toolchains/iar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def check_executable():
3737
return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin")
3838

3939
def __init__(self, target, notify=None, macros=None,
40-
silent=False, extra_verbose=False, build_profile=None):
40+
silent=False, extra_verbose=False, build_profile=None,
41+
build_dir=None):
4142
mbedToolchain.__init__(self, target, notify, macros, silent,
43+
build_dir=build_dir,
4244
extra_verbose=extra_verbose,
4345
build_profile=build_profile)
4446
if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":

0 commit comments

Comments
 (0)