tools: fix the path generated to the sct file

The sct file path generated in the online compiler
is incorrect. Fix that by changing the correct_scatter_shebang
API to accept a FileRef object instead and use the path.

This change should go with change in online compiler that removes
the override for correct_scatter_shebang.
pull/9966/head
Naveen Kaje 2019-03-06 14:34:09 -06:00 committed by Brian Daniels
parent 2a694cf1d9
commit f0f133f3ec
3 changed files with 24 additions and 21 deletions

View File

@ -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.
@ -272,11 +272,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):

View File

@ -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"):

View File

@ -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