Skip to content

Commit 392df40

Browse files
theotherjimmyCruz Monrreal II
authored andcommitted
Rework make.py Ct pLI to avoid treating apps as tests
Prior to this changeset, applications were all compiled as test #0. This can lead to unexpected behavoir. In particluar, it's weirdly impossible to use a `.mbedignore` file to ignore `mbed-os/features/unsupported/tests/mbed/env/test_env.cpp`. This PR stops treating applications like tests. [x] Fix [ ] Refactor [ ] Target update [ ] Functionality change [ ] Docs update [ ] Test update [ ] Breaking change
1 parent 808ceab commit 392df40

File tree

1 file changed

+94
-99
lines changed

1 file changed

+94
-99
lines changed

tools/make.py

Lines changed: 94 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,41 @@
5656
from utils import argparse_dir_not_parent
5757
from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
5858

59+
60+
def default_args_dict(options):
61+
return dict(
62+
linker_script=options.linker_script,
63+
clean=options.clean,
64+
macros=options.macros,
65+
jobs=options.jobs,
66+
name=options.artifact_name,
67+
app_config=options.app_config,
68+
stats_depth=options.stats_depth,
69+
ignore=options.ignore
70+
)
71+
72+
73+
def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
74+
try:
75+
bin_file, update_file = build_project(
76+
src_dir, build_dir, mcu, *args, **kwargs
77+
)
78+
if update_file:
79+
print('Update Image: %s' % update_file)
80+
print('Image: %s' % bin_file)
81+
except KeyboardInterrupt as e:
82+
print("\n[CTRL+c] exit")
83+
except NotSupportedException as e:
84+
print("\nCould not compile for %s: %s" % (mcu, str(e)))
85+
except Exception as e:
86+
if options.verbose:
87+
import traceback
88+
traceback.print_exc(file=sys.stdout)
89+
else:
90+
print("[ERROR] %s" % str(e))
91+
sys.exit(1)
92+
93+
5994
if __name__ == '__main__':
6095
# Parse Options
6196
parser = get_default_options_parser(add_app_config=True)
@@ -207,16 +242,6 @@
207242
print('\n'.join(map(str, sorted(TEST_MAP.values()))))
208243
sys.exit()
209244

210-
# force program to "0" if a source dir is specified
211-
if options.source_dir is not None:
212-
p = 0
213-
else:
214-
# Program Number or name
215-
p = options.program
216-
217-
# If 'p' was set via -n to list of numbers make this a single element integer list
218-
if type(p) != type([]):
219-
p = [p]
220245

221246
# Target
222247
if options.mcu is None :
@@ -243,102 +268,72 @@
243268
"Currently set search path: %s"
244269
%(toolchain, search_path))
245270

246-
# Test
247-
build_data_blob = {} if options.build_data else None
248-
for test_no in p:
249-
test = Test(test_no)
250-
if options.automated is not None: test.automated = options.automated
251-
if options.dependencies is not None: test.dependencies = options.dependencies
252-
if options.host_test is not None: test.host_test = options.host_test;
253-
if options.peripherals is not None: test.peripherals = options.peripherals;
254-
if options.duration is not None: test.duration = options.duration;
255-
if options.extra is not None: test.extra_files = options.extra
256-
257-
if not test.is_supported(mcu, toolchain):
258-
print('The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain))
259-
sys.exit()
260-
261-
# Linking with extra libraries
262-
if options.rpc: test.dependencies.append(RPC_LIBRARY)
263-
if options.usb: test.dependencies.append(USB_LIBRARIES)
264-
if options.dsp: test.dependencies.append(DSP_LIBRARIES)
265-
if options.testlib: test.dependencies.append(TEST_MBED_LIB)
266-
267-
build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
268-
if options.source_dir is not None:
269-
test.source_dir = options.source_dir
270-
build_dir = options.source_dir
271-
272-
if options.build_dir is not None:
273-
build_dir = options.build_dir
274-
275-
try:
276-
bin_file, update_file = build_project(
271+
if options.source_dir is not None:
272+
wrapped_build_project(
273+
options.source_dir,
274+
options.build_dir,
275+
mcu,
276+
toolchain,
277+
notify=notify,
278+
build_profile=extract_profile(parser, options, toolchain),
279+
**default_args_dict(options)
280+
)
281+
else:
282+
p = options.program
283+
284+
# If 'p' was set via -n to list of numbers make this a single element
285+
# integer list
286+
if not isinstance(p, list):
287+
p = [p]
288+
289+
build_data_blob = {} if options.build_data else None
290+
for test_no in p:
291+
test = Test(test_no)
292+
if options.automated is not None:
293+
test.automated = options.automated
294+
if options.dependencies is not None:
295+
test.dependencies = options.dependencies
296+
if options.host_test is not None:
297+
test.host_test = options.host_test
298+
if options.peripherals is not None:
299+
test.peripherals = options.peripherals
300+
if options.duration is not None:
301+
test.duration = options.duration
302+
if options.extra is not None:
303+
test.extra_files = options.extra
304+
305+
if not test.is_supported(mcu, toolchain):
306+
print(
307+
'The selected test is not supported on target '
308+
'%s with toolchain %s' % (mcu, toolchain)
309+
)
310+
sys.exit()
311+
312+
# Linking with extra libraries
313+
if options.rpc:
314+
test.dependencies.append(RPC_LIBRARY)
315+
if options.usb:
316+
test.dependencies.append(USB_LIBRARIES)
317+
if options.dsp:
318+
test.dependencies.append(DSP_LIBRARIES)
319+
if options.testlib:
320+
test.dependencies.append(TEST_MBED_LIB)
321+
322+
build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
323+
if options.build_dir is not None:
324+
build_dir = options.build_dir
325+
326+
wrapped_build_project(
277327
test.source_dir,
278328
build_dir,
279329
mcu,
280330
toolchain,
281331
set(test.dependencies),
282-
linker_script=options.linker_script,
283-
clean=options.clean,
284332
notify=notify,
285333
report=build_data_blob,
286-
macros=options.macros,
287-
jobs=options.jobs,
288-
name=options.artifact_name,
289-
app_config=options.app_config,
290334
inc_dirs=[dirname(MBED_LIBRARIES)],
291335
build_profile=extract_profile(parser, options, toolchain),
292-
stats_depth=options.stats_depth,
293-
ignore=options.ignore
336+
**default_args_dict(options)
294337
)
295-
if update_file:
296-
print('Update Image: %s' % update_file)
297-
print('Image: %s' % bin_file)
298-
299-
if options.disk:
300-
# Simple copy to the mbed disk
301-
copy(bin_file, options.disk)
302-
303-
if options.serial:
304-
# Import pyserial: https://pypi.python.org/pypi/pyserial
305-
from serial import Serial
306-
307-
sleep(TARGET_MAP[mcu].program_cycle_s)
308-
309-
serial = Serial(options.serial, timeout = 1)
310-
if options.baud:
311-
serial.setBaudrate(options.baud)
312-
313-
serial.flushInput()
314-
serial.flushOutput()
315-
316-
try:
317-
serial.sendBreak()
318-
except:
319-
# In linux a termios.error is raised in sendBreak and in setBreak.
320-
# The following setBreak() is needed to release the reset signal on the target mcu.
321-
try:
322-
serial.setBreak(False)
323-
except:
324-
pass
325-
326-
while True:
327-
c = serial.read(512)
328-
sys.stdout.write(c)
329-
sys.stdout.flush()
330-
331-
except KeyboardInterrupt as e:
332-
print("\n[CTRL+c] exit")
333-
except NotSupportedException as e:
334-
print("\nCould not compile for %s: %s" % (mcu, str(e)))
335-
except Exception as e:
336-
if options.verbose:
337-
import traceback
338-
traceback.print_exc(file=sys.stdout)
339-
else:
340-
print("[ERROR] %s" % str(e))
341-
342-
sys.exit(1)
343-
if options.build_data:
344-
merge_build_data(options.build_data, build_data_blob, "application")
338+
if options.build_data:
339+
merge_build_data(options.build_data, build_data_blob, "application")

0 commit comments

Comments
 (0)