15
15
limitations under the License.
16
16
"""
17
17
from __future__ import print_function , absolute_import
18
- from builtins import str
18
+ from builtins import str # noqa: F401
19
19
20
20
import re
21
21
from copy import copy
22
- from os .path import join , dirname , splitext , basename , exists , relpath , isfile
23
- from os import makedirs , write , curdir , remove
22
+ from os .path import join , dirname , splitext , basename , exists , isfile
23
+ from os import makedirs , write , remove
24
24
from tempfile import mkstemp
25
25
from shutil import rmtree
26
26
from distutils .version import LooseVersion
29
29
from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
30
30
from tools .utils import mkdir , NotSupportedException , run_cmd
31
31
32
+
32
33
class ARM (mbedToolchain ):
33
34
LINKER_EXT = '.sct'
34
35
LIBRARY_EXT = '.ar'
35
36
36
37
STD_LIB_NAME = "%s.ar"
37
- DIAGNOSTIC_PATTERN = re .compile ('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)' )
38
- INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
38
+ DIAGNOSTIC_PATTERN = re .compile ('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)' )
39
+ INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
39
40
DEP_PATTERN = re .compile ('\S+:\s(?P<file>.+)\n ' )
40
41
SHEBANG = "#! armcc -E"
41
- SUPPORTED_CORES = ["Cortex-M0" , "Cortex-M0+" , "Cortex-M3" , "Cortex-M4" ,
42
- "Cortex-M4F" , "Cortex-M7" , "Cortex-M7F" , "Cortex-M7FD" , "Cortex-A9" ]
42
+ SUPPORTED_CORES = [
43
+ "Cortex-M0" , "Cortex-M0+" , "Cortex-M3" , "Cortex-M4" , "Cortex-M4F" ,
44
+ "Cortex-M7" , "Cortex-M7F" , "Cortex-M7FD" , "Cortex-A9"
45
+ ]
43
46
ARMCC_RANGE = (LooseVersion ("5.06" ), LooseVersion ("5.07" ))
44
47
ARMCC_VERSION_RE = re .compile (b"Component: ARM Compiler (\d+\.\d+)" )
45
48
@@ -81,15 +84,17 @@ def __init__(self, target, notify=None, macros=None,
81
84
cpu = target .core
82
85
83
86
ARM_BIN = join (TOOLCHAIN_PATHS ['ARM' ], "bin" )
84
- ARM_INC = join (TOOLCHAIN_PATHS ['ARM' ], "include" )
85
87
86
88
main_cc = join (ARM_BIN , "armcc" )
87
89
88
90
self .flags ['common' ] += ["--cpu=%s" % cpu ]
89
91
90
92
self .asm = [main_cc ] + self .flags ['common' ] + self .flags ['asm' ]
91
93
self .cc = [main_cc ] + self .flags ['common' ] + self .flags ['c' ]
92
- self .cppc = [main_cc ] + self .flags ['common' ] + self .flags ['c' ] + self .flags ['cxx' ]
94
+ self .cppc = (
95
+ [main_cc ] + self .flags ['common' ] +
96
+ self .flags ['c' ] + self .flags ['cxx' ]
97
+ )
93
98
94
99
self .ld = [join (ARM_BIN , "armlink" )] + self .flags ['ld' ]
95
100
@@ -103,9 +108,13 @@ def version_check(self):
103
108
msg = None
104
109
min_ver , max_ver = self .ARMCC_RANGE
105
110
match = self .ARMCC_VERSION_RE .search (stdout .encode ("utf-8" ))
106
- found_version = LooseVersion (match .group (1 ).decode ("utf-8" )) if match else None
111
+ if match :
112
+ found_version = LooseVersion (match .group (1 ).decode ("utf-8" ))
113
+ else :
114
+ found_version = None
107
115
min_ver , max_ver = self .ARMCC_RANGE
108
- if found_version and (found_version < min_ver or found_version >= max_ver ):
116
+ if found_version and (found_version < min_ver
117
+ or found_version >= max_ver ):
109
118
msg = ("Compiler version mismatch: Have {}; "
110
119
"expected version >= {} and < {}"
111
120
.format (found_version , min_ver , max_ver ))
@@ -134,8 +143,11 @@ def parse_dependencies(self, dep_path):
134
143
for line in open (dep_path ).readlines ():
135
144
match = ARM .DEP_PATTERN .match (line )
136
145
if match is not None :
137
- #we need to append chroot, because when the .d files are generated the compiler is chrooted
138
- dependencies .append ((self .CHROOT if self .CHROOT else '' ) + match .group ('file' ))
146
+ # we need to append chroot, because when the .d files are
147
+ # generated the compiler is chrooted
148
+ dependencies .append (
149
+ (self .CHROOT if self .CHROOT else '' ) + match .group ('file' )
150
+ )
139
151
return dependencies
140
152
141
153
def parse_output (self , output ):
@@ -150,14 +162,18 @@ def parse_output(self, output):
150
162
'severity' : match .group ('severity' ).lower (),
151
163
'file' : match .group ('file' ),
152
164
'line' : match .group ('line' ),
153
- 'col' : match .group ('column' ) if match .group ('column' ) else 0 ,
154
165
'message' : match .group ('message' ),
155
166
'text' : '' ,
156
167
'target_name' : self .target .name ,
157
168
'toolchain_name' : self .name
158
169
}
170
+ if match .group ('column' ):
171
+ msg ['col' ] = match .group ('column' )
172
+ else :
173
+ msg ['col' ] = 0
159
174
elif msg is not None :
160
- # Determine the warning/error column by calculating the ^ position
175
+ # Determine the warning/error column by calculating the '^'
176
+ # position
161
177
match = ARM .INDEX_PATTERN .match (line )
162
178
if match is not None :
163
179
msg ['col' ] = len (match .group ('col' ))
@@ -244,7 +260,7 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
244
260
with open (scatter_file , "r" ) as input :
245
261
lines = input .readlines ()
246
262
if (lines [0 ].startswith (self .SHEBANG ) or
247
- not lines [0 ].startswith ("#!" )):
263
+ not lines [0 ].startswith ("#!" )):
248
264
return scatter_file
249
265
else :
250
266
new_scatter = join (self .build_dir , ".link_script.sct" )
@@ -290,7 +306,8 @@ def archive(self, objects, lib_path):
290
306
291
307
def binary (self , resources , elf , bin ):
292
308
_ , fmt = splitext (bin )
293
- # On .hex format, combine multiple .hex files (for multiple load regions) into one
309
+ # On .hex format, combine multiple .hex files (for multiple load
310
+ # regions) into one
294
311
bin_arg = {".bin" : "--bin" , ".hex" : "--i32combined" }[fmt ]
295
312
cmd = [self .elf2bin , bin_arg , '-o' , bin , elf ]
296
313
@@ -322,46 +339,95 @@ def redirect_symbol(source, sync, build_dir):
322
339
323
340
324
341
class ARM_STD (ARM ):
342
+
325
343
OFFICIALLY_SUPPORTED = True
326
- def __init__ (self , target , notify = None , macros = None ,
327
- build_profile = None , build_dir = None ):
328
- ARM .__init__ (self , target , notify , macros , build_dir = build_dir ,
329
- build_profile = build_profile )
344
+
345
+ def __init__ (
346
+ self ,
347
+ target ,
348
+ notify = None ,
349
+ macros = None ,
350
+ build_profile = None ,
351
+ build_dir = None
352
+ ):
353
+ ARM .__init__ (
354
+ self ,
355
+ target ,
356
+ notify ,
357
+ macros ,
358
+ build_dir = build_dir ,
359
+ build_profile = build_profile
360
+ )
330
361
if int (target .build_tools_metadata ["version" ]) > 0 :
331
- #check only for ARMC5 because ARM_STD means using ARMC5, and thus supported_toolchains must include ARMC5
362
+ #check only for ARMC5 because ARM_STD means using ARMC5, and thus
363
+ # supported_toolchains must include ARMC5
332
364
if "ARMC5" not in target .supported_toolchains :
333
- raise NotSupportedException ("ARM compiler 5 support is required for ARM build" )
365
+ raise NotSupportedException (
366
+ "ARM compiler 5 support is required for ARM build"
367
+ )
334
368
else :
335
- if not set (("ARM" , "uARM" )).intersection (set (target .supported_toolchains )):
336
- raise NotSupportedException ("ARM/uARM compiler support is required for ARM build" )
369
+ if not set (("ARM" , "uARM" )).intersection (set (
370
+ target .supported_toolchains
371
+ )):
372
+ raise NotSupportedException (
373
+ "ARM/uARM compiler support is required for ARM build"
374
+ )
337
375
338
376
class ARM_MICRO (ARM ):
377
+
339
378
PATCHED_LIBRARY = False
379
+
340
380
OFFICIALLY_SUPPORTED = True
341
- def __init__ (self , target , notify = None , macros = None ,
342
- silent = False , extra_verbose = False , build_profile = None ,
343
- build_dir = None ):
344
- target .default_toolchain = "uARM"
345
381
382
+ def __init__ (
383
+ self ,
384
+ target ,
385
+ notify = None ,
386
+ macros = None ,
387
+ silent = False ,
388
+ extra_verbose = False ,
389
+ build_profile = None ,
390
+ build_dir = None
391
+ ):
392
+ target .default_toolchain = "uARM"
346
393
if int (target .build_tools_metadata ["version" ]) > 0 :
347
- #At this point we already know that we want to use ARMC5+Microlib, so check for if they are supported
348
- #For, AC6+Microlib we still use ARMC6 class
349
- if not set (("ARMC5" ,"uARM" )).issubset (set (target .supported_toolchains )):
350
- raise NotSupportedException ("ARM/uARM compiler support is required for ARM build" )
394
+ # At this point we already know that we want to use ARMC5+Microlib
395
+ # so check for if they are supported For, AC6+Microlib we still
396
+ # use ARMC6 class
397
+ if not set (("ARMC5" ,"uARM" )).issubset (set (
398
+ target .supported_toolchains
399
+ )):
400
+ raise NotSupportedException (
401
+ "ARM/uARM compiler support is required for ARM build"
402
+ )
351
403
else :
352
- if not set (("ARM" , "uARM" )).intersection (set (target .supported_toolchains )):
353
- raise NotSupportedException ("ARM/uARM compiler support is required for ARM build" )
354
- ARM .__init__ (self , target , notify , macros , build_dir = build_dir ,
355
- build_profile = build_profile )
404
+ if not set (("ARM" , "uARM" )).intersection (set (
405
+ target .supported_toolchains
406
+ )):
407
+ raise NotSupportedException (
408
+ "ARM/uARM compiler support is required for ARM build"
409
+ )
410
+ ARM .__init__ (
411
+ self ,
412
+ target ,
413
+ notify ,
414
+ macros ,
415
+ build_dir = build_dir ,
416
+ build_profile = build_profile
417
+ )
418
+
356
419
357
420
class ARMC6 (ARM_STD ):
358
- OFFICIALLY_SUPPORTED = True
421
+
422
+ OFFICIALLY_SUPPORTED = False
359
423
SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
360
- SUPPORTED_CORES = ["Cortex-M0" , "Cortex-M0+" , "Cortex-M3" , "Cortex-M4" ,
361
- "Cortex-M4F" , "Cortex-M7" , "Cortex-M7F" , "Cortex-M7FD" ,
362
- "Cortex-M23" , "Cortex-M23-NS" , "Cortex-M33" , "Cortex-M33F" ,
363
- "Cortex-M33-NS" , "Cortex-M33F-NS" , "Cortex-M33FE-NS" , "Cortex-M33FE" ,
364
- "Cortex-A9" ]
424
+ SUPPORTED_CORES = [
425
+ "Cortex-M0" , "Cortex-M0+" , "Cortex-M3" , "Cortex-M4" ,
426
+ "Cortex-M4F" , "Cortex-M7" , "Cortex-M7F" , "Cortex-M7FD" ,
427
+ "Cortex-M23" , "Cortex-M23-NS" , "Cortex-M33" , "Cortex-M33F" ,
428
+ "Cortex-M33-NS" , "Cortex-M33F-NS" , "Cortex-M33FE-NS" , "Cortex-M33FE" ,
429
+ "Cortex-A9"
430
+ ]
365
431
ARMCC_RANGE = (LooseVersion ("6.10" ), LooseVersion ("7.0" ))
366
432
367
433
@staticmethod
@@ -375,12 +441,20 @@ def __init__(self, target, *args, **kwargs):
375
441
"this compiler does not support the core %s" % target .core )
376
442
377
443
if int (target .build_tools_metadata ["version" ]) > 0 :
378
- if not set (("ARM" , "ARMC6" , "uARM" )).intersection (set (target .supported_toolchains )):
379
- raise NotSupportedException ("ARM/ARMC6 compiler support is required for ARMC6 build" )
444
+ if not set (("ARM" , "ARMC6" , "uARM" )).intersection (set (
445
+ target .supported_toolchains
446
+ )):
447
+ raise NotSupportedException (
448
+ "ARM/ARMC6 compiler support is required for ARMC6 build"
449
+ )
380
450
else :
381
- if not set (("ARM" , "ARMC6" )).intersection (set (target .supported_toolchains )):
382
- raise NotSupportedException ("ARM/ARMC6 compiler support is required for ARMC6 build" )
383
-
451
+ if not set (("ARM" , "ARMC6" )).intersection (set (
452
+ target .supported_toolchains
453
+ )):
454
+ raise NotSupportedException (
455
+ "ARM/ARMC6 compiler support is required for ARMC6 build"
456
+ )
457
+
384
458
if getattr (target , "default_toolchain" , "ARMC6" ) == "uARM" :
385
459
if "-DMBED_RTOS_SINGLE_THREAD" not in self .flags ['common' ]:
386
460
self .flags ['common' ].append ("-DMBED_RTOS_SINGLE_THREAD" )
@@ -389,15 +463,16 @@ def __init__(self, target, *args, **kwargs):
389
463
if "--library_type=microlib" not in self .flags ['ld' ]:
390
464
self .flags ['ld' ].append ("--library_type=microlib" )
391
465
if "-Wl,--library_type=microlib" not in self .flags ['c' ]:
392
- self .flags ['c' ].append ("-Wl,--library_type=microlib" )
466
+ self .flags ['c' ].append ("-Wl,--library_type=microlib" )
393
467
if "-Wl,--library_type=microlib" not in self .flags ['cxx' ]:
394
- self .flags ['cxx' ].append ("-Wl,--library_type=microlib" )
468
+ self .flags ['cxx' ].append ("-Wl,--library_type=microlib" )
395
469
if "--library_type=microlib" not in self .flags ['asm' ]:
396
- self .flags ['asm' ].append ("--library_type=microlib" )
470
+ self .flags ['asm' ].append ("--library_type=microlib" )
397
471
398
472
core = target .core
399
473
if CORE_ARCH [target .core ] == 8 :
400
- if (not target .core .endswith ("-NS" )) and kwargs .get ('build_dir' , False ):
474
+ if ((not target .core .endswith ("-NS" )) and
475
+ kwargs .get ('build_dir' , False )):
401
476
# Create Secure library
402
477
build_dir = kwargs ['build_dir' ]
403
478
secure_file = join (build_dir , "cmse_lib.o" )
@@ -464,8 +539,10 @@ def __init__(self, target, *args, **kwargs):
464
539
self .flags ['common' ] + self .flags ['c' ])
465
540
self .cppc = ([join (TOOLCHAIN_PATHS ["ARMC6" ], "armclang" )] +
466
541
self .flags ['common' ] + self .flags ['cxx' ])
467
- self .asm = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armasm" )] + self .flags ['asm' ]
468
- self .ld = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armlink" )] + self .flags ['ld' ]
542
+ self .asm = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armasm" )]
543
+ self .asm += self .flags ['asm' ]
544
+ self .ld = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armlink" )]
545
+ self .ld += self .flags ['ld' ]
469
546
self .ar = join (TOOLCHAIN_PATHS ["ARMC6" ], "armar" )
470
547
self .elf2bin = join (TOOLCHAIN_PATHS ["ARMC6" ], "fromelf" )
471
548
@@ -499,8 +576,10 @@ def get_compile_options(self, defines, includes, for_asm=False):
499
576
if config_header :
500
577
opts .extend (self .get_config_option (config_header ))
501
578
if for_asm :
502
- return ["--cpreproc" ,
503
- "--cpreproc_opts=%s" % "," .join (self .flags ['common' ] + opts )]
579
+ return [
580
+ "--cpreproc" ,
581
+ "--cpreproc_opts=%s" % "," .join (self .flags ['common' ] + opts )
582
+ ]
504
583
return opts
505
584
506
585
def assemble (self , source , object , includes ):
0 commit comments