Skip to content

Commit 0035a19

Browse files
committed
Merge pull request #452 from PrzemekWirkus/macros-missing
Macros are not passed down to toolchain for compilation
2 parents 0f8a06d + a971352 commit 0035a19

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

workspace_tools/toolchains/__init__.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import re
3333

3434
#Disables multiprocessing if set to higher number than the host machine CPUs
35-
CPU_COUNT_MIN = 1
35+
CPU_COUNT_MIN = 1
3636

3737
def print_notify(event):
3838
# Default command line notification
@@ -74,7 +74,7 @@ def compile_worker(job):
7474
'output': stderr,
7575
'command': command
7676
})
77-
77+
7878
return {
7979
'source': job['source'],
8080
'object': job['object'],
@@ -235,11 +235,11 @@ def __init__(self, target, options=None, notify=None, macros=None):
235235
self.build_all = False
236236
self.timestamp = time()
237237
self.jobs = 1
238-
238+
239239
self.CHROOT = None
240-
240+
241241
self.mp_pool = None
242-
242+
243243
def __exit__(self):
244244
if self.mp_pool is not None:
245245
self.mp_pool.terminate()
@@ -271,8 +271,9 @@ def get_symbols(self):
271271
self.symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
272272

273273
# 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
276277

277278
# Form factor variables
278279
if hasattr(self.target, 'supported_form_factors'):
@@ -310,7 +311,7 @@ def need_update(self, target, dependencies):
310311
return True
311312

312313
return False
313-
314+
314315
def scan_resources(self, path):
315316
labels = self.get_labels()
316317
resources = Resources(path)
@@ -426,38 +427,38 @@ def relative_object_path(self, build_path, base_dir, source):
426427
obj_dir = join(build_path, relpath(source_dir, base_dir))
427428
mkdir(obj_dir)
428429
return join(obj_dir, name + '.o')
429-
430+
430431
def compile_sources(self, resources, build_path, inc_dirs=None):
431432
# Web IDE progress bar for project build
432433
files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
433434
self.to_be_compiled = len(files_to_compile)
434435
self.compiled = 0
435-
436+
436437
#for i in self.build_params:
437438
# self.debug(i)
438439
# self.debug("%s" % self.build_params[i])
439-
440+
440441
inc_paths = resources.inc_dirs
441442
if inc_dirs is not None:
442443
inc_paths.extend(inc_dirs)
443-
444+
444445
objects = []
445446
queue = []
446447
prev_dir = None
447-
448+
448449
# The dependency checking for C/C++ is delegated to the compiler
449450
base_path = resources.base_path
450451
files_to_compile.sort()
451452
for source in files_to_compile:
452453
_, name, _ = split_path(source)
453454
object = self.relative_object_path(build_path, base_path, source)
454-
455+
455456
# Avoid multiple mkdir() calls on same work directory
456457
work_dir = dirname(object)
457458
if work_dir is not prev_dir:
458459
prev_dir = work_dir
459460
mkdir(work_dir)
460-
461+
461462
# Queue mode (multiprocessing)
462463
commands = self.compile_command(source, object, inc_paths)
463464
if commands is not None:
@@ -481,7 +482,7 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
481482
def compile_seq(self, queue, objects):
482483
for item in queue:
483484
result = compile_worker(item)
484-
485+
485486
self.compiled += 1
486487
self.progress("compile", item['source'], build_update=True)
487488
for res in result['results']:
@@ -497,7 +498,7 @@ def compile_seq(self, queue, objects):
497498
def compile_queue(self, queue, objects):
498499
jobs_count = int(self.jobs if self.jobs else cpu_count())
499500
p = Pool(processes=jobs_count)
500-
501+
501502
results = []
502503
for i in range(len(queue)):
503504
results.append(p.apply_async(compile_worker, [queue[i]]))
@@ -509,7 +510,7 @@ def compile_queue(self, queue, objects):
509510
p.terminate()
510511
p.join()
511512
raise ToolException("Compile did not finish in 5 minutes")
512-
513+
513514
pending = 0
514515
for r in results:
515516
if r._ready is True:
@@ -535,7 +536,7 @@ def compile_queue(self, queue, objects):
535536
pending += 1
536537
if pending > jobs_count:
537538
break
538-
539+
539540

540541
if len(results) == 0:
541542
break
@@ -544,15 +545,15 @@ def compile_queue(self, queue, objects):
544545

545546
results = None
546547
p.terminate()
547-
p.join()
548-
548+
p.join()
549+
549550
return objects
550551

551552
def compile_command(self, source, object, includes):
552553
# Check dependencies
553554
_, ext = splitext(source)
554555
ext = ext.lower()
555-
556+
556557
if ext == '.c' or ext == '.cpp':
557558
base, _ = splitext(object)
558559
dep_path = base + '.d'
@@ -568,37 +569,37 @@ def compile_command(self, source, object, includes):
568569
return self.assemble(source, object, includes)
569570
else:
570571
return False
571-
572+
572573
return None
573-
574+
574575
def compile_output(self, output=[]):
575576
rc = output[0]
576577
stderr = output[1]
577578
command = output[2]
578-
579+
579580
# Parse output for Warnings and Errors
580581
self.parse_output(stderr)
581582
self.debug("Return: %s" % rc)
582583
self.debug("Output: %s" % stderr)
583-
584+
584585
# Check return code
585586
if rc != 0:
586587
raise ToolException(stderr)
587588

588589
def compile(self, cc, source, object, includes):
589590
_, ext = splitext(source)
590591
ext = ext.lower()
591-
592+
592593
command = cc + ['-D%s' % s for s in self.get_symbols()] + ["-I%s" % i for i in includes] + ["-o", object, source]
593-
594+
594595
if hasattr(self, "get_dep_opt"):
595596
base, _ = splitext(object)
596597
dep_path = base + '.d'
597598
command.extend(self.get_dep_opt(dep_path))
598-
599+
599600
if hasattr(self, "cc_extra"):
600601
command.extend(self.cc_extra(base))
601-
602+
602603
return [command]
603604

604605
def compile_c(self, source, object, includes):
@@ -650,7 +651,7 @@ def default_cmd(self, command):
650651
stdout, stderr, rc = run_cmd(command)
651652
self.debug("Return: %s" % rc)
652653
self.debug("Output: %s" % ' '.join(stdout))
653-
654+
654655
if rc != 0:
655656
for line in stderr.splitlines():
656657
self.tool_error(line)

0 commit comments

Comments
 (0)