3
3
import sys
4
4
import subprocess
5
5
import 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 ()
6
33
7
- all_warnings = False
8
34
exit_status = 0
9
35
success_count = 0
10
36
fail_count = 0
11
37
skip_count = 0
12
-
13
38
build_format = '| {:22} | {:30} | {:9} '
14
39
build_separator = '-' * 80
15
40
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
- all_warnings = True if 'all_warnings' in sys .arv [2 :]
27
-
28
-
29
- def errorOutputFilter (line ):
41
+ def errorOutputFilter (line : str ):
30
42
if len (line ) == 0 :
31
43
return False
32
44
if line .isspace (): # Note: empty string does not match here!
33
45
return False
34
46
# TODO: additional items to remove?
35
47
return True
36
48
37
-
38
- def build_examples (variant ):
39
- 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
40
51
41
52
print ('\n ' )
42
53
print (build_separator )
@@ -45,7 +56,7 @@ def build_examples(variant):
45
56
print ((build_format + '| {:6} |' ).format ('Library' , 'Example' , 'Result' , 'Time' ))
46
57
print (build_separator )
47
58
48
- fqbn = "adafruit:samd:adafruit_{} " .format (variant )
59
+ fqbn = "{}{} " .format (FQBN_PREFIX , variant )
49
60
50
61
for sketch in glob .iglob ('libraries/**/*.ino' , recursive = True ):
51
62
start_time = time .monotonic ()
@@ -61,14 +72,14 @@ def build_examples(variant):
61
72
# TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
62
73
# preferably, would use Python logging handler to get both distinct outputs and one merged output
63
74
# for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
64
- if all_warnings :
75
+ if args . all_warnings :
65
76
build_result = subprocess .run ("arduino-cli compile --warnings all --fqbn {} {}" .format (fqbn , sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
66
77
else :
67
78
build_result = subprocess .run ("arduino-cli compile --warnings default --fqbn {} {}" .format (fqbn , sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
68
79
69
80
# get stderr into a form where len(warningLines) indicates a true warning was output to stderr
70
81
warningLines = [];
71
- if all_warnings and build_result .stderr :
82
+ if args . all_warnings and build_result .stderr :
72
83
tmpWarningLines = build_result .stderr .decode ("utf-8" ).splitlines ()
73
84
warningLines = list (filter (errorOutputFilter , (tmpWarningLines )))
74
85
@@ -77,7 +88,8 @@ def build_examples(variant):
77
88
success = "\033 [31mfailed\033 [0m "
78
89
fail_count += 1
79
90
elif len (warningLines ) != 0 :
80
- exit_status = - 1
91
+ if not args .warnings_do_not_cause_job_failure :
92
+ exit_status = - 1
81
93
success = "\033 [31mwarnings\033 [0m "
82
94
fail_count += 1
83
95
else :
@@ -101,7 +113,7 @@ def build_examples(variant):
101
113
102
114
build_time = time .monotonic ()
103
115
104
- for board in build_boards :
116
+ for board in args . build_boards :
105
117
build_examples (board )
106
118
107
119
print (build_separator )
0 commit comments