22
22
23
23
from tools .targets import CORE_ARCH
24
24
from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
25
- from tools .utils import run_cmd , NotSupportedException
25
+ from tools .utils import run_cmd
26
+
26
27
27
28
class GCC (mbedToolchain ):
28
29
OFFICIALLY_SUPPORTED = True
@@ -37,15 +38,21 @@ class GCC(mbedToolchain):
37
38
38
39
def __init__ (self , target , notify = None , macros = None , build_profile = None ,
39
40
build_dir = None ):
40
- mbedToolchain .__init__ (self , target , notify , macros ,
41
- build_profile = build_profile , build_dir = build_dir )
42
-
43
- tool_path = TOOLCHAIN_PATHS ['GCC_ARM' ]
41
+ mbedToolchain .__init__ (
42
+ self ,
43
+ target ,
44
+ notify ,
45
+ macros ,
46
+ build_profile = build_profile ,
47
+ build_dir = build_dir
48
+ )
49
+
50
+ tool_path = TOOLCHAIN_PATHS ['GCC_ARM' ]
44
51
# Add flags for current size setting
45
52
default_lib = "std"
46
53
if hasattr (target , "default_lib" ):
47
54
default_lib = target .default_lib
48
- elif hasattr (target , "default_build" ): # Legacy
55
+ elif hasattr (target , "default_build" ):
49
56
default_lib = target .default_build
50
57
51
58
if default_lib == "small" :
@@ -109,8 +116,8 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
109
116
main_cc = join (tool_path , "arm-none-eabi-gcc" )
110
117
main_cppc = join (tool_path , "arm-none-eabi-g++" )
111
118
self .asm = [main_cc ] + self .flags ['asm' ] + self .flags ["common" ]
112
- self .cc = [main_cc ]
113
- self .cppc = [main_cppc ]
119
+ self .cc = [main_cc ]
120
+ self .cppc = [main_cppc ]
114
121
self .cc += self .flags ['c' ] + self .flags ['common' ]
115
122
self .cppc += self .flags ['cxx' ] + self .flags ['common' ]
116
123
@@ -129,9 +136,13 @@ def version_check(self):
129
136
stdout , _ , retcode = run_cmd ([self .cc [0 ], "--version" ], redirect = True )
130
137
msg = None
131
138
match = self .GCC_VERSION_RE .search (stdout .encode ("utf-8" ))
132
- found_version = LooseVersion (match .group (0 ).decode ('utf-8' )) if match else None
139
+ if match :
140
+ found_version = LooseVersion (match .group (0 ).decode ('utf-8' ))
141
+ else :
142
+ found_version = None
133
143
min_ver , max_ver = self .GCC_RANGE
134
- if found_version and (found_version < min_ver or found_version >= max_ver ):
144
+ if found_version and (found_version < min_ver
145
+ or found_version >= max_ver ):
135
146
msg = ("Compiler version mismatch: Have {}; "
136
147
"expected version >= {} and < {}"
137
148
.format (found_version , min_ver , max_ver ))
@@ -196,7 +207,9 @@ def get_compile_options(self, defines, includes, for_asm=False):
196
207
197
208
def assemble (self , source , object , includes ):
198
209
# Build assemble command
199
- cmd = self .asm + self .get_compile_options (self .get_symbols (True ), includes ) + ["-o" , object , source ]
210
+ cmd = self .asm + self .get_compile_options (
211
+ self .get_symbols (True ), includes
212
+ ) + ["-o" , object , source ]
200
213
201
214
# Return command array, don't execute
202
215
return [cmd ]
@@ -230,15 +243,23 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
230
243
# Preprocess
231
244
if mem_map :
232
245
preproc_output = join (dirname (output ), ".link_script.ld" )
233
- cmd = (self .preproc + [mem_map ] + self .ld [1 :] +
234
- [ "-o" , preproc_output ])
246
+ cmd = (
247
+ self .preproc + [mem_map ] + self .ld [1 :] + ["-o" , preproc_output ]
248
+ )
235
249
self .notify .cc_verbose ("Preproc: %s" % ' ' .join (cmd ))
236
250
self .default_cmd (cmd )
237
251
mem_map = preproc_output
238
252
239
253
# Build linker command
240
254
map_file = splitext (output )[0 ] + ".map"
241
- cmd = self .ld + ["-o" , output , "-Wl,-Map=%s" % map_file ] + objects + ["-Wl,--start-group" ] + libs + ["-Wl,--end-group" ]
255
+ cmd = (
256
+ self .ld +
257
+ ["-o" , output , "-Wl,-Map=%s" % map_file ] +
258
+ objects +
259
+ ["-Wl,--start-group" ] +
260
+ libs +
261
+ ["-Wl,--end-group" ]
262
+ )
242
263
243
264
if mem_map :
244
265
cmd .extend (['-T' , mem_map ])
@@ -291,9 +312,12 @@ def redirect_symbol(source, sync, build_dir):
291
312
@staticmethod
292
313
def check_executable ():
293
314
"""Returns True if the executable (arm-none-eabi-gcc) location
294
- specified by the user exists OR the executable can be found on the PATH.
295
- Returns False otherwise."""
296
- if not TOOLCHAIN_PATHS ['GCC_ARM' ] or not exists (TOOLCHAIN_PATHS ['GCC_ARM' ]):
315
+ specified by the user exists OR the executable can be found on the
316
+ PATH. Returns False otherwise."""
317
+ if (
318
+ not TOOLCHAIN_PATHS ['GCC_ARM' ] or
319
+ not exists (TOOLCHAIN_PATHS ['GCC_ARM' ])
320
+ ):
297
321
if find_executable ('arm-none-eabi-gcc' ):
298
322
TOOLCHAIN_PATHS ['GCC_ARM' ] = ''
299
323
return True
@@ -303,5 +327,6 @@ def check_executable():
303
327
exec_name = join (TOOLCHAIN_PATHS ['GCC_ARM' ], 'arm-none-eabi-gcc' )
304
328
return exists (exec_name ) or exists (exec_name + '.exe' )
305
329
330
+
306
331
class GCC_ARM (GCC ):
307
332
pass
0 commit comments