Skip to content

Commit ad87f9d

Browse files
committed
Document code and mark which methods are used by the online build system
1 parent 74b7f9e commit ad87f9d

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

tools/toolchains/__init__.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,14 @@ def __str__(self):
188188

189189

190190
class mbedToolchain:
191+
# Verbose logging
191192
VERBOSE = True
193+
194+
# Compile C files as CPP
192195
COMPILE_C_AS_CPP = False
196+
197+
# Response files for compiling, includes, linking and archiving.
198+
# Not needed on posix systems where the typical arg limit is 2 megabytes
193199
RESPONSE_FILES = True
194200

195201
CORTEX_SYMBOLS = {
@@ -242,8 +248,6 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
242248
# Number of concurrent build jobs. 0 means auto (based on host system cores)
243249
self.jobs = 0
244250

245-
self.CHROOT = None
246-
247251
# Ignore patterns from .mbedignore files
248252
self.ignore_patterns = []
249253

@@ -285,12 +289,20 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
285289
# uVisor spepcific rules
286290
if 'UVISOR' in self.target.features and 'UVISOR_SUPPORTED' in self.target.extra_labels:
287291
self.target.core = re.sub(r"F$", '', self.target.core)
288-
292+
293+
# Stats cache is used to reduce the amount of IO requests to stat
294+
# header files during dependency change. See need_update()
289295
self.stat_cache = {}
290296

297+
# Used by the mbed Online Build System to build in chrooted environment
298+
self.CHROOT = None
299+
300+
# Call post __init__() hooks before the ARM/GCC_ARM/IAR toolchain __init__() takes over
291301
self.init()
292302

293-
# This allows post __init__() hooks. Do not use
303+
# Used for post __init__() hooks
304+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
305+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
294306
def init(self):
295307
return True
296308

@@ -340,6 +352,8 @@ def print_notify_verbose(self, event, silent=False):
340352
elif event['type'] == 'progress':
341353
self.print_notify(event) # standard handle
342354

355+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
356+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
343357
def notify(self, event):
344358
""" Little closure for notify functions
345359
"""
@@ -392,6 +406,8 @@ def get_labels(self):
392406
}
393407
return self.labels
394408

409+
410+
# Determine whether a source file needs updating/compiling
395411
def need_update(self, target, dependencies):
396412
if self.build_all:
397413
return True
@@ -601,6 +617,8 @@ def copy_files(self, files_paths, trg_path, resources=None, rel_path=None):
601617
mkdir(dirname(target))
602618
copyfile(source, target)
603619

620+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
621+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
604622
def relative_object_path(self, build_path, base_dir, source):
605623
source_dir, name, _ = split_path(source)
606624

@@ -610,6 +628,8 @@ def relative_object_path(self, build_path, base_dir, source):
610628
mkdir(obj_dir)
611629
return join(obj_dir, name + '.o')
612630

631+
# Generate response file for all includes.
632+
# ARM, GCC, IAR cross compatible
613633
def get_inc_file(self, includes):
614634
include_file = join(self.build_dir, ".includes_%s.txt" % self.inc_md5)
615635
if not exists(include_file):
@@ -625,6 +645,8 @@ def get_inc_file(self, includes):
625645
f.write(string)
626646
return include_file
627647

648+
# Generate response file for all objects when linking.
649+
# ARM, GCC, IAR cross compatible
628650
def get_link_file(self, cmd):
629651
link_file = join(self.build_dir, ".link_files.txt")
630652
with open(link_file, "wb") as f:
@@ -639,6 +661,8 @@ def get_link_file(self, cmd):
639661
f.write(string)
640662
return link_file
641663

664+
# Generate response file for all objects when archiving.
665+
# ARM, GCC, IAR cross compatible
642666
def get_arch_file(self, objects):
643667
archive_file = join(self.build_dir, ".archive_files.txt")
644668
with open(archive_file, "wb") as f:
@@ -649,6 +673,8 @@ def get_arch_file(self, objects):
649673
f.write(string)
650674
return archive_file
651675

