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