diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 959ccafa34..e08e0eae78 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -1,6 +1,6 @@ """ mbed SDK -Copyright (c) 2011-2016 ARM Limited +Copyright (c) 2011-2019 ARM Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -269,11 +269,10 @@ class Arm(Makefile): if self.resources.linker_script: sct_file = self.resources.get_file_refs(FileType.LD_SCRIPT)[-1] new_script = self.toolchain.correct_scatter_shebang( - sct_file.path, join("..", dirname(sct_file.name))) + sct_file, dirname(sct_file.name)) if new_script is not sct_file: self.resources.add_files_to_type( FileType.LD_SCRIPT, [new_script]) - self.generated_files.append(new_script) return super(Arm, self).generate() class Armc5(Arm): diff --git a/tools/export/uvision/__init__.py b/tools/export/uvision/__init__.py index 0011c7dcfe..50404a3d03 100644 --- a/tools/export/uvision/__init__.py +++ b/tools/export/uvision/__init__.py @@ -244,12 +244,14 @@ class Uvision(Exporter): self.resources.inc_dirs), 'device': DeviceUvision(self.target), } - sct_name, sct_path = self.resources.get_file_refs( - FileType.LD_SCRIPT)[0] - ctx['linker_script'] = self.toolchain.correct_scatter_shebang( - sct_path, dirname(sct_name)) - if ctx['linker_script'] != sct_path: - self.generated_files.append(ctx['linker_script']) + sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0] + sct_file_ref = self.toolchain.correct_scatter_shebang( + sct_file_ref, dirname(sct_file_ref.name) + ) + self.resources.add_file_ref( + FileType.LD_SCRIPT, sct_file_ref.name, sct_file_ref.path + ) + ctx['linker_script'] = sct_file_ref.name fpu_included_core_name = ctx['device'].core.replace("-NS", "") ctx['cputype'] = fpu_included_core_name.rstrip("FDE") if fpu_included_core_name.endswith("FD"): diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index 302e47107c..2f7b905d47 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -1,6 +1,6 @@ """ mbed SDK -Copyright (c) 2011-2013 ARM Limited +Copyright (c) 2011-2019 ARM Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ from builtins import str # noqa: F401 import re from copy import copy -from os.path import join, dirname, splitext, basename, exists, isfile +from os.path import join, dirname, splitext, basename, exists, isfile, relpath from os import makedirs, write, remove from tempfile import mkstemp from shutil import rmtree @@ -28,6 +28,7 @@ from distutils.version import LooseVersion from tools.targets import CORE_ARCH from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS from tools.utils import mkdir, NotSupportedException, run_cmd +from tools.resources import FileRef ARMC5_MIGRATION_WARNING = ( "Warning: We noticed that you are using Arm Compiler 5. " @@ -272,11 +273,11 @@ class ARM(mbedToolchain): def compile_cpp(self, source, object, includes): return self.compile(self.cppc, source, object, includes) - def correct_scatter_shebang(self, scatter_file, cur_dir_name=None): + def correct_scatter_shebang(self, sc_fileref, cur_dir_name=None): """Correct the shebang at the top of a scatter file. Positional arguments: - scatter_file -- the scatter file to correct + sc_fileref -- FileRef object of the scatter file Keyword arguments: cur_dir_name -- the name (not path) of the directory containing the @@ -288,23 +289,23 @@ class ARM(mbedToolchain): Side Effects: This method MAY write a new scatter file to disk """ - with open(scatter_file, "r") as input: + with open(sc_fileref.path, "r") as input: lines = input.readlines() if (lines[0].startswith(self.SHEBANG) or - not lines[0].startswith("#!")): - return scatter_file + not lines[0].startswith("#!")): + return sc_fileref else: new_scatter = join(self.build_dir, ".link_script.sct") if cur_dir_name is None: - cur_dir_name = dirname(scatter_file) + cur_dir_name = dirname(sc_fileref.path) self.SHEBANG += " -I %s" % cur_dir_name - if self.need_update(new_scatter, [scatter_file]): + if self.need_update(new_scatter, [sc_fileref.path]): with open(new_scatter, "w") as out: out.write(self.SHEBANG) out.write("\n") out.write("".join(lines[1:])) - return new_scatter + return FileRef(".link_script.sct", new_scatter) def get_link_command( self, @@ -322,8 +323,9 @@ class ARM(mbedToolchain): if lib_dirs: args.extend(["--userlibpath", ",".join(lib_dirs)]) if scatter_file: - new_scatter = self.correct_scatter_shebang(scatter_file) - args.extend(["--scatter", new_scatter]) + scatter_name = relpath(scatter_file) + new_scatter = self.correct_scatter_shebang(FileRef(scatter_name, scatter_file)) + args.extend(["--scatter", new_scatter.path]) cmd = self.ld + args