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 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.targets import TARGET_NAMES, TARGET_MAP
from tools.libraries import Library

View File

@ -129,49 +129,63 @@ if __name__ == '__main__':
build_report = {}
build_properties = {}
# Build sources
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool,
options=options.options,
jobs=options.jobs,
clean=options.clean,
report=build_report,
properties=build_properties,
name="mbed-os",
macros=options.macros,
archive=False)
# Build all the tests
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
options=options.options,
clean=options.clean,
report=build_report,
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)
library_build_success = True
try:
# Build sources
build_library(base_source_paths, options.build_dir, target, options.tool,
options=options.options,
jobs=options.jobs,
clean=options.clean,
report=build_report,
properties=build_properties,
name="mbed-os",
macros=options.macros,
archive=False)
except Exception, e:
library_build_success = False
print "Failed to build library"
print e
# Create the target dir for the test spec if necessary
# 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)
if library_build_success:
# Build all the tests
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
options=options.options,
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:
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 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
# 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 options.build_report_junit:
report_exporter = ReportExporter(ResultExporterType.JUNIT)
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:
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,
macros=None, silent=False, report=None, properties=None):
"""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 = {
"platform": target.name,
@ -2040,6 +2043,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
"tests": {}
}
result = True
for test_name, test_path in tests.iteritems():
test_build_path = os.path.join(build_path, 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)
except Exception, e:
result = False
continue
# 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
return test_builds
return result, test_builds
def test_spec_from_test_build(test_builds):