1
1
"""
2
2
mbed SDK
3
- Copyright (c) 2011-2013 ARM Limited
3
+ Copyright (c) 2011-2019 ARM Limited
4
4
5
5
Licensed under the Apache License, Version 2.0 (the "License");
6
6
you may not use this file except in compliance with the License.
19
19
20
20
import re
21
21
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
23
23
from os import makedirs , write , remove
24
24
from tempfile import mkstemp
25
25
from shutil import rmtree
28
28
from tools .targets import CORE_ARCH
29
29
from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
30
30
from tools .utils import mkdir , NotSupportedException , run_cmd
31
+ from tools .resources import FileRef
31
32
32
33
ARMC5_MIGRATION_WARNING = (
33
34
"Warning: We noticed that you are using Arm Compiler 5. "
@@ -272,11 +273,11 @@ def compile_c(self, source, object, includes):
272
273
def compile_cpp (self , source , object , includes ):
273
274
return self .compile (self .cppc , source , object , includes )
274
275
275
- def correct_scatter_shebang (self , scatter_file , cur_dir_name = None ):
276
+ def correct_scatter_shebang (self , sc_fileref , cur_dir_name = None ):
276
277
"""Correct the shebang at the top of a scatter file.
277
278
278
279
Positional arguments:
279
- scatter_file -- the scatter file to correct
280
+ sc_fileref -- FileRef object of the scatter file
280
281
281
282
Keyword arguments:
282
283
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):
288
289
Side Effects:
289
290
This method MAY write a new scatter file to disk
290
291
"""
291
- with open (scatter_file , "r" ) as input :
292
+ with open (sc_fileref . path , "r" ) as input :
292
293
lines = input .readlines ()
293
294
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
296
297
else :
297
298
new_scatter = join (self .build_dir , ".link_script.sct" )
298
299
if cur_dir_name is None :
299
- cur_dir_name = dirname (scatter_file )
300
+ cur_dir_name = dirname (sc_fileref . path )
300
301
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 ]):
302
303
with open (new_scatter , "w" ) as out :
303
304
out .write (self .SHEBANG )
304
305
out .write ("\n " )
305
306
out .write ("" .join (lines [1 :]))
306
307
307
- return new_scatter
308
+ return FileRef ( ".link_script.sct" , new_scatter )
308
309
309
310
def get_link_command (
310
311
self ,
@@ -322,8 +323,9 @@ def get_link_command(
322
323
if lib_dirs :
323
324
args .extend (["--userlibpath" , "," .join (lib_dirs )])
324
325
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 ])
327
329
328
330
cmd = self .ld + args
329
331
0 commit comments