676+
# THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
677+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
652678
def compile_sources(self, resources, build_path, inc_dirs=None):
653679
# Web IDE progress bar for project build
654680
files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
@@ -699,6 +725,7 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
699725
else:
700726
return self.compile_seq(queue, objects)
701727

728+
# Compile source files queue in sequential order
702729
def compile_seq(self, queue, objects):
703730
for item in queue:
704731
result = compile_worker(item)
@@ -715,6 +742,7 @@ def compile_seq(self, queue, objects):
715742
objects.append(result['object'])
716743
return objects
717744

745+
# Compile source files queue in parallel by creating pool of worker threads
718746
def compile_queue(self, queue, objects):
719747
jobs_count = int(self.jobs if self.jobs else cpu_count() * CPU_COEF)
720748
p = Pool(processes=jobs_count)
@@ -764,6 +792,7 @@ def compile_queue(self, queue, objects):
764792

765793
return objects
766794

795+
# Determine the compile command based on type of source file
767796
def compile_command(self, source, object, includes):
768797
# Check dependencies
769798
_, ext = splitext(source)
@@ -858,6 +887,8 @@ def link_program(self, r, tmp_path, name):
858887

859888
return bin, needed_update
860889

890+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
891+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
861892
def default_cmd(self, command):
862893
_stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
863894
self.debug("Return: %s"% _rc)
@@ -876,18 +907,24 @@ def default_cmd(self, command):
876907
def info(self, message):
877908
self.notify({'type': 'info', 'message': message})
878909

910+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
911+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
879912
def debug(self, message):
880913
if self.VERBOSE:
881914
if type(message) is ListType:
882915
message = ' '.join(message)
883916
message = "[DEBUG] " + message
884917
self.notify({'type': 'debug', 'message': message})
885918

919+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
920+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
886921
def cc_info(self, info=None):
887922
if info is not None:
888923
info['type'] = 'cc'
889924
self.notify(info)
890925

926+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
927+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
891928
def cc_verbose(self, message, file=""):
892929
self.debug(message)
893930

@@ -903,6 +940,8 @@ def tool_error(self, message):
903940
def var(self, key, value):
904941
self.notify({'type': 'var', 'key': key, 'val': value})
905942

943+
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
944+
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
906945
def mem_stats(self, map):
907946
"""! Creates parser object
908947
@param map Path to linker map file to parse and decode
@@ -957,7 +996,6 @@ def get_config_header(self):
957996
def get_config_macros(self):
958997
return Config.config_to_macros(self.config_data) if self.config_data else []
959998

960-
961999
from tools.settings import ARM_PATH
9621000
from tools.settings import GCC_ARM_PATH, GCC_CR_PATH
9631001
from tools.settings import IAR_PATH

tools/toolchains/arm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def parse_output(self, output):
108108
'toolchain_name': self.name
109109
}
110110
elif msg is not None:
111+
# Determine the warning/error column by calculating the ^ position
111112
match = ARM.INDEX_PATTERN.match(line)
112113
if match is not None:
113114
msg['col'] = len(match.group('col'))

tools/toolchains/gcc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def parse_output(self, output):
153153
'toolchain_name': self.name
154154
}
155155
elif msg is not None:
156+
# Determine the warning/error column by calculating the ^ position
156157
match = GCC.INDEX_PATTERN.match(line)
157158
if match is not None:
158159
msg['col'] = len(match.group('col'))

tools/toolchains/iar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def parse_output(self, output):
123123
'toolchain_name': self.name
124124
}
125125
elif msg is not None:
126+
# Determine the warning/error column by calculating the ^ position
126127
match = IAR.INDEX_PATTERN.match(line)
127128
if match is not None:
128129
msg['col'] = len(match.group('col'))

0 commit comments

Comments
 (0)