Reflecting build failures in the status code of the process

Brian Daniels 2016-05-25 15:04:03 -05:00
parent 7a627b3fdd
commit 6dbc9601f8
3 changed files with 59 additions and 39 deletions

View File

@ -26,7 +26,7 @@ from os.path import join, exists, basename, abspath
from os import getcwd from os import getcwd
from time import time from time import time
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException, ToolException
from tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON from tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
from tools.targets import TARGET_NAMES, TARGET_MAP from tools.targets import TARGET_NAMES, TARGET_MAP
from tools.libraries import Library from tools.libraries import Library

View File

@ -129,49 +129,63 @@ if __name__ == '__main__':
build_report = {} build_report = {}
build_properties = {} build_properties = {}
# Build sources library_build_success = True
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool, try:
options=options.options, # Build sources
jobs=options.jobs, build_library(base_source_paths, options.build_dir, target, options.tool,
clean=options.clean, options=options.options,
report=build_report, jobs=options.jobs,
properties=build_properties, clean=options.clean,
name="mbed-os", report=build_report,
macros=options.macros, properties=build_properties,
archive=False) name="mbed-os",
macros=options.macros,
# Build all the tests archive=False)
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool, except Exception, e:
options=options.options, library_build_success = False
clean=options.clean, print "Failed to build library"
report=build_report, print e
properties=build_properties,
macros=options.macros,
jobs=options.jobs)
# If a path to a test spec is provided, write it to a file
if options.test_spec:
test_spec_data = test_spec_from_test_build(test_build)
# Create the target dir for the test spec if necessary if library_build_success:
# mkdir will not create the dir if it already exists # Build all the tests
test_spec_dir = os.path.dirname(options.test_spec) test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
if test_spec_dir: options=options.options,
mkdir(test_spec_dir) clean=options.clean,
report=build_report,
properties=build_properties,
macros=options.macros,
jobs=options.jobs)
if not test_build_success:
print "Failed to build some tests, check build log for details"
try: # If a path to a test spec is provided, write it to a file
with open(options.test_spec, 'w') as f: if options.test_spec:
f.write(json.dumps(test_spec_data, indent=2)) test_spec_data = test_spec_from_test_build(test_build)
except IOError, e:
print "[ERROR] Error writing test spec to file" # Create the target dir for the test spec if necessary
print e # mkdir will not create the dir if it already exists
test_spec_dir = os.path.dirname(options.test_spec)
if test_spec_dir:
mkdir(test_spec_dir)
try:
with open(options.test_spec, 'w') as f:
f.write(json.dumps(test_spec_data, indent=2))
except IOError, e:
print "[ERROR] Error writing test spec to file"
print e
# If a path to a JUnit build report spec is provided, write it to a file # If a path to a JUnit build report spec is provided, write it to a file
if options.build_report_junit: if options.build_report_junit:
report_exporter = ReportExporter(ResultExporterType.JUNIT) report_exporter = ReportExporter(ResultExporterType.JUNIT)
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties) report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
sys.exit()
if library_build_success and test_build_success:
sys.exit(0)
else:
sys.exit(1)
except KeyboardInterrupt, e: except KeyboardInterrupt, e:
print "\n[CTRL+c] exit" print "\n[CTRL+c] exit"

View File

@ -2029,7 +2029,10 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
options=None, clean=False, notify=None, verbose=False, jobs=1, options=None, clean=False, notify=None, verbose=False, jobs=1,
macros=None, silent=False, report=None, properties=None): macros=None, silent=False, report=None, properties=None):
"""Given the data structure from 'find_tests' and the typical build parameters, """Given the data structure from 'find_tests' and the typical build parameters,
build all the tests and return a test build data structure""" build all the tests
Returns a tuple of the build result (True or False) followed by the test
build data structure"""
test_build = { test_build = {
"platform": target.name, "platform": target.name,
@ -2040,6 +2043,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
"tests": {} "tests": {}
} }
result = True
for test_name, test_path in tests.iteritems(): for test_name, test_path in tests.iteritems():
test_build_path = os.path.join(build_path, test_path) test_build_path = os.path.join(build_path, test_path)
src_path = base_source_paths + [test_path] src_path = base_source_paths + [test_path]
@ -2056,6 +2061,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
verbose=verbose) verbose=verbose)
except Exception, e: except Exception, e:
result = False
continue continue
# If a clean build was carried out last time, disable it for the next build. # If a clean build was carried out last time, disable it for the next build.
@ -2080,7 +2086,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
test_builds["%s-%s" % (target.name, toolchain_name)] = test_build test_builds["%s-%s" % (target.name, toolchain_name)] = test_build
return test_builds return result, test_builds
def test_spec_from_test_build(test_builds): def test_spec_from_test_build(test_builds):