6262CROSS = u'\N{cross mark} '
6363CHECK = u'\N{check mark} '
6464
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
6776
6877class ColorPrint :
6978
@@ -156,62 +165,63 @@ def run_or_die(cmd, error):
156165 ColorPrint .print_fail (error )
157166 exit (- 1 )
158167
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 ()
169168
170169def is_library_installed (lib_name ):
171170 try :
172171 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 ' )])
174173 except subprocess .CalledProcessError as e :
175174 print ("Error checking installed libraries:" , e )
176175 return False
177176
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
201177
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 )
206183
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 ()
208187
209- # link our library folder to the arduino libraries folder
210- if not IS_LEARNING_SYS :
188+ # Install dependencies
189+ our_name = None
211190 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
215225
216226################################ UF2 Utils.
217227
@@ -242,10 +252,12 @@ def download_uf2_utils():
242252 return False
243253 return True
244254
245- def generate_uf2 (example_path ):
255+
256+ def generate_uf2 (platform , fqbn , example_path ):
246257 """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.
247260 :param str example_path: A path to the compiled .bin or .hex file.
248-
249261 """
250262 if not download_uf2_utils ():
251263 return None
@@ -292,21 +304,6 @@ def generate_uf2(example_path):
292304 return None
293305 return output_file
294306
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 )
310307
311308@contextmanager
312309def group_output (title ):
@@ -322,12 +319,13 @@ def group_output(title):
322319 sys .stdout .flush ()
323320
324321
325- def test_examples_in_folder (folderpath ):
322+ def test_examples_in_folder (platform , folderpath ):
326323 global success
324+ fqbn = ALL_PLATFORMS [platform ][0 ]
327325 for example in sorted (os .listdir (folderpath )):
328326 examplepath = folderpath + "/" + example
329327 if os .path .isdir (examplepath ):
330- test_examples_in_folder (examplepath )
328+ test_examples_in_folder (platform , examplepath )
331329 continue
332330 if not examplepath .endswith (".ino" ):
333331 continue
@@ -382,11 +380,11 @@ def test_examples_in_folder(folderpath):
382380 with group_output (f"{ example } { fqbn } build output" ):
383381 ColorPrint .print_fail (err .decode ("utf-8" ))
384382 if os .path .exists (gen_file_name ):
385- if ALL_PLATFORMS [platform ][1 ] == None :
383+ if ALL_PLATFORMS [platform ][1 ] is None :
386384 ColorPrint .print_info ("Platform does not support UF2 files, skipping..." )
387385 else :
388386 ColorPrint .print_info ("Generating UF2..." )
389- filename = generate_uf2 (folderpath )
387+ filename = generate_uf2 (platform , fqbn , folderpath )
390388 if filename is None :
391389 success = 1 # failure
392390 if IS_LEARNING_SYS :
@@ -402,53 +400,38 @@ def test_examples_in_folder(folderpath):
402400 ColorPrint .print_fail (err .decode ("utf-8" ))
403401 success = 1
404402
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
425403
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 )
437416 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 )
442433
443434
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