11"""
22mbed SDK
3- Copyright (c) 2011-2013 ARM Limited
3+ Copyright (c) 2011-2019 ARM Limited
44
55Licensed under the Apache License, Version 2.0 (the "License");
66you may not use this file except in compliance with the License.
1919
2020import re
2121from 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
2323from os import makedirs , write , remove
2424from tempfile import mkstemp
2525from shutil import rmtree
2828from tools .targets import CORE_ARCH
2929from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
3030from tools .utils import mkdir , NotSupportedException , run_cmd
31+ from tools .resources import FileRef
3132
3233ARMC5_MIGRATION_WARNING = (
3334 "Warning: We noticed that you are using Arm Compiler 5. "
@@ -272,39 +273,39 @@ 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
283284 scatter file
284285
285286 Return:
286- The location of the correct scatter file
287+ The FileRef of the correct scatter file
287288
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