|
56 | 56 | from utils import argparse_dir_not_parent
|
57 | 57 | from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
|
58 | 58 |
|
| 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 | + |
59 | 94 | if __name__ == '__main__':
|
60 | 95 | # Parse Options
|
61 | 96 | parser = get_default_options_parser(add_app_config=True)
|
|
207 | 242 | print('\n'.join(map(str, sorted(TEST_MAP.values()))))
|
208 | 243 | sys.exit()
|
209 | 244 |
|
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] |
220 | 245 |
|
221 | 246 | # Target
|
222 | 247 | if options.mcu is None :
|
|
243 | 268 | "Currently set search path: %s"
|
244 | 269 | %(toolchain, search_path))
|
245 | 270 |
|
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( |
277 | 327 | test.source_dir,
|
278 | 328 | build_dir,
|
279 | 329 | mcu,
|
280 | 330 | toolchain,
|
281 | 331 | set(test.dependencies),
|
282 |
| - linker_script=options.linker_script, |
283 |
| - clean=options.clean, |
284 | 332 | notify=notify,
|
285 | 333 | report=build_data_blob,
|
286 |
| - macros=options.macros, |
287 |
| - jobs=options.jobs, |
288 |
| - name=options.artifact_name, |
289 |
| - app_config=options.app_config, |
290 | 334 | inc_dirs=[dirname(MBED_LIBRARIES)],
|
291 | 335 | build_profile=extract_profile(parser, options, toolchain),
|
292 |
| - stats_depth=options.stats_depth, |
293 |
| - ignore=options.ignore |
| 336 | + **default_args_dict(options) |
294 | 337 | )
|
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