Skip to content

Commit f0f133f

Browse files
Naveen Kajebridadan
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 2a694cf commit f0f133f

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,14 @@ def generate(self):
244244
self.resources.inc_dirs),
245245
'device': DeviceUvision(self.target),
246246
}
247-
sct_name, sct_path = self.resources.get_file_refs(
248-
FileType.LD_SCRIPT)[0]
249-
ctx['linker_script'] = self.toolchain.correct_scatter_shebang(
250-
sct_path, dirname(sct_name))
251-
if ctx['linker_script'] != sct_path:
252-
self.generated_files.append(ctx['linker_script'])
247+
sct_file_ref = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
248+
sct_file_ref = self.toolchain.correct_scatter_shebang(
249+
sct_file_ref, dirname(sct_file_ref.name)
250+
)
251+
self.resources.add_file_ref(
252+
FileType.LD_SCRIPT, sct_file_ref.name, sct_file_ref.path
253+
)
254+
ctx['linker_script'] = sct_file_ref.name
253255
fpu_included_core_name = ctx['device'].core.replace("-NS", "")
254256
ctx['cputype'] = fpu_included_core_name.rstrip("FDE")
255257
if fpu_included_core_name.endswith("FD"):

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
ARMC5_MIGRATION_WARNING = (
3334
"Warning: We noticed that you are using Arm Compiler 5. "
@@ -272,11 +273,11 @@ def compile_c(self, source, object, includes):
272273
def compile_cpp(self, source, object, includes):
273274
return self.compile(self.cppc, source, object, includes)
274275

275-
def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
276+
def correct_scatter_shebang(self, sc_fileref, cur_dir_name=None):
276277
"""Correct the shebang at the top of a scatter file.
277278
278279
Positional arguments:
279-
scatter_file -- the scatter file to correct
280+
sc_fileref -- FileRef object of the scatter file
280281
281282
Keyword arguments:
282283
cur_dir_name -- the name (not path) of the directory containing the
@@ -288,23 +289,23 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
288289
Side Effects:
289290
This method MAY write a new scatter file to disk
290291
"""
291-
with open(scatter_file, "r") as input:
292+
with open(sc_fileref.path, "r") as input:
292293
lines = input.readlines()
293294
if (lines[0].startswith(self.SHEBANG) or
294-
not lines[0].startswith("#!")):
295-
return scatter_file
295+
not lines[0].startswith("#!")):
296+
return sc_fileref
296297
else:
297298
new_scatter = join(self.build_dir, ".link_script.sct")
298299
if cur_dir_name is None:
299-
cur_dir_name = dirname(scatter_file)
300+
cur_dir_name = dirname(sc_fileref.path)
300301
self.SHEBANG += " -I %s" % cur_dir_name
301-
if self.need_update(new_scatter, [scatter_file]):
302+
if self.need_update(new_scatter, [sc_fileref.path]):
302303
with open(new_scatter, "w") as out:
303304
out.write(self.SHEBANG)
304305
out.write("\n")
305306
out.write("".join(lines[1:]))
306307

307-
return new_scatter
308+
return FileRef(".link_script.sct", new_scatter)
308309

309310
def get_link_command(
310311
self,
@@ -322,8 +323,9 @@ def get_link_command(
322323
if lib_dirs:
323324
args.extend(["--userlibpath", ",".join(lib_dirs)])
324325
if scatter_file:
325-
new_scatter = self.correct_scatter_shebang(scatter_file)
326-
args.extend(["--scatter", new_scatter])
326+
scatter_name = relpath(scatter_file)
327+
new_scatter = self.correct_scatter_shebang(FileRef(scatter_name, scatter_file))
328+
args.extend(["--scatter", new_scatter.path])
327329

328330
cmd = self.ld + args
329331

0 commit comments

Comments
 (0)