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
33
34
class ARM (mbedToolchain ):
@@ -241,11 +242,11 @@ def compile_c(self, source, object, includes):
241
242
def compile_cpp (self , source , object , includes ):
242
243
return self .compile (self .cppc , source , object , includes )
243
244
244
- def correct_scatter_shebang (self , scatter_file , cur_dir_name = None ):
245
+ def correct_scatter_shebang (self , sc_fileref , cur_dir_name = None ):
245
246
"""Correct the shebang at the top of a scatter file.
246
247
247
248
Positional arguments:
248
- scatter_file -- the scatter file to correct
249
+ sc_fileref -- FileRef object of the scatter file
249
250
250
251
Keyword arguments:
251
252
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):
257
258
Side Effects:
258
259
This method MAY write a new scatter file to disk
259
260
"""
260
- with open (scatter_file , "r" ) as input :
261
+ with open (sc_fileref . path , "r" ) as input :
261
262
lines = input .readlines ()
262
263
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
265
266
else :
266
267
new_scatter = join (self .build_dir , ".link_script.sct" )
267
268
if cur_dir_name is None :
268
- cur_dir_name = dirname (scatter_file )
269
+ cur_dir_name = dirname (sc_fileref . path )
269
270
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 ]):
271
272
with open (new_scatter , "w" ) as out :
272
273
out .write (self .SHEBANG )
273
274
out .write ("\n " )
274
275
out .write ("" .join (lines [1 :]))
275
276
276
- return new_scatter
277
+ return FileRef ( ".link_script.sct" , new_scatter )
277
278
278
279
def link (self , output , objects , libraries , lib_dirs , scatter_file ):
279
280
base , _ = splitext (output )
@@ -284,8 +285,9 @@ def link(self, output, objects, libraries, lib_dirs, scatter_file):
284
285
if lib_dirs :
285
286
args .extend (["--userlibpath" , "," .join (lib_dirs )])
286
287
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 ])
289
291
290
292
cmd = self .ld + args
291
293
0 commit comments