diff --git a/workspace_tools/build.py b/workspace_tools/build.py index 9477e2e2ad..2709592129 100755 --- a/workspace_tools/build.py +++ b/workspace_tools/build.py @@ -122,6 +122,12 @@ if __name__ == '__main__': default=False, help="Verbose diagnostic output") + parser.add_option("--silent", + action="store_true", + dest="silent", + default=False, + help="Silent diagnostic output (no copy, compile notification)") + parser.add_option("-x", "--extra-verbose-notifications", action="store_true", dest="extra_verbose_notify", @@ -213,14 +219,24 @@ if __name__ == '__main__': tt_id = "%s::%s" % (toolchain, target) try: mcu = TARGET_MAP[target] - lib_build_res = build_mbed_libs(mcu, toolchain, options=options.options, - notify=notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean, + lib_build_res = build_mbed_libs(mcu, toolchain, + options=options.options, + notify=notify, + verbose=options.verbose, + silent=options.silent, + jobs=options.jobs, + clean=options.clean, macros=options.macros) for lib_id in libraries: notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose) - build_lib(lib_id, mcu, toolchain, options=options.options, - notify=notify, verbose=options.verbose, clean=options.clean, - macros=options.macros, jobs=options.jobs) + build_lib(lib_id, mcu, toolchain, + options=options.options, + notify=notify, + verbose=options.verbose, + silent=options.silent, + clean=options.clean, + macros=options.macros, + jobs=options.jobs) if lib_build_res: successes.append(tt_id) else: @@ -234,6 +250,7 @@ if __name__ == '__main__': print e # Write summary of the builds + print print "Completed in: (%.2f)s" % (time() - start) print diff --git a/workspace_tools/build_api.py b/workspace_tools/build_api.py index 82055cacb6..2bfaff0d81 100644 --- a/workspace_tools/build_api.py +++ b/workspace_tools/build_api.py @@ -31,11 +31,11 @@ from workspace_tools.toolchains import TOOLCHAIN_CLASSES def build_project(src_path, build_path, target, toolchain_name, libraries_paths=None, options=None, linker_script=None, - clean=False, notify=None, verbose=False, name=None, macros=None, inc_dirs=None, jobs=1): + clean=False, notify=None, verbose=False, name=None, macros=None, inc_dirs=None, jobs=1, silent=False): """ This function builds project. Project can be for example one test / UT """ # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent) toolchain.VERBOSE = verbose toolchain.jobs = jobs toolchain.build_all = clean @@ -92,7 +92,7 @@ def build_project(src_path, build_path, target, toolchain_name, def build_library(src_paths, build_path, target, toolchain_name, dependencies_paths=None, options=None, name=None, clean=False, - notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None, jobs=1): + notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None, jobs=1, silent=False): """ src_path: the path of the source directory build_path: the path of the build directory target: ['LPC1768', 'LPC11U24', 'LPC2368'] @@ -112,7 +112,7 @@ def build_library(src_paths, build_path, target, toolchain_name, raise Exception("The library source folder does not exist: %s", src_path) # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent) toolchain.VERBOSE = verbose toolchain.jobs = jobs toolchain.build_all = clean @@ -162,7 +162,7 @@ def build_library(src_paths, build_path, target, toolchain_name, toolchain.build_library(objects, bin_path, name) -def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1): +def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False): """ Wrapper for build_library function. Function builds library in proper directory using all dependencies and macros defined by user. """ @@ -175,6 +175,7 @@ def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=Fals build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, verbose=verbose, + silent=silent, clean=clean, macros=MACROS, notify=notify, @@ -186,7 +187,7 @@ def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=Fals # We do have unique legacy conventions about how we build and package the mbed library -def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1): +def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False): """ Function returns True is library was built and false if building was skipped """ # Check toolchain support if toolchain_name not in target.supported_toolchains: @@ -196,7 +197,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F return False # Toolchain - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent) toolchain.VERBOSE = verbose toolchain.jobs = jobs toolchain.build_all = clean diff --git a/workspace_tools/build_travis.py b/workspace_tools/build_travis.py index 60d3847bc7..f4951e5960 100644 --- a/workspace_tools/build_travis.py +++ b/workspace_tools/build_travis.py @@ -64,6 +64,22 @@ build_list = ( ) ################################################################################ +# Configure example test building (linking against external mbed SDK libraries liek fat or rtos) + +linking_list = [ + {"target": "LPC1768", + "toolchains": "GCC_ARM", + "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_15", "MBED_16", "MBED_17"], + "eth" : ["NET_1", "NET_2", "NET_3", "NET_4"], + "fat" : ["MBED_A12", "MBED_19", "PERF_1", "PERF_2", "PERF_3"], + "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3"], + } + } + ] + +################################################################################ + # Driver def run_builds(dry_run): @@ -71,7 +87,7 @@ def run_builds(dry_run): toolchain_list = build["toolchains"] if type(toolchain_list) != type([]): toolchain_list = [toolchain_list] for toolchain in toolchain_list: - cmdline = "python workspace_tools/build.py -m %s -t %s -j 4 -c " % (build["target"], toolchain) + cmdline = "python workspace_tools/build.py -m %s -t %s -j 4 -c --silent "% (build["target"], toolchain) libs = build.get("libs", []) if libs: cmdline = cmdline + " ".join(["--" + l for l in libs]) @@ -80,5 +96,28 @@ def run_builds(dry_run): if os.system(cmdline) != 0: sys.exit(1) + +def run_test_linking(dry_run): + """ Function run make.py commands to build and link simple mbed SDK + tests against few libraries to make sure there are no simple linking errors. + """ + for link in linking_list: + toolchain_list = link["toolchains"] + if type(toolchain_list) != type([]): + toolchain_list = [toolchain_list] + for toolchain in toolchain_list: + tests = link["tests"] + # Call make.py for each test group for particular library + for test_lib in tests: + test_names = tests[test_lib] + test_lib_switch = "--" + test_lib if test_lib else "" + cmdline = "python workspace_tools/make.py -m %s -t %s -c --silent %s -n %s " % (link["target"], toolchain, test_lib_switch, ",".join(test_names)) + print "Executing: " + cmdline + if not dry_run: + if os.system(cmdline) != 0: + sys.exit(1) + + if __name__ == "__main__": run_builds("-s" in sys.argv) + run_test_linking("-s" in sys.argv) diff --git a/workspace_tools/make.py b/workspace_tools/make.py index 2383842439..932a03c125 100644 --- a/workspace_tools/make.py +++ b/workspace_tools/make.py @@ -49,15 +49,36 @@ except: if __name__ == '__main__': # Parse Options parser = get_default_options_parser() - parser.add_option("-p", type="int", dest="program", + parser.add_option("-p", + type="int", + dest="program", help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) - parser.add_option("-n", dest="program_name", + + parser.add_option("-n", + dest="program_name", help="The name of the desired test program") - parser.add_option("-j", "--jobs", type="int", dest="jobs", - default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") - parser.add_option("-v", "--verbose", action="store_true", dest="verbose", - default=False, help="Verbose diagnostic output") - parser.add_option("-D", "", action="append", dest="macros", + + parser.add_option("-j", "--jobs", + type="int", + dest="jobs", + default=1, + help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") + + parser.add_option("-v", "--verbose", + action="store_true", + dest="verbose", + default=False, + help="Verbose diagnostic output") + + parser.add_option("--silent", + action="store_true", + dest="silent", + default=False, + help="Silent diagnostic output (no copy, compile notification)") + + parser.add_option("-D", "", + action="append", + dest="macros", help="Add a macro definition") # Local run @@ -219,6 +240,7 @@ if __name__ == '__main__': linker_script=options.linker_script, clean=options.clean, verbose=options.verbose, + silent=options.silent, macros=options.macros, jobs=options.jobs) print 'Image: %s'% bin_file diff --git a/workspace_tools/toolchains/__init__.py b/workspace_tools/toolchains/__init__.py index e943133821..dd1a02a72d 100644 --- a/workspace_tools/toolchains/__init__.py +++ b/workspace_tools/toolchains/__init__.py @@ -16,6 +16,7 @@ limitations under the License. """ import re +import sys from os import stat, walk from copy import copy from time import time, sleep @@ -33,8 +34,9 @@ import workspace_tools.hooks as hooks #Disables multiprocessing if set to higher number than the host machine CPUs CPU_COUNT_MIN = 1 -def print_notify(event): - # Default command line notification +def print_notify(event, silent=False): + """ Default command line notification + """ if event['type'] in ['info', 'debug']: print event['message'] @@ -44,11 +46,12 @@ def print_notify(event): print '[%(severity)s] %(file)s@%(line)s: %(message)s' % event elif event['type'] == 'progress': - print '%s: %s' % (event['action'].title(), basename(event['file'])) + if not silent: + print '%s: %s' % (event['action'].title(), basename(event['file'])) - -def print_notify_verbose(event): - """ Default command line notification with more verbose mode """ +def print_notify_verbose(event, silent=False): + """ Default command line notification with more verbose mode + """ if event['type'] in ['info', 'debug']: print_notify(event) # standard handle @@ -204,22 +207,16 @@ class mbedToolchain: GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%" GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?Pwarning) \[(?P[^:]+):(?P\d+)\] \- (?P.*)"') - def __init__(self, target, options=None, notify=None, macros=None): + def __init__(self, target, options=None, notify=None, macros=None, silent=False): self.target = target self.name = self.__class__.__name__ self.hook = hooks.Hook(target, self) + self.silent = silent self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]]) - if notify is not None: - self.notify = notify - else: - self.notify = print_notify - - if options is None: - self.options = [] - else: - self.options = options + self.notify_fun = notify if notify is not None else print_notify + self.options = options if options is not None else [] self.macros = macros or [] self.options.extend(BUILD_OPTIONS) @@ -240,6 +237,11 @@ class mbedToolchain: self.mp_pool = None + def notify(self, event): + """ Little closure for notify functions + """ + return self.notify_fun(event, self.silent) + def __exit__(self): if self.mp_pool is not None: self.mp_pool.terminate() diff --git a/workspace_tools/toolchains/arm.py b/workspace_tools/toolchains/arm.py index 08ba481d8d..6975e9f4b5 100644 --- a/workspace_tools/toolchains/arm.py +++ b/workspace_tools/toolchains/arm.py @@ -30,8 +30,8 @@ class ARM(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)", line (?P\d+): (?PWarning|Error): (?P.+)') DEP_PATTERN = re.compile('\S+:\s(?P.+)\n') - def __init__(self, target, options=None, notify=None, macros=None): - mbedToolchain.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + mbedToolchain.__init__(self, target, options, notify, macros, silent) if target.core == "Cortex-M0+": cpu = "Cortex-M0" @@ -147,8 +147,8 @@ class ARM(mbedToolchain): self.default_cmd(args) class ARM_STD(ARM): - def __init__(self, target, options=None, notify=None, macros=None): - ARM.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + ARM.__init__(self, target, options, notify, macros, silent) self.cc += ["-D__ASSERT_MSG"] self.cppc += ["-D__ASSERT_MSG"] self.ld.append("--libpath=%s" % ARM_LIB) @@ -157,8 +157,8 @@ class ARM_STD(ARM): class ARM_MICRO(ARM): PATCHED_LIBRARY = False - def __init__(self, target, options=None, notify=None, macros=None): - ARM.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + ARM.__init__(self, target, options, notify, macros, silent) # Compiler self.asm += ["-D__MICROLIB"] diff --git a/workspace_tools/toolchains/gcc.py b/workspace_tools/toolchains/gcc.py index e1e3403fd5..ef94d41288 100644 --- a/workspace_tools/toolchains/gcc.py +++ b/workspace_tools/toolchains/gcc.py @@ -30,8 +30,8 @@ class GCC(mbedToolchain): CIRCULAR_DEPENDENCIES = True DIAGNOSTIC_PATTERN = re.compile('((?P\d+):)(\d+:)? (?Pwarning|error): (?P.+)') - def __init__(self, target, options=None, notify=None, macros=None, tool_path=""): - mbedToolchain.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path=""): + mbedToolchain.__init__(self, target, options, notify, macros, silent) if target.core == "Cortex-M0+": cpu = "cortex-m0" @@ -170,8 +170,8 @@ class GCC(mbedToolchain): class GCC_ARM(GCC): - def __init__(self, target, options=None, notify=None, macros=None): - GCC.__init__(self, target, options, notify, macros, GCC_ARM_PATH) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC.__init__(self, target, options, notify, macros, silent, GCC_ARM_PATH) # Use latest gcc nanolib self.ld.append("--specs=nano.specs") @@ -182,8 +182,8 @@ class GCC_ARM(GCC): class GCC_CR(GCC): - def __init__(self, target, options=None, notify=None, macros=None): - GCC.__init__(self, target, options, notify, macros, GCC_CR_PATH) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC.__init__(self, target, options, notify, macros, silent, GCC_CR_PATH) additional_compiler_flags = [ "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP", @@ -199,8 +199,8 @@ class GCC_CR(GCC): class GCC_CS(GCC): - def __init__(self, target, options=None, notify=None, macros=None): - GCC.__init__(self, target, options, notify, macros, GCC_CS_PATH) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC.__init__(self, target, options, notify, macros, silent, GCC_CS_PATH) class GCC_CW(GCC): @@ -208,13 +208,13 @@ class GCC_CW(GCC): "Cortex-M0+": "armv6-m", } - def __init__(self, target, options=None, notify=None, macros=None): - GCC.__init__(self, target, options, notify, macros, CW_GCC_PATH) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC.__init__(self, target, options, notify, macros, silent, CW_GCC_PATH) class GCC_CW_EWL(GCC_CW): - def __init__(self, target, options=None, notify=None, macros=None): - GCC_CW.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC_CW.__init__(self, target, options, notify, macros, silent) # Compiler common = [ @@ -242,5 +242,5 @@ class GCC_CW_EWL(GCC_CW): class GCC_CW_NEWLIB(GCC_CW): - def __init__(self, target, options=None, notify=None, macros=None): - GCC_CW.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + GCC_CW.__init__(self, target, options, notify, macros, silent) diff --git a/workspace_tools/toolchains/iar.py b/workspace_tools/toolchains/iar.py index 810dd000be..cfc040cc57 100644 --- a/workspace_tools/toolchains/iar.py +++ b/workspace_tools/toolchains/iar.py @@ -30,8 +30,8 @@ class IAR(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)",(?P[\d]+)\s+(?PWarning|Error)(?P.+)') - def __init__(self, target, options=None, notify=None, macros=None): - mbedToolchain.__init__(self, target, options, notify, macros) + def __init__(self, target, options=None, notify=None, macros=None, silent=False): + mbedToolchain.__init__(self, target, options, notify, macros, silent) c_flags = [ "--cpu=%s" % target.core, "--thumb",