@@ -298,26 +298,6 @@ def detect_inline_asm_arch(pyb, args):
298
298
return None
299
299
300
300
301
- def detect_target_wiring_script (args ):
302
- port = platform_to_port (args .platform )
303
- build = args .build
304
- tw_board_exact = None
305
- tw_board_partial = None
306
- tw_port = None
307
- for file in os .listdir ("target_wiring" ):
308
- file_base = file .removesuffix (".py" )
309
- if file_base == build :
310
- # A file matching the target's board/build name.
311
- tw_board_exact = file
312
- elif file_base .endswith ("x" ) and build .startswith (file_base .removesuffix ("x" )):
313
- # A file with a partial match to the target's board/build name.
314
- tw_board_partial = file
315
- elif file_base == port :
316
- # A file matching the target's port.
317
- tw_port = file
318
- return tw_board_exact or tw_board_partial or tw_port
319
-
320
-
321
301
def detect_test_platform (pyb , args ):
322
302
# Run a script to detect various bits of information about the target test instance.
323
303
output = run_feature_check (pyb , args , "target_info.py" )
@@ -342,16 +322,6 @@ def detect_test_platform(pyb, args):
342
322
args .float_prec = float_prec
343
323
args .unicode = unicode
344
324
345
- # Get the target_wiring script, if one exists for this target.
346
- tw = None
347
- if pyb :
348
- tw = detect_target_wiring_script (args )
349
- data = b""
350
- if tw :
351
- with open ("target_wiring/" + tw , "rb" ) as f :
352
- data = f .read ()
353
- pyb .target_wiring_script = data
354
-
355
325
# Print the detected information about the target.
356
326
print ("platform={}" .format (platform ), end = "" )
357
327
if arch :
@@ -364,11 +334,48 @@ def detect_test_platform(pyb, args):
364
334
print (" float={}-bit" .format (float_prec ), end = "" )
365
335
if unicode :
366
336
print (" unicode" , end = "" )
367
- if tw :
368
- print (" target_wiring={}" .format (tw ), end = "" )
369
337
print ()
370
338
371
339
340
+ def detect_target_wiring_script (pyb , args ):
341
+ tw_data = b""
342
+ tw_source = None
343
+ has_target_wiring = (
344
+ pyb .exec_ ("try:\n import target_wiring\n print(True)\n except:\n print(False)" ).strip ()
345
+ == b"True"
346
+ )
347
+ if has_target_wiring :
348
+ # The board already has a target_wiring module available, so use that.
349
+ tw_source = "target's filesystem"
350
+ else :
351
+ port = platform_to_port (args .platform )
352
+ build = args .build
353
+ tw_board_exact = None
354
+ tw_board_partial = None
355
+ tw_port = None
356
+ for file in os .listdir ("target_wiring" ):
357
+ file_base = file .removesuffix (".py" )
358
+ if file_base == build :
359
+ # A file matching the target's board/build name.
360
+ tw_board_exact = file
361
+ elif file_base .endswith ("x" ) and build .startswith (file_base .removesuffix ("x" )):
362
+ # A file with a partial match to the target's board/build name.
363
+ tw_board_partial = file
364
+ elif file_base == port :
365
+ # A file matching the target's port.
366
+ tw_port = file
367
+ tw = tw_board_exact or tw_board_partial or tw_port
368
+ if tw :
369
+ with open ("target_wiring/" + tw , "rb" ) as f :
370
+ tw_data = f .read ()
371
+ tw_source = f"host file { tw } "
372
+ if tw_source :
373
+ print (f"using target_wiring module from { tw_source } " )
374
+ else :
375
+ print (f"WARNING: target_wiring module not found for this target" )
376
+ pyb .target_wiring_script = tw_data
377
+
378
+
372
379
def prepare_script_for_target (args , * , script_text = None , force_plain = False ):
373
380
if force_plain or (not args .via_mpy and args .emit == "bytecode" ):
374
381
# A plain test to run as-is, no processing needed.
@@ -1430,6 +1437,10 @@ def main():
1430
1437
# tests explicitly given
1431
1438
tests = args .files
1432
1439
1440
+ # If any tests need it, prepare the target_wiring script for the target.
1441
+ if pyb and any (test .endswith (tests_requiring_target_wiring ) for test in tests ):
1442
+ detect_target_wiring_script (pyb , args )
1443
+
1433
1444
if not args .keep_path :
1434
1445
# Clear search path to make sure tests use only builtin modules, those in
1435
1446
# extmod, and a path to unittest in case it's needed.
0 commit comments