Skip to content

Commit 6dbc960

Browse files
committed
Reflecting build failures in the status code of the process
1 parent 7a627b3 commit 6dbc960

File tree

3 files changed

+59
-39
lines changed

3 files changed

+59
-39
lines changed

tools/build_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from os import getcwd
2727
from time import time
2828

29-
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException
29+
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException, ToolException
3030
from tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
3131
from tools.targets import TARGET_NAMES, TARGET_MAP
3232
from tools.libraries import Library

tools/test.py

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,49 +129,63 @@
129129

130130
build_report = {}
131131
build_properties = {}
132-
133-
# Build sources
134-
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool,
135-
options=options.options,
136-
jobs=options.jobs,
137-
clean=options.clean,
138-
report=build_report,
139-
properties=build_properties,
140-
name="mbed-os",
141-
macros=options.macros,
142-
archive=False)
143-
144-
# Build all the tests
145-
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
146-
options=options.options,
147-
clean=options.clean,
148-
report=build_report,
149-
properties=build_properties,
150-
macros=options.macros,
151-
jobs=options.jobs)
152-
153-
# If a path to a test spec is provided, write it to a file
154-
if options.test_spec:
155-
test_spec_data = test_spec_from_test_build(test_build)
132+
133+
library_build_success = True
134+
try:
135+
# Build sources
136+
build_library(base_source_paths, options.build_dir, target, options.tool,
137+
options=options.options,
138+
jobs=options.jobs,
139+
clean=options.clean,
140+
report=build_report,
141+
properties=build_properties,
142+
name="mbed-os",
143+
macros=options.macros,
144+
archive=False)
145+
except Exception, e:
146+
library_build_success = False
147+
print "Failed to build library"
148+
print e
156149

157-
# Create the target dir for the test spec if necessary
158-
# mkdir will not create the dir if it already exists
159-
test_spec_dir = os.path.dirname(options.test_spec)
160-
if test_spec_dir:
161-
mkdir(test_spec_dir)
150+
if library_build_success:
151+
# Build all the tests
152+
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
153+
options=options.options,
154+
clean=options.clean,
155+
report=build_report,
156+
properties=build_properties,
157+
macros=options.macros,
158+
jobs=options.jobs)
159+
160+
if not test_build_success:
161+
print "Failed to build some tests, check build log for details"
162162

163-
try:
164-
with open(options.test_spec, 'w') as f:
165-
f.write(json.dumps(test_spec_data, indent=2))
166-
except IOError, e:
167-
print "[ERROR] Error writing test spec to file"
168-
print e
163+
# If a path to a test spec is provided, write it to a file
164+
if options.test_spec:
165+
test_spec_data = test_spec_from_test_build(test_build)
166+
167+
# Create the target dir for the test spec if necessary
168+
# mkdir will not create the dir if it already exists
169+
test_spec_dir = os.path.dirname(options.test_spec)
170+
if test_spec_dir:
171+
mkdir(test_spec_dir)
172+
173+
try:
174+
with open(options.test_spec, 'w') as f:
175+
f.write(json.dumps(test_spec_data, indent=2))
176+
except IOError, e:
177+
print "[ERROR] Error writing test spec to file"
178+
print e
169179

170180
# If a path to a JUnit build report spec is provided, write it to a file
171181
if options.build_report_junit:
172182
report_exporter = ReportExporter(ResultExporterType.JUNIT)
173183
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
174-
sys.exit()
184+
185+
if library_build_success and test_build_success:
186+
sys.exit(0)
187+
else:
188+
sys.exit(1)
175189

176190
except KeyboardInterrupt, e:
177191
print "\n[CTRL+c] exit"

tools/test_api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,10 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20292029
options=None, clean=False, notify=None, verbose=False, jobs=1,
20302030
macros=None, silent=False, report=None, properties=None):
20312031
"""Given the data structure from 'find_tests' and the typical build parameters,
2032-
build all the tests and return a test build data structure"""
2032+
build all the tests
2033+
2034+
Returns a tuple of the build result (True or False) followed by the test
2035+
build data structure"""
20332036

20342037
test_build = {
20352038
"platform": target.name,
@@ -2040,6 +2043,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20402043
"tests": {}
20412044
}
20422045

2046+
result = True
2047+
20432048
for test_name, test_path in tests.iteritems():
20442049
test_build_path = os.path.join(build_path, test_path)
20452050
src_path = base_source_paths + [test_path]
@@ -2056,6 +2061,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
20562061
verbose=verbose)
20572062

20582063
except Exception, e:
2064+
result = False
20592065
continue
20602066

20612067
# 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,
20802086
test_builds["%s-%s" % (target.name, toolchain_name)] = test_build
20812087

20822088

2083-
return test_builds
2089+
return result, test_builds
20842090

20852091

20862092
def test_spec_from_test_build(test_builds):

0 commit comments

Comments
 (0)