Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 9a87aea

Browse files
committed
Merge pull request #304 from autopulated/master
fix #303 - still try to run tests if the build status is nonzero
2 parents 548f4f0 + cfe1b67 commit 9a87aea

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

yotta/build.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,34 @@ def addOptions(parser, add_build_targets=True):
3838
)
3939

4040
def execCommand(args, following_args):
41+
status = installAndBuild(args, following_args)
42+
return status['status']
43+
44+
def installAndBuild(args, following_args):
45+
''' Perform the build command, but provide detailed error information.
46+
Returns {status:0, build_status:0, generate_status:0, install_status:0} on success.
47+
If status: is nonzero there was some sort of error. Other properties
48+
are optional, and may not be set if that step was not attempted.
49+
'''
50+
build_status = generate_status = install_status = 0
51+
4152
if not hasattr(args, 'build_targets'):
4253
vars(args)['build_targets'] = []
4354

4455
if 'test' in args.build_targets:
4556
logging.error('Cannot build "test". Use "yotta test" to run tests.')
46-
return 1
57+
return {'status':1}
4758

4859
cwd = os.getcwd()
4960
c = validate.currentDirectoryModule()
5061
if not c:
51-
return 1
62+
return {'status':1}
5263

5364
target, errors = c.satisfyTarget(args.target)
5465
if errors:
5566
for error in errors:
5667
logging.error(error)
57-
return 1
68+
return {'status':1}
5869

5970
# run the install command before building, we need to add some options the
6071
# install command expects to be present to do this:
@@ -77,7 +88,7 @@ def execCommand(args, following_args):
7788

7889
# install may exit non-zero for non-fatal errors (such as incompatible
7990
# version specs), which it will display
80-
errcode = install.execCommand(args, [])
91+
install_status = install.execCommand(args, [])
8192

8293
builddir = os.path.join(cwd, 'build', target.getName())
8394

@@ -95,12 +106,12 @@ def execCommand(args, following_args):
95106
missing += 1
96107
if missing:
97108
logging.error('Missing dependencies prevent build. Use `yotta ls` to list them.')
98-
return 1
109+
return {'status': 1, 'install_status':install_status, 'missing_status':missing}
99110

100111
generator = cmakegen.CMakeGen(builddir, target)
101112
for error in generator.generateRecursive(c, all_components, builddir):
102113
logging.error(error)
103-
errcode = 1
114+
generate_status = 1
104115

105116
if (not hasattr(args, 'generate_only')) or (not args.generate_only):
106117
error = target.build(
@@ -109,7 +120,14 @@ def execCommand(args, following_args):
109120
)
110121
if error:
111122
logging.error(error)
112-
errcode = 1
113-
123+
build_status = 1
124+
125+
return {
126+
'status': build_status or generate_status or install_status,
127+
'missing_status': missing,
128+
'build_status': build_status,
129+
'generate_status': generate_status,
130+
'install_status': install_status
131+
}
114132
return errcode
115133

yotta/test_subcommand.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,23 @@ def execCommand(args, following_args):
9393
if all_tests:
9494
args.tests.remove('all')
9595

96+
returncode = 0
9697
if args.build and not args.list_only:
9798
# we need to build before testing, make sure that any tests needed are
9899
# built:
99100
if all_tests:
100101
vars(args)['build_targets'] = args.tests + ['all_tests']
101102
else:
102103
vars(args)['build_targets'] = args.tests
103-
status = build.execCommand(args, following_args)
104-
if status:
105-
return status
104+
build_status = build.installAndBuild(args, following_args)
105+
# a generate or build step failure is fatal, but an install-step
106+
# failure should not prevent attempting tests:
107+
if build_status.get('generate_status', 0) != 0 or \
108+
build_status.get('build_status', 0) != 0 or \
109+
build_status.get('missing_status', 0) != 0:
110+
return 1
111+
else:
112+
returncode = build_status['status']
106113

107114
cwd = os.getcwd()
108115

@@ -132,7 +139,6 @@ def execCommand(args, following_args):
132139
# tests, in case the specific test does not belong to this module
133140
tests = findCTests(builddir, recurse_yotta_modules=(all_tests or len(args.tests)))
134141

135-
returncode = 0
136142
passed = 0
137143
failed = 0
138144
for dirname, test_exes in tests:
@@ -152,15 +158,17 @@ def execCommand(args, following_args):
152158
logging.info('test %s: %s', module.getName(), test)
153159
if args.list_only:
154160
continue
155-
returncode = target.test(
161+
test_returncode = target.test(
156162
builddir = dirname,
157163
program = test,
158164
filter_command = filter_command,
159165
forward_args = following_args
160166
)
161-
if returncode:
167+
if test_returncode:
162168
logging.error('test %s failed', test)
163169
failed += 1
170+
if not returncode:
171+
returncode = 1
164172
else:
165173
logging.info('test %s passed', test)
166174
passed += 1

0 commit comments

Comments
 (0)