62
62
CROSS = u'\N{cross mark} '
63
63
CHECK = u'\N{check mark} '
64
64
65
-
66
- BSP_URLS = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json,https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json,https://drazzy.good-enough.cloud/package_drazzy.com_index.json"
65
+ BSP_URLS = (
66
+ "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,"
67
+ "http://arduino.esp8266.com/stable/package_esp8266com_index.json,"
68
+ "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json,"
69
+ "https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json,"
70
+ "https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json,"
71
+ "https://drazzy.good-enough.cloud/package_drazzy.com_index.json"
72
+ )
73
+
74
+ # global exit code
75
+ success = 0
67
76
68
77
class ColorPrint :
69
78
@@ -156,62 +165,63 @@ def run_or_die(cmd, error):
156
165
ColorPrint .print_fail (error )
157
166
exit (- 1 )
158
167
159
- ################################ Install Arduino IDE
160
- print ()
161
- ColorPrint .print_info ('#' * 40 )
162
- print ("INSTALLING ARDUINO BOARDS" )
163
- ColorPrint .print_info ('#' * 40 )
164
-
165
- run_or_die ("arduino-cli core update-index --additional-urls " + BSP_URLS +
166
- " > /dev/null" , "FAILED to update core indices" )
167
-
168
- print ()
169
168
170
169
def is_library_installed (lib_name ):
171
170
try :
172
171
installed_libs = subprocess .check_output (["arduino-cli" , "lib" , "list" ]).decode ("utf-8" )
173
- return not all (not item for item in [re .match ('^' + dep + '\\ s*\\ d+\\ .' , line ) for line in installed_libs .split ('\n ' )])
172
+ return not all (not item for item in [re .match ('^' + lib_name + '\\ s*\\ d+\\ .' , line ) for line in installed_libs .split ('\n ' )])
174
173
except subprocess .CalledProcessError as e :
175
174
print ("Error checking installed libraries:" , e )
176
175
return False
177
176
178
- ################################ Install dependencies
179
- our_name = None
180
- try :
181
- if IS_LEARNING_SYS :
182
- libprop = open (BUILD_DIR + '/library.deps' )
183
- else :
184
- libprop = open (BUILD_DIR + '/library.properties' )
185
- for line in libprop :
186
- if line .startswith ("name=" ):
187
- our_name = line .replace ("name=" , "" ).strip ()
188
- if line .startswith ("depends=" ):
189
- deps = line .replace ("depends=" , "" ).split ("," )
190
- for dep in deps :
191
- dep = dep .strip ()
192
- if not is_library_installed (dep ):
193
- print ("Installing " + dep )
194
- run_or_die ('arduino-cli lib install "' + dep + '" > /dev/null' ,
195
- "FAILED to install dependency " + dep )
196
- else :
197
- print ("Skipping already installed lib: " + dep )
198
- except OSError :
199
- print ("No library dep or properties found!" )
200
- pass # no library properties
201
177
202
- # Delete the existing library if we somehow downloaded
203
- # due to dependencies
204
- if our_name :
205
- run_or_die ("arduino-cli lib uninstall \" " + our_name + "\" " , "Could not uninstall" )
178
+ def install_library_deps ():
179
+ print ()
180
+ ColorPrint .print_info ('#' * 40 )
181
+ print ("INSTALLING ARDUINO LIBRARIES" )
182
+ ColorPrint .print_info ('#' * 40 )
206
183
207
- print ("Libraries installed: " , glob .glob (os .environ ['HOME' ]+ '/Arduino/libraries/*' ))
184
+ run_or_die ("arduino-cli core update-index --additional-urls " + BSP_URLS +
185
+ " > /dev/null" , "FAILED to update core indices" )
186
+ print ()
208
187
209
- # link our library folder to the arduino libraries folder
210
- if not IS_LEARNING_SYS :
188
+ # Install dependencies
189
+ our_name = None
211
190
try :
212
- os .symlink (BUILD_DIR , os .environ ['HOME' ]+ '/Arduino/libraries/' + os .path .basename (BUILD_DIR ))
213
- except FileExistsError :
214
- pass
191
+ if IS_LEARNING_SYS :
192
+ libprop = open (BUILD_DIR + '/library.deps' )
193
+ else :
194
+ libprop = open (BUILD_DIR + '/library.properties' )
195
+ for line in libprop :
196
+ if line .startswith ("name=" ):
197
+ our_name = line .replace ("name=" , "" ).strip ()
198
+ if line .startswith ("depends=" ):
199
+ deps = line .replace ("depends=" , "" ).split ("," )
200
+ for dep in deps :
201
+ dep = dep .strip ()
202
+ if not is_library_installed (dep ):
203
+ print ("Installing " + dep )
204
+ run_or_die ('arduino-cli lib install "' + dep + '" > /dev/null' ,
205
+ "FAILED to install dependency " + dep )
206
+ else :
207
+ print ("Skipping already installed lib: " + dep )
208
+ except OSError :
209
+ print ("No library dep or properties found!" )
210
+ pass # no library properties
211
+
212
+ # Delete the existing library if we somehow downloaded
213
+ # due to dependencies
214
+ if our_name :
215
+ run_or_die ("arduino-cli lib uninstall \" " + our_name + "\" " , "Could not uninstall" )
216
+
217
+ print ("Libraries installed: " , glob .glob (os .environ ['HOME' ]+ '/Arduino/libraries/*' ))
218
+
219
+ # link our library folder to the arduino libraries folder
220
+ if not IS_LEARNING_SYS :
221
+ try :
222
+ os .symlink (BUILD_DIR , os .environ ['HOME' ]+ '/Arduino/libraries/' + os .path .basename (BUILD_DIR ))
223
+ except FileExistsError :
224
+ pass
215
225
216
226
################################ UF2 Utils.
217
227
@@ -242,10 +252,12 @@ def download_uf2_utils():
242
252
return False
243
253
return True
244
254
245
- def generate_uf2 (example_path ):
255
+
256
+ def generate_uf2 (platform , fqbn , example_path ):
246
257
"""Generates a .uf2 file from a .bin or .hex file.
258
+ :param str platform: The platform name.
259
+ :param str fqbn: The fully qualified board name.
247
260
:param str example_path: A path to the compiled .bin or .hex file.
248
-
249
261
"""
250
262
if not download_uf2_utils ():
251
263
return None
@@ -292,21 +304,6 @@ def generate_uf2(example_path):
292
304
return None
293
305
return output_file
294
306
295
- ################################ Test platforms
296
- platforms = []
297
- success = 0
298
-
299
- # expand groups:
300
- for arg in sys .argv [1 :]:
301
- platform = ALL_PLATFORMS .get (arg , None )
302
- if isinstance (platform , list ):
303
- platforms .append (arg )
304
- elif isinstance (platform , tuple ):
305
- for p in platform :
306
- platforms .append (p )
307
- else :
308
- print ("Unknown platform: " , arg )
309
- exit (- 1 )
310
307
311
308
@contextmanager
312
309
def group_output (title ):
@@ -322,12 +319,13 @@ def group_output(title):
322
319
sys .stdout .flush ()
323
320
324
321
325
- def test_examples_in_folder (folderpath ):
322
+ def test_examples_in_folder (platform , folderpath ):
326
323
global success
324
+ fqbn = ALL_PLATFORMS [platform ][0 ]
327
325
for example in sorted (os .listdir (folderpath )):
328
326
examplepath = folderpath + "/" + example
329
327
if os .path .isdir (examplepath ):
330
- test_examples_in_folder (examplepath )
328
+ test_examples_in_folder (platform , examplepath )
331
329
continue
332
330
if not examplepath .endswith (".ino" ):
333
331
continue
@@ -382,11 +380,11 @@ def test_examples_in_folder(folderpath):
382
380
with group_output (f"{ example } { fqbn } build output" ):
383
381
ColorPrint .print_fail (err .decode ("utf-8" ))
384
382
if os .path .exists (gen_file_name ):
385
- if ALL_PLATFORMS [platform ][1 ] == None :
383
+ if ALL_PLATFORMS [platform ][1 ] is None :
386
384
ColorPrint .print_info ("Platform does not support UF2 files, skipping..." )
387
385
else :
388
386
ColorPrint .print_info ("Generating UF2..." )
389
- filename = generate_uf2 (folderpath )
387
+ filename = generate_uf2 (platform , fqbn , folderpath )
390
388
if filename is None :
391
389
success = 1 # failure
392
390
if IS_LEARNING_SYS :
@@ -402,53 +400,38 @@ def test_examples_in_folder(folderpath):
402
400
ColorPrint .print_fail (err .decode ("utf-8" ))
403
401
success = 1
404
402
405
- def test_examples_in_learningrepo (folderpath ):
406
- global success
407
- for project in os .listdir (folderpath ):
408
- projectpath = folderpath + "/" + project
409
- if os .path .isdir (learningrepo ):
410
- test_examples_in_learningrepo (projectpath )
411
- continue
412
- if not projectpath .endswith (".ino" ):
413
- continue
414
- # found an INO!
415
- print ('\t ' + projectpath , end = ' ' , flush = True )
416
- # check if we should SKIP
417
- skipfilename = folderpath + "/." + platform + ".test.skip"
418
- onlyfilename = folderpath + "/." + platform + ".test.only"
419
- if os .path .exists (skipfilename ):
420
- ColorPrint .print_warn ("skipping" )
421
- continue
422
- elif glob .glob (folderpath + "/.*.test.only" ) and not os .path .exists (onlyfilename ):
423
- ColorPrint .print_warn ("skipping" )
424
- continue
425
403
426
- cmd = ['arduino-cli' , 'compile' , '--warnings' , 'all' , '--fqbn' , fqbn , projectpath ]
427
- proc = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
428
- stderr = subprocess .PIPE )
429
- r = proc .wait ()
430
- out = proc .stdout .read ()
431
- err = proc .stderr .read ()
432
- if r == 0 :
433
- ColorPrint .print_pass (CHECK )
434
- if err :
435
- # also print out warning message
436
- ColorPrint .print_fail (err .decode ("utf-8" ))
404
+ def main ():
405
+ # Test platforms
406
+ platforms = []
407
+
408
+ # expand groups:
409
+ for arg in sys .argv [1 :]:
410
+ platform = ALL_PLATFORMS .get (arg , None )
411
+ if isinstance (platform , list ):
412
+ platforms .append (arg )
413
+ elif isinstance (platform , tuple ):
414
+ for p in platform :
415
+ platforms .append (p )
437
416
else :
438
- ColorPrint .print_fail (CROSS )
439
- ColorPrint .print_fail (out .decode ("utf-8" ))
440
- ColorPrint .print_fail (err .decode ("utf-8" ))
441
- success = 1
417
+ print ("Unknown platform: " , arg )
418
+ exit (- 1 )
419
+
420
+ # Install libraries deps
421
+ install_library_deps ()
422
+
423
+ for platform in platforms :
424
+ fqbn = ALL_PLATFORMS [platform ][0 ]
425
+ print ('#' * 80 )
426
+ ColorPrint .print_info ("SWITCHING TO " + fqbn )
427
+ install_platform (":" .join (fqbn .split (':' , 2 )[0 :2 ]), ALL_PLATFORMS [platform ]) # take only first two elements
428
+ print ('#' * 80 )
429
+ if not IS_LEARNING_SYS :
430
+ test_examples_in_folder (platform , BUILD_DIR + "/examples" )
431
+ else :
432
+ test_examples_in_folder (platform , BUILD_DIR )
442
433
443
434
444
- for platform in platforms :
445
- fqbn = ALL_PLATFORMS [platform ][0 ]
446
- print ('#' * 80 )
447
- ColorPrint .print_info ("SWITCHING TO " + fqbn )
448
- install_platform (":" .join (fqbn .split (':' , 2 )[0 :2 ]), ALL_PLATFORMS [platform ]) # take only first two elements
449
- print ('#' * 80 )
450
- if not IS_LEARNING_SYS :
451
- test_examples_in_folder (BUILD_DIR + "/examples" )
452
- else :
453
- test_examples_in_folder (BUILD_DIR )
454
- exit (success )
435
+ if __name__ == "__main__" :
436
+ main ()
437
+ exit (success )
0 commit comments