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/10469/head
Naveen Kaje 2019-03-06 14:34:09 -06:00 committed by adbridge
parent b2e0110eb5
commit c3fa5252e5
3 changed files with 24 additions and 21 deletions

View File

@ -1,6 +1,6 @@
""" """
mbed SDK mbed SDK
Copyright (c) 2011-2016 ARM Limited Copyright (c) 2011-2019 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with 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: if self.resources.linker_script:
sct_file = self.resources.get_file_refs(FileType.LD_SCRIPT)[-1] sct_file = self.resources.get_file_refs(FileType.LD_SCRIPT)[-1]
new_script = self.toolchain.correct_scatter_shebang( 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: if new_script is not sct_file:
self.resources.add_files_to_type( self.resources.add_files_to_type(
FileType.LD_SCRIPT, [new_script]) FileType.LD_SCRIPT, [new_script])
self.generated_files.append(new_script)
return super(Arm, self).generate() return super(Arm, self).generate()
class Armc5(Arm): class Armc5(Arm):

View File

@ -244,12 +244,14 @@ class Uvision(Exporter):
self.resources.inc_dirs), self.resources.inc_dirs),
'device': DeviceUvision(self.target), 'device': DeviceUvision(self.target),
} }
sct_name, sct_path = self.resources.get_file_refs( sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
FileType.LD_SCRIPT)[0] sct_file_ref = self.toolchain.correct_scatter_shebang(
ctx['linker_script'] = self.toolchain.correct_scatter_shebang( sct_file_ref, dirname(sct_file_ref.name)
sct_path, dirname(sct_name)) )
if ctx['linker_script'] != sct_path: self.resources.add_file_ref(
self.generated_files.append(ctx['linker_script']) 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", "") fpu_included_core_name = ctx['device'].core.replace("-NS", "")
ctx['cputype'] = fpu_included_core_name.rstrip("FDE") ctx['cputype'] = fpu_included_core_name.rstrip("FDE")
if fpu_included_core_name.endswith("FD"): if fpu_included_core_name.endswith("FD"):

View File

@ -1,6 +1,6 @@
""" """
mbed SDK mbed SDK
Copyright (c) 2011-2013 ARM Limited Copyright (c) 2011-2019 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with 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 import re
from copy import copy 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 os import makedirs, write, remove
from tempfile import mkstemp from tempfile import mkstemp
from shutil import rmtree from shutil import rmtree
@ -28,6 +28,7 @@ from distutils.version import LooseVersion
from tools.targets import CORE_ARCH from tools.targets import CORE_ARCH
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
from tools.utils import mkdir, NotSupportedException, run_cmd from tools.utils import mkdir, NotSupportedException, run_cmd
from tools.resources import FileRef
ARMC5_MIGRATION_WARNING = ( ARMC5_MIGRATION_WARNING = (
"Warning: We noticed that you are using Arm Compiler 5. " "Warning: We noticed that you are using Arm Compiler 5. "
@ -272,11 +273,11 @@ class ARM(mbedToolchain):
def compile_cpp(self, source, object, includes): def compile_cpp(self, source, object, includes):
return self.compile(self.cppc, 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. """Correct the shebang at the top of a scatter file.
Positional arguments: Positional arguments:
scatter_file -- the scatter file to correct sc_fileref -- FileRef object of the scatter file
Keyword arguments: Keyword arguments:
cur_dir_name -- the name (not path) of the directory containing the cur_dir_name -- the name (not path) of the directory containing the
@ -288,23 +289,23 @@ class ARM(mbedToolchain):
Side Effects: Side Effects:
This method MAY write a new scatter file to disk 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() lines = input.readlines()
if (lines[0].startswith(self.SHEBANG) or if (lines[0].startswith(self.SHEBANG) or
not lines[0].startswith("#!")): not lines[0].startswith("#!")):
return scatter_file return sc_fileref
else: else:
new_scatter = join(self.build_dir, ".link_script.sct") new_scatter = join(self.build_dir, ".link_script.sct")
if cur_dir_name is None: 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 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: with open(new_scatter, "w") as out:
out.write(self.SHEBANG) out.write(self.SHEBANG)
out.write("\n") out.write("\n")
out.write("".join(lines[1:])) out.write("".join(lines[1:]))
return new_scatter return FileRef(".link_script.sct", new_scatter)
def get_link_command( def get_link_command(
self, self,
@ -322,8 +323,9 @@ class ARM(mbedToolchain):
if lib_dirs: if lib_dirs:
args.extend(["--userlibpath", ",".join(lib_dirs)]) args.extend(["--userlibpath", ",".join(lib_dirs)])
if scatter_file: if scatter_file:
new_scatter = self.correct_scatter_shebang(scatter_file) scatter_name = relpath(scatter_file)
args.extend(["--scatter", new_scatter]) new_scatter = self.correct_scatter_shebang(FileRef(scatter_name, scatter_file))
args.extend(["--scatter", new_scatter.path])
cmd = self.ld + args cmd = self.ld + args