33import sys
44import subprocess
55import time
6+ import argparse
7+
8+ FQBN_PREFIX = 'adafruit:samd:adafruit_'
9+
10+
11+ parser = argparse .ArgumentParser (
12+ description = 'python wrapper for adafruit arduino CI workflows' ,
13+ allow_abbrev = False
14+ )
15+ parser .add_argument (
16+ '--all_warnings' , '--Wall' ,
17+ action = 'store_true' ,
18+ help = 'build with all warnings enabled (`--warnings all`)' ,
19+ )
20+ parser .add_argument (
21+ '--warnings_do_not_cause_job_failure' ,
22+ action = 'store_true' ,
23+ help = 'failed builds will be listed as failed, but not cause job to exit with an error status' ,
24+ )
25+ parser .add_argument (
26+ 'build_boards' ,
27+ metavar = 'board' ,
28+ nargs = '*' ,
29+ help = 'list of boards to be built -- Note that the fqbn is created by prepending "{}"' .format (FQBN_PREFIX ),
30+ default = [ 'metro_m0' , 'metro_m4' , 'circuitplayground_m0' ]
31+ )
32+ args = parser .parse_args ()
633
7- all_warnings = False
834exit_status = 0
935success_count = 0
1036fail_count = 0
1137skip_count = 0
12-
1338build_format = '| {:22} | {:30} | {:9} '
1439build_separator = '-' * 80
1540
16- default_boards = [ 'metro_m0' , 'metro_m4' , 'circuitplayground_m0' ]
17-
18- build_boards = []
19-
20- # build all variants if input not existed
21- if len (sys .argv ) > 1 :
22- build_boards .append (sys .argv [1 ])
23- else :
24- build_boards = default_boards
25-
26- def errorOutputFilter (line ):
41+ def errorOutputFilter (line : str ):
2742 if len (line ) == 0 :
2843 return False
2944 if line .isspace (): # Note: empty string does not match here!
3045 return False
3146 # TODO: additional items to remove?
3247 return True
3348
34-
35- def build_examples (variant ):
36- global exit_status , success_count , fail_count , skip_count , build_format , build_separator
49+ def build_examples (variant : str ):
50+ global args , exit_status , success_count , fail_count , skip_count , build_format , build_separator
3751
3852 print ('\n ' )
3953 print (build_separator )
@@ -42,7 +56,7 @@ def build_examples(variant):
4256 print ((build_format + '| {:6} |' ).format ('Library' , 'Example' , 'Result' , 'Time' ))
4357 print (build_separator )
4458
45- fqbn = "adafruit:samd:adafruit_{} " .format (variant )
59+ fqbn = "{}{} " .format (FQBN_PREFIX , variant )
4660
4761 for sketch in glob .iglob ('libraries/**/*.ino' , recursive = True ):
4862 start_time = time .monotonic ()
@@ -58,14 +72,14 @@ def build_examples(variant):
5872 # TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
5973 # preferably, would use Python logging handler to get both distinct outputs and one merged output
6074 # for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
61- if all_warnings :
75+ if args . all_warnings :
6276 build_result = subprocess .run ("arduino-cli compile --warnings all --fqbn {} {}" .format (fqbn , sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
6377 else :
6478 build_result = subprocess .run ("arduino-cli compile --warnings default --fqbn {} {}" .format (fqbn , sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
6579
6680 # get stderr into a form where len(warningLines) indicates a true warning was output to stderr
6781 warningLines = [];
68- if all_warnings and build_result .stderr :
82+ if args . all_warnings and build_result .stderr :
6983 tmpWarningLines = build_result .stderr .decode ("utf-8" ).splitlines ()
7084 warningLines = list (filter (errorOutputFilter , (tmpWarningLines )))
7185
@@ -74,7 +88,8 @@ def build_examples(variant):
7488 success = "\033 [31mfailed\033 [0m "
7589 fail_count += 1
7690 elif len (warningLines ) != 0 :
77- exit_status = - 1
91+ if not args .warnings_do_not_cause_job_failure :
92+ exit_status = - 1
7893 success = "\033 [31mwarnings\033 [0m "
7994 fail_count += 1
8095 else :
@@ -98,7 +113,7 @@ def build_examples(variant):
98113
99114build_time = time .monotonic ()
100115
101- for board in build_boards :
116+ for board in args . build_boards :
102117 build_examples (board )
103118
104119print (build_separator )
0 commit comments