32
32
import re
33
33
34
34
#Disables multiprocessing if set to higher number than the host machine CPUs
35
- CPU_COUNT_MIN = 1
35
+ CPU_COUNT_MIN = 1
36
36
37
37
def print_notify (event ):
38
38
# Default command line notification
@@ -74,7 +74,7 @@ def compile_worker(job):
74
74
'output' : stderr ,
75
75
'command' : command
76
76
})
77
-
77
+
78
78
return {
79
79
'source' : job ['source' ],
80
80
'object' : job ['object' ],
@@ -235,11 +235,11 @@ def __init__(self, target, options=None, notify=None, macros=None):
235
235
self .build_all = False
236
236
self .timestamp = time ()
237
237
self .jobs = 1
238
-
238
+
239
239
self .CHROOT = None
240
-
240
+
241
241
self .mp_pool = None
242
-
242
+
243
243
def __exit__ (self ):
244
244
if self .mp_pool is not None :
245
245
self .mp_pool .terminate ()
@@ -271,8 +271,9 @@ def get_symbols(self):
271
271
self .symbols .append ('MBED_USERNAME=' + MBED_ORG_USER )
272
272
273
273
# Add target's symbols
274
- for macro in self .target .macros :
275
- self .symbols .append (macro )
274
+ self .symbols += self .target .macros
275
+ # Add extra symbols passed via 'macros' parameter
276
+ self .symbols += self .macros
276
277
277
278
# Form factor variables
278
279
if hasattr (self .target , 'supported_form_factors' ):
@@ -310,7 +311,7 @@ def need_update(self, target, dependencies):
310
311
return True
311
312
312
313
return False
313
-
314
+
314
315
def scan_resources (self , path ):
315
316
labels = self .get_labels ()
316
317
resources = Resources (path )
@@ -426,38 +427,38 @@ def relative_object_path(self, build_path, base_dir, source):
426
427
obj_dir = join (build_path , relpath (source_dir , base_dir ))
427
428
mkdir (obj_dir )
428
429
return join (obj_dir , name + '.o' )
429
-
430
+
430
431
def compile_sources (self , resources , build_path , inc_dirs = None ):
431
432
# Web IDE progress bar for project build
432
433
files_to_compile = resources .s_sources + resources .c_sources + resources .cpp_sources
433
434
self .to_be_compiled = len (files_to_compile )
434
435
self .compiled = 0
435
-
436
+
436
437
#for i in self.build_params:
437
438
# self.debug(i)
438
439
# self.debug("%s" % self.build_params[i])
439
-
440
+
440
441
inc_paths = resources .inc_dirs
441
442
if inc_dirs is not None :
442
443
inc_paths .extend (inc_dirs )
443
-
444
+
444
445
objects = []
445
446
queue = []
446
447
prev_dir = None
447
-
448
+
448
449
# The dependency checking for C/C++ is delegated to the compiler
449
450
base_path = resources .base_path
450
451
files_to_compile .sort ()
451
452
for source in files_to_compile :
452
453
_ , name , _ = split_path (source )
453
454
object = self .relative_object_path (build_path , base_path , source )
454
-
455
+
455
456
# Avoid multiple mkdir() calls on same work directory
456
457
work_dir = dirname (object )
457
458
if work_dir is not prev_dir :
458
459
prev_dir = work_dir
459
460
mkdir (work_dir )
460
-
461
+
461
462
# Queue mode (multiprocessing)
462
463
commands = self .compile_command (source , object , inc_paths )
463
464
if commands is not None :
@@ -481,7 +482,7 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
481
482
def compile_seq (self , queue , objects ):
482
483
for item in queue :
483
484
result = compile_worker (item )
484
-
485
+
485
486
self .compiled += 1
486
487
self .progress ("compile" , item ['source' ], build_update = True )
487
488
for res in result ['results' ]:
@@ -497,7 +498,7 @@ def compile_seq(self, queue, objects):
497
498
def compile_queue (self , queue , objects ):
498
499
jobs_count = int (self .jobs if self .jobs else cpu_count ())
499
500
p = Pool (processes = jobs_count )
500
-
501
+
501
502
results = []
502
503
for i in range (len (queue )):
503
504
results .append (p .apply_async (compile_worker , [queue [i ]]))
@@ -509,7 +510,7 @@ def compile_queue(self, queue, objects):
509
510
p .terminate ()
510
511
p .join ()
511
512
raise ToolException ("Compile did not finish in 5 minutes" )
512
-
513
+
513
514
pending = 0
514
515
for r in results :
515
516
if r ._ready is True :
@@ -535,7 +536,7 @@ def compile_queue(self, queue, objects):
535
536
pending += 1
536
537
if pending > jobs_count :
537
538
break
538
-
539
+
539
540
540
541
if len (results ) == 0 :
541
542
break
@@ -544,15 +545,15 @@ def compile_queue(self, queue, objects):
544
545
545
546
results = None
546
547
p .terminate ()
547
- p .join ()
548
-
548
+ p .join ()
549
+
549
550
return objects
550
551
551
552
def compile_command (self , source , object , includes ):
552
553
# Check dependencies
553
554
_ , ext = splitext (source )
554
555
ext = ext .lower ()
555
-
556
+
556
557
if ext == '.c' or ext == '.cpp' :
557
558
base , _ = splitext (object )
558
559
dep_path = base + '.d'
@@ -568,37 +569,37 @@ def compile_command(self, source, object, includes):
568
569
return self .assemble (source , object , includes )
569
570
else :
570
571
return False
571
-
572
+
572
573
return None
573
-
574
+
574
575
def compile_output (self , output = []):
575
576
rc = output [0 ]
576
577
stderr = output [1 ]
577
578
command = output [2 ]
578
-
579
+
579
580
# Parse output for Warnings and Errors
580
581
self .parse_output (stderr )
581
582
self .debug ("Return: %s" % rc )
582
583
self .debug ("Output: %s" % stderr )
583
-
584
+
584
585
# Check return code
585
586
if rc != 0 :
586
587
raise ToolException (stderr )
587
588
588
589
def compile (self , cc , source , object , includes ):
589
590
_ , ext = splitext (source )
590
591
ext = ext .lower ()
591
-
592
+
592
593
command = cc + ['-D%s' % s for s in self .get_symbols ()] + ["-I%s" % i for i in includes ] + ["-o" , object , source ]
593
-
594
+
594
595
if hasattr (self , "get_dep_opt" ):
595
596
base , _ = splitext (object )
596
597
dep_path = base + '.d'
597
598
command .extend (self .get_dep_opt (dep_path ))
598
-
599
+
599
600
if hasattr (self , "cc_extra" ):
600
601
command .extend (self .cc_extra (base ))
601
-
602
+
602
603
return [command ]
603
604
604
605
def compile_c (self , source , object , includes ):
@@ -650,7 +651,7 @@ def default_cmd(self, command):
650
651
stdout , stderr , rc = run_cmd (command )
651
652
self .debug ("Return: %s" % rc )
652
653
self .debug ("Output: %s" % ' ' .join (stdout ))
653
-
654
+
654
655
if rc != 0 :
655
656
for line in stderr .splitlines ():
656
657
self .tool_error (line )
0 commit comments