47
47
from tools .build_api import mcu_toolchain_list
48
48
from tools .build_api import mcu_target_list
49
49
from tools .build_api import merge_build_data
50
- from tools .build_api import get_toolchain_name
51
- from utils import argparse_filestring_type
52
- from utils import argparse_many
53
- from utils import argparse_dir_not_parent
54
- from tools .toolchains import TOOLCHAIN_CLASSES , TOOLCHAIN_PATHS
50
+ from tools .build_api import find_valid_toolchain
51
+ from tools .utils import argparse_filestring_type
52
+ from tools .utils import argparse_many
53
+ from tools .utils import argparse_dir_not_parent
54
+ from tools .utils import NoValidToolchainException
55
+ from tools .utils import print_end_warnings
55
56
from tools .settings import ROOT
56
57
from tools .targets import Target
57
58
@@ -68,8 +69,8 @@ def default_args_dict(options):
68
69
ignore = options .ignore
69
70
)
70
71
71
-
72
- def wrapped_build_project ( src_dir , build_dir , mcu , * args , ** kwargs ):
72
+ def wrapped_build_project ( src_dir , build_dir , mcu , end_warnings , options , * args , ** kwargs ):
73
+ error = False
73
74
try :
74
75
bin_file , update_file = build_project (
75
76
src_dir , build_dir , mcu , * args , ** kwargs
@@ -80,17 +81,22 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
80
81
except KeyboardInterrupt as e :
81
82
print ("\n [CTRL+c] exit" )
82
83
except NotSupportedException as e :
83
- print ("\n Could not compile for %s: %s" % (mcu , str (e )))
84
+ print ("\n Could not compile for {}: {}" .format (mcu , str (e )))
85
+ error = True
84
86
except Exception as e :
85
87
if options .verbose :
86
88
import traceback
87
89
traceback .print_exc (file = sys .stdout )
88
90
else :
89
- print ("[ERROR] %s" % str (e ))
90
- sys .exit (1 )
91
+ print ("[ERROR] {}" .format (str (e )))
91
92
93
+ error = True
92
94
93
- if __name__ == '__main__' :
95
+ print_end_warnings (end_warnings )
96
+ if error :
97
+ sys .exit (1 )
98
+
99
+ def main ():
94
100
# Parse Options
95
101
parser = get_default_options_parser (add_app_config = True )
96
102
@@ -282,6 +288,8 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
282
288
)
283
289
options = parser .parse_args ()
284
290
291
+ end_warnings = []
292
+
285
293
if options .supported_toolchains :
286
294
if options .supported_toolchains == "matrix" :
287
295
print (mcu_toolchain_matrix (
@@ -323,21 +331,24 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
323
331
324
332
notify = TerminalNotifier (options .verbose , options .silent , options .color )
325
333
326
- toolchain_name = get_toolchain_name (target , toolchain )
327
- if not TOOLCHAIN_CLASSES [toolchain_name ].check_executable ():
328
- search_path = TOOLCHAIN_PATHS [toolchain_name ] or "No path set"
329
- args_error (parser , "Could not find executable for %s.\n "
330
- "Currently set search path: %s"
331
- % (toolchain_name , search_path ))
334
+ try :
335
+ toolchain_name , internal_tc_name , end_warnings = find_valid_toolchain (
336
+ target , toolchain
337
+ )
338
+ except NoValidToolchainException as e :
339
+ print_end_warnings (e .end_warnings )
340
+ args_error (parser , str (e ))
332
341
333
342
if options .source_dir is not None :
334
343
wrapped_build_project (
335
344
options .source_dir ,
336
345
options .build_dir ,
337
346
mcu ,
338
- toolchain ,
347
+ end_warnings ,
348
+ options ,
349
+ toolchain_name ,
339
350
notify = notify ,
340
- build_profile = extract_profile (parser , options , toolchain ),
351
+ build_profile = extract_profile (parser , options , internal_tc_name ),
341
352
** default_args_dict (options )
342
353
)
343
354
else :
@@ -389,13 +400,18 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
389
400
test .source_dir ,
390
401
build_dir ,
391
402
mcu ,
392
- toolchain ,
403
+ end_warnings ,
404
+ options ,
405
+ toolchain_name ,
393
406
set (test .dependencies ),
394
407
notify = notify ,
395
408
report = build_data_blob ,
396
409
inc_dirs = [dirname (MBED_LIBRARIES )],
397
- build_profile = extract_profile (parser , options , toolchain ),
410
+ build_profile = extract_profile (parser , options , internal_tc_name ),
398
411
** default_args_dict (options )
399
412
)
400
413
if options .build_data :
401
414
merge_build_data (options .build_data , build_data_blob , "application" )
415
+
416
+ if __name__ == '__main__' :
417
+ main ()
0 commit comments