mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9966 from naveenkaje/sct_fix
tools: fix the path generated to the sct filepull/10053/head
commit
803f5fd44e
|
|
@ -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,14 @@ 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, join("..", 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)
|
||||
self.resources.add_file_ref(
|
||||
FileType.LD_SCRIPT,
|
||||
new_script.name,
|
||||
new_script.path
|
||||
)
|
||||
return super(Arm, self).generate()
|
||||
|
||||
class Armc5(Arm):
|
||||
|
|
|
|||
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -269,6 +269,10 @@ class Resources(object):
|
|||
if file_type:
|
||||
if sep != self._sep:
|
||||
file_name = file_name.replace(sep, self._sep)
|
||||
# Mbed OS projects only use one linker script at a time, so remove
|
||||
# any existing linker script when adding a new one
|
||||
if file_type == FileType.LD_SCRIPT:
|
||||
self._file_refs[file_type].clear()
|
||||
self._file_refs[file_type].add(FileRef(file_name, file_path))
|
||||
|
||||
def _include_file(self, ref):
|
||||
|
|
|
|||
|
|
@ -146,6 +146,20 @@ class ResourcesTest(unittest.TestCase):
|
|||
exc_names = [dirname(name) or "." for name, _ in excluded_libs]
|
||||
assert(all(e in res.ignored_dirs for e in exc_names))
|
||||
|
||||
def test_only_one_linker_script(self):
|
||||
"""
|
||||
Verify that when multiple linker scripts are added to a resource object,
|
||||
only the last one added is used.
|
||||
"""
|
||||
resources = Resources(MockNotifier())
|
||||
linker_scripts = ["first_linker_script.sct", "second_linker_script.sct"]
|
||||
for linker_script in linker_scripts:
|
||||
resources.add_file_ref(FileType.LD_SCRIPT, linker_script, linker_script)
|
||||
|
||||
assert(len(resources.get_file_refs(FileType.LD_SCRIPT)) == 1)
|
||||
assert(resources.get_file_refs(FileType.LD_SCRIPT)[-1].name == linker_scripts[-1])
|
||||
assert(resources.get_file_refs(FileType.LD_SCRIPT)[-1].path == linker_scripts[-1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -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,39 +273,39 @@ 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
|
||||
scatter file
|
||||
|
||||
Return:
|
||||
The location of the correct scatter file
|
||||
The FileRef of the correct scatter file
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue