Skip to content

Commit 8e59caa

Browse files
Naveen KajeNaveen Kaje
authored andcommitted
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.
1 parent 277c91f commit 8e59caa

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

tools/export/makefile/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2016 ARM Limited
3+
Copyright (c) 2011-2019 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -272,11 +272,10 @@ def generate(self):
272272
if self.resources.linker_script:
273273
sct_file = self.resources.get_file_refs(FileType.LD_SCRIPT)[-1]
274274
new_script = self.toolchain.correct_scatter_shebang(
275-
sct_file.path, join("..", dirname(sct_file.name)))
275+
sct_file, dirname(sct_file.name))
276276
if new_script is not sct_file:
277277
self.resources.add_files_to_type(
278278
FileType.LD_SCRIPT, [new_script])
279-
self.generated_files.append(new_script)
280279
return super(Arm, self).generate()
281280

282281
class Armc5(Arm):

tools/export/uvision/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,10 @@ def generate(self):
240240
self.resources.inc_dirs).encode('utf-8'),
241241
'device': DeviceUvision(self.target),
242242
}
243-
sct_name, sct_path = self.resources.get_file_refs(
244-
FileType.LD_SCRIPT)[0]
245-
ctx['linker_script'] = self.toolchain.correct_scatter_shebang(
246-
sct_path, dirname(sct_name))
247-
if ctx['linker_script'] != sct_path:
248-
self.generated_files.append(ctx['linker_script'])
243+
sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
244+
sct_file_ref = self.toolchain.correct_scatter_shebang(sct_file_ref, dirname(sct_file_ref.name))
245+
self.resources.add_file_ref(FileType.LD_SCRIPT, sct_file_ref.name, sct_file_ref.path)
246+
ctx['linker_script'] = sct_file_ref.name
249247
ctx['cputype'] = ctx['device'].core.rstrip("FD").replace("-NS", "")
250248
if ctx['device'].core.endswith("FD"):
251249
ctx['fpu_setting'] = 3

tools/toolchains/arm.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2013 ARM Limited
3+
Copyright (c) 2011-2019 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919

2020
import re
2121
from copy import copy
22-
from os.path import join, dirname, splitext, basename, exists, isfile
22+
from os.path import join, dirname, splitext, basename, exists, isfile, relpath
2323
from os import makedirs, write, remove
2424
from tempfile import mkstemp
2525
from shutil import rmtree
@@ -28,6 +28,7 @@
2828
from tools.targets import CORE_ARCH
2929
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
3030
from tools.utils import mkdir, NotSupportedException, run_cmd
31+
from tools.resources import FileRef
3132

3233

3334
class ARM(mbedToolchain):
@@ -241,11 +242,11 @@ def compile_c(self, source, object, includes):
241242
def compile_cpp(self, source, object, includes):
242243
return self.compile(self.cppc, source, object, includes)
243244

244-
def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
245+
def correct_scatter_shebang(self, sc_fileref, cur_dir_name=None):
245246
"""Correct the shebang at the top of a scatter file.
246247
247248
Positional arguments:
248-
scatter_file -- the scatter file to correct
249+
sc_fileref -- FileRef object of the scatter file
249250
250251
Keyword arguments:
251252
cur_dir_name -- the name (not path) of the directory containing the
@@ -257,23 +258,23 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
257258
Side Effects:
258259
This method MAY write a new scatter file to disk
259260
"""
260-
with open(scatter_file, "r") as input:
261+
with open(sc_fileref.path, "r") as input:
261262
lines = input.readlines()
262263
if (lines[0].startswith(self.SHEBANG) or
263-
not lines[0].startswith("#!")):
264-
return scatter_file
264+
not lines[0].startswith("#!")):
265+
return sc_fileref
265266
else:
266267
new_scatter = join(self.build_dir, ".link_script.sct")
267268
if cur_dir_name is None:
268-
cur_dir_name = dirname(scatter_file)
269+
cur_dir_name = dirname(sc_fileref.path)
269270
self.SHEBANG += " -I %s" % cur_dir_name
270-
if self.need_update(new_scatter, [scatter_file]):
271+
if self.need_update(new_scatter, [sc_fileref.path]):
271272
with open(new_scatter, "w") as out:
272273
out.write(self.SHEBANG)
273274
out.write("\n")
274275
out.write("".join(lines[1:]))
275276

276-
return new_scatter
277+
return FileRef(".link_script.sct", new_scatter)
277278

278279
def link(self, output, objects, libraries, lib_dirs, scatter_file):
279280
base, _ = splitext(output)
@@ -284,8 +285,9 @@ def link(self, output, objects, libraries, lib_dirs, scatter_file):
284285
if lib_dirs:
285286
args.extend(["--userlibpath", ",".join(lib_dirs)])
286287
if scatter_file:
287-
new_scatter = self.correct_scatter_shebang(scatter_file)
288-
args.extend(["--scatter", new_scatter])
288+
scatter_name = relpath(scatter_file)
289+
new_scatter = self.correct_scatter_shebang(FileRef(scatter_name, scatter_file))
290+
args.extend(["--scatter", new_scatter.path])
289291

290292
cmd = self.ld + args
291293

0 commit comments

Comments
 (0)