diff --git a/tools/build_api.py b/tools/build_api.py index e84bf2200c..a288e3d484 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -336,16 +336,6 @@ def build_library(src_paths, build_path, target, toolchain_name, for path in src_paths: # Scan resources resource = toolchain.scan_resources(path) - - # Copy headers, objects and static libraries - all files needed for static lib - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) - toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path) - toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path) - if resource.linker_script: - toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path) - - if resource.hex_files: - toolchain.copy_files(resource.hex_files, build_path, rel_path=resource.base_path) # Extend resources collection if not resources: @@ -404,6 +394,16 @@ def build_library(src_paths, build_path, target, toolchain_name, # And add the configuration macros to the toolchain toolchain.add_macros(config.get_config_data_macros()) + # Copy headers, objects and static libraries - all files needed for static lib + toolchain.copy_files(resources.headers, build_path, resources=resources) + toolchain.copy_files(resources.objects, build_path, resources=resources) + toolchain.copy_files(resources.libraries, build_path, resources=resources) + if resources.linker_script: + toolchain.copy_files(resources.linker_script, build_path, resources=resources) + + if resource.hex_files: + toolchain.copy_files(resources.hex_files, build_path, resources=resources) + # Compile Sources objects = toolchain.compile_sources(resources, abspath(tmp_path), resources.inc_dirs) resources.objects.extend(objects) @@ -544,7 +544,7 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False, clean # Copy Headers for resource in resources: - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) + toolchain.copy_files(resource.headers, build_path, resources=resource) dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs) @@ -643,7 +643,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F # Target specific sources HAL_SRC = join(MBED_TARGETS_PATH, "hal") hal_implementation = toolchain.scan_resources(HAL_SRC) - toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files + hal_implementation.libraries, BUILD_TARGET, HAL_SRC) + toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files + hal_implementation.libraries, BUILD_TARGET, resources=hal_implementation) incdirs = toolchain.scan_resources(BUILD_TARGET).inc_dirs objects = toolchain.compile_sources(hal_implementation, TMP_PATH, [MBED_LIBRARIES] + incdirs) @@ -821,7 +821,7 @@ def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORM hal_implementation = toolchain.scan_resources(HAL_SRC) # Copy files before analysis - toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET, HAL_SRC) + toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET, resources=hal_implementation) incdirs = toolchain.scan_resources(BUILD_TARGET) target_includes = ["-I%s" % i for i in incdirs.inc_dirs] @@ -925,7 +925,7 @@ def static_analysis_scan_library(src_paths, build_path, target, toolchain_name, # Copy Headers for resource in resources: - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) + toolchain.copy_files(resource.headers, build_path, resources=resource) includes += ["-I%s" % i for i in resource.inc_dirs] c_sources += " ".join(resource.c_sources) + " " cpp_sources += " ".join(resource.cpp_sources) + " " diff --git a/tools/export/exporters.py b/tools/export/exporters.py index ae46752bb6..c84b3c1290 100644 --- a/tools/export/exporters.py +++ b/tools/export/exporters.py @@ -57,7 +57,7 @@ class Exporter(object): 'lib_builds', 'lib_refs', 'repo_files', 'hex_files', 'bin_files']: r = getattr(resources, r_type) if r: - self.toolchain.copy_files(r, trg_path, rel_path=src_path) + self.toolchain.copy_files(r, trg_path, resources=resources) return resources @staticmethod diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index 7e8a8f9e17..918208bdc9 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -546,7 +546,7 @@ class mbedToolchain: return resources - def copy_files(self, files_paths, trg_path, rel_path=None): + def copy_files(self, files_paths, trg_path, resources=None, rel_path=None): # Handle a single file if type(files_paths) != ListType: files_paths = [files_paths] @@ -556,7 +556,9 @@ class mbedToolchain: files_paths.remove(source) for source in files_paths: - if rel_path is not None: + if resources is not None: + relative_path = relpath(source, resources.file_basepath[source]) + elif rel_path is not None: relative_path = relpath(source, rel_path) else: _, relative_path = split(source)