Skip to content

Commit

Permalink
tools: fix the path generated to the sct file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Naveen Kaje authored and Naveen Kaje committed Mar 5, 2019
1 parent fa65546 commit 2dfc513
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 5 additions & 5 deletions tools/export/uvision/__init__.py
Expand Up @@ -244,11 +244,11 @@ def generate(self):
self.resources.inc_dirs).encode('utf-8'),
'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:
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
if ctx['linker_script'] != sct_file_ref.path:
self.generated_files.append(ctx['linker_script'])
ctx['cputype'] = ctx['device'].core.rstrip("FD").replace("-NS", "")
if ctx['device'].core.endswith("FD"):
Expand Down
22 changes: 12 additions & 10 deletions tools/toolchains/arm.py
Expand Up @@ -19,7 +19,7 @@

import re
from copy import copy
from os.path import join, dirname, splitext, basename, exists, relpath, isfile
from os.path import join, dirname, splitext, basename, exists, isfile, split
from os import makedirs, write, curdir, remove
from tempfile import mkstemp
from shutil import rmtree
Expand All @@ -29,6 +29,7 @@
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
from tools.utils import mkdir, NotSupportedException, run_cmd
from tools.resources import FileRef

class ARM(mbedToolchain):
LINKER_EXT = '.sct'
Expand Down Expand Up @@ -235,11 +236,11 @@ def compile_c(self, source, object, includes):
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
Expand All @@ -251,23 +252,23 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
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
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)

@hook_tool
def link(self, output, objects, libraries, lib_dirs, scatter_file):
Expand All @@ -279,8 +280,9 @@ def link(self, output, objects, libraries, lib_dirs, scatter_file):
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 = split(scatter_file)[-1]
new_scatter = self.correct_scatter_shebang(FileRef(scatter_name, scatter_file))
args.extend(["--scatter", new_scatter.path])

cmd_pre = self.ld + args
cmd = self.hook.get_cmdline_linker(cmd_pre)
Expand Down

0 comments on commit 2dfc513

Please sign in to comment.