Skip to content

Have objects depend on their respective compiler invocations #4331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/test/build_api/build_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def tearDown(self):
side_effect=[i % 2 for i in range(3000)])
@patch('os.mkdir')
@patch('tools.toolchains.exists', return_value=True)
@patch('tools.toolchains.mbedToolchain.dump_build_profile')
@patch('tools.utils.run_cmd', return_value=("", "", 0))
def test_always_complete_build(self, *_):
with MagicMock() as notify:
Expand Down
32 changes: 29 additions & 3 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ class mbedToolchain:

MBED_CONFIG_FILE_NAME="mbed_config.h"

PROFILE_FILE_NAME = ".profile"

__metaclass__ = ABCMeta

profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
Expand Down Expand Up @@ -798,6 +800,7 @@ def compile_sources(self, resources, inc_dirs=None):

# Generate configuration header (this will update self.build_all if needed)
self.get_config_header()
self.dump_build_profile()

# Sort compile queue for consistency
files_to_compile.sort()
Expand Down Expand Up @@ -911,13 +914,19 @@ def compile_command(self, source, object, includes):
deps = []
config_file = ([self.config.app_config_location]
if self.config.app_config_location else [])
if len(deps) == 0 or self.need_update(object, deps + config_file):
deps.append(config_file)
if ext == '.cpp' or self.COMPILE_C_AS_CPP:
deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-cxx"))
else:
deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-c"))
if len(deps) == 0 or self.need_update(object, deps):
if ext == '.cpp' or self.COMPILE_C_AS_CPP:
return self.compile_cpp(source, object, includes)
else:
return self.compile_c(source, object, includes)
elif ext == '.s':
deps = [source]
deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-asm"))
if self.need_update(object, deps):
return self.assemble(source, object, includes)
else:
Expand Down Expand Up @@ -1012,8 +1021,9 @@ def link_program(self, r, tmp_path, name):
r.objects = sorted(set(r.objects))
config_file = ([self.config.app_config_location]
if self.config.app_config_location else [])
if self.need_update(elf, r.objects + r.libraries + [r.linker_script] +
config_file):
dependencies = r.objects + r.libraries + [r.linker_script, config_file]
dependencies.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-ld"))
if self.need_update(elf, dependencies):
needed_update = True
self.progress("link", name)
self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)
Expand Down Expand Up @@ -1161,6 +1171,22 @@ def get_config_header(self):
self.config_processed = True
return self.config_file

def dump_build_profile(self):
"""Dump the current build profile and macros into the `.profile` file
in the build directory"""
for key in ["cxx", "c", "asm", "ld"]:
to_dump = (str(self.flags[key]) + str(sorted(self.macros)))
if key in ["cxx", "c"]:
to_dump += str(self.flags['common'])
where = join(self.build_dir, self.PROFILE_FILE_NAME + "-" + key)
self._overwrite_when_not_equal(where, to_dump)

@staticmethod
def _overwrite_when_not_equal(filename, content):
if not exists(filename) or content != open(filename).read():
with open(filename, "wb") as out:
out.write(content)

@staticmethod
def generic_check_executable(tool_key, executable_name, levels_up,
nested_dir=None):
Expand Down