62
62
CROSS = u'\N{cross mark} '
63
63
CHECK = u'\N{check mark} '
64
64
65
-
66
65
BSP_URLS = (
67
66
"https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,"
68
67
"http://arduino.esp8266.com/stable/package_esp8266com_index.json,"
71
70
"https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json"
72
71
)
73
72
73
+ # global exit code
74
+ success = 0
75
+
74
76
class ColorPrint :
75
77
76
78
@staticmethod
@@ -249,10 +251,12 @@ def download_uf2_utils():
249
251
return False
250
252
return True
251
253
252
- def generate_uf2 (example_path ):
254
+
255
+ def generate_uf2 (platform , fqbn , example_path ):
253
256
"""Generates a .uf2 file from a .bin or .hex file.
257
+ :param str platform: The platform name.
258
+ :param str fqbn: The fully qualified board name.
254
259
:param str example_path: A path to the compiled .bin or .hex file.
255
-
256
260
"""
257
261
if not download_uf2_utils ():
258
262
return None
@@ -314,12 +318,13 @@ def group_output(title):
314
318
sys .stdout .flush ()
315
319
316
320
317
- def test_examples_in_folder (folderpath ):
321
+ def test_examples_in_folder (platform , folderpath ):
318
322
global success
323
+ fqbn = ALL_PLATFORMS [platform ][0 ]
319
324
for example in sorted (os .listdir (folderpath )):
320
325
examplepath = folderpath + "/" + example
321
326
if os .path .isdir (examplepath ):
322
- test_examples_in_folder (examplepath )
327
+ test_examples_in_folder (platform , examplepath )
323
328
continue
324
329
if not examplepath .endswith (".ino" ):
325
330
continue
@@ -374,11 +379,11 @@ def test_examples_in_folder(folderpath):
374
379
with group_output (f"{ example } { fqbn } build output" ):
375
380
ColorPrint .print_fail (err .decode ("utf-8" ))
376
381
if os .path .exists (gen_file_name ):
377
- if ALL_PLATFORMS [platform ][1 ] == None :
382
+ if ALL_PLATFORMS [platform ][1 ] is None :
378
383
ColorPrint .print_info ("Platform does not support UF2 files, skipping..." )
379
384
else :
380
385
ColorPrint .print_info ("Generating UF2..." )
381
- filename = generate_uf2 (folderpath )
386
+ filename = generate_uf2 (platform , fqbn , folderpath )
382
387
if filename is None :
383
388
success = 1 # failure
384
389
if IS_LEARNING_SYS :
@@ -394,52 +399,14 @@ def test_examples_in_folder(folderpath):
394
399
ColorPrint .print_fail (err .decode ("utf-8" ))
395
400
success = 1
396
401
397
- def test_examples_in_learningrepo (folderpath ):
398
- global success
399
- for project in os .listdir (folderpath ):
400
- projectpath = folderpath + "/" + project
401
- if os .path .isdir (learningrepo ):
402
- test_examples_in_learningrepo (projectpath )
403
- continue
404
- if not projectpath .endswith (".ino" ):
405
- continue
406
- # found an INO!
407
- print ('\t ' + projectpath , end = ' ' , flush = True )
408
- # check if we should SKIP
409
- skipfilename = folderpath + "/." + platform + ".test.skip"
410
- onlyfilename = folderpath + "/." + platform + ".test.only"
411
- if os .path .exists (skipfilename ):
412
- ColorPrint .print_warn ("skipping" )
413
- continue
414
- elif glob .glob (folderpath + "/.*.test.only" ) and not os .path .exists (onlyfilename ):
415
- ColorPrint .print_warn ("skipping" )
416
- continue
417
402
418
- cmd = ['arduino-cli' , 'compile' , '--warnings' , 'all' , '--fqbn' , fqbn , projectpath ]
419
- proc = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
420
- stderr = subprocess .PIPE )
421
- r = proc .wait ()
422
- out = proc .stdout .read ()
423
- err = proc .stderr .read ()
424
- if r == 0 :
425
- ColorPrint .print_pass (CHECK )
426
- if err :
427
- # also print out warning message
428
- ColorPrint .print_fail (err .decode ("utf-8" ))
429
- else :
430
- ColorPrint .print_fail (CROSS )
431
- ColorPrint .print_fail (out .decode ("utf-8" ))
432
- ColorPrint .print_fail (err .decode ("utf-8" ))
433
- success = 1
434
-
435
-
436
- if __name__ == "__main__" :
403
+ def main ():
437
404
# Test platforms
438
405
platforms = []
439
- success = 0
440
406
441
407
# expand groups:
442
408
for arg in sys .argv [1 :]:
409
+
443
410
platform = ALL_PLATFORMS .get (arg , None )
444
411
if isinstance (platform , list ):
445
412
platforms .append (arg )
@@ -460,7 +427,11 @@ def test_examples_in_learningrepo(folderpath):
460
427
install_platform (":" .join (fqbn .split (':' , 2 )[0 :2 ]), ALL_PLATFORMS [platform ]) # take only first two elements
461
428
print ('#' * 80 )
462
429
if not IS_LEARNING_SYS :
463
- test_examples_in_folder (BUILD_DIR + "/examples" )
430
+ test_examples_in_folder (platform , BUILD_DIR + "/examples" )
464
431
else :
465
- test_examples_in_folder (BUILD_DIR )
432
+ test_examples_in_folder (platform , BUILD_DIR )
433
+
434
+
435
+ if __name__ == "__main__" :
436
+ main ()
466
437
exit (success )
0 commit comments