8
8
if "TRAVIS" in os .environ and os .environ ["TRAVIS" ] == "true" :
9
9
travis = True
10
10
11
+ all_warnings = False
12
+ if "ALL_WARNINGS" in os .environ and os .environ ["ALL_WARNINGS" ] == "true" :
13
+ all_warnings = True
14
+
15
+ ENV_VARIABLE_NAME = 'VARIANT'
16
+
17
+
11
18
exit_status = 0
12
19
success_count = 0
13
20
fail_count = 0
21
28
'feather52832' : 'Feather nRF52832'
22
29
}
23
30
31
+ # STDERR receives output that starts with the following text, none of which should be considered a warning or error...
32
+ output_to_ignore = (
33
+ 'Picked up JAVA_TOOL_OPTIONS:' ,
34
+ 'Loading configuration...' ,
35
+ 'Initializing packages...' ,
36
+ 'Preparing boards...' ,
37
+ 'Verifying...' ,
38
+ )
39
+
40
+ def errorOutputFilter (line ):
41
+ if len (line ) == 0 :
42
+ return False
43
+ if line .isspace (): # Note: empty string does not match here!
44
+ return False
45
+ if line .startswith (output_to_ignore ): # alternatively, can trim() each line, but that would create lots of short-lived strings...
46
+ return False
47
+ # TODO: additional items to remove?
48
+ return True
49
+
24
50
25
51
def build_examples (variant ):
26
52
global exit_status , success_count , fail_count , build_format , build_separator
@@ -33,18 +59,39 @@ def build_examples(variant):
33
59
print (build_separator )
34
60
subprocess .run ("arduino --board adafruit:nrf52:{}:softdevice={},debug=l0 --save-prefs" .format (variant , 's140v6' if variant != 'feather52832' else 's132v6' ), shell = True ,
35
61
stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
62
+
63
+ if all_warnings :
64
+ subprocess .run ("arduino --pref 'compiler.warning_level=all' --save-prefs" , shell = True ,
65
+ stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
36
66
37
67
for sketch in glob .iglob ('libraries/**/*.ino' , recursive = True ):
38
68
start_time = time .monotonic ()
39
69
40
70
if os .path .exists (os .path .dirname (sketch ) + '/.skip' ) or os .path .exists (os .path .dirname (sketch ) + '/.skip.' + variant ):
41
71
success = "skipped"
42
72
else :
43
- build_result = subprocess .run ("arduino --verify {}" .format (sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
73
+ # TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
74
+ # preferably, would use Python logging handler to get both distinct outputs and one merged output
75
+ # for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
76
+ if all_warnings :
77
+ build_result = subprocess .run ("arduino --verify {}" .format (sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
78
+ else :
79
+ build_result = subprocess .run ("arduino --verify {}" .format (sketch ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
80
+
81
+ # get stderr into a form where len(warningLines) indicates a true warning was output to stderr
82
+ warningLines = [];
83
+ if all_warnings and build_result .stderr :
84
+ tmpWarningLines = build_result .stderr .decode ("utf-8" ).splitlines ()
85
+ warningLines = list (filter (errorOutputFilter , (tmpWarningLines )))
86
+
44
87
if build_result .returncode != 0 :
45
88
exit_status = build_result .returncode
46
89
success = "\033 [31mfailed\033 [0m "
47
90
fail_count += 1
91
+ elif len (warningLines ) != 0 :
92
+ exit_status = - 1
93
+ success = "\033 [31mwarnings\033 [0m "
94
+ fail_count += 1
48
95
else :
49
96
success = "\033 [32msucceeded\033 [0m"
50
97
success_count += 1
@@ -58,14 +105,19 @@ def build_examples(variant):
58
105
59
106
if build_result .returncode != 0 :
60
107
print (build_result .stdout .decode ("utf-8" ))
108
+ if (build_result .stderr ):
109
+ print (build_result .stderr .decode ("utf-8" ))
110
+
111
+ if len (warningLines ) != 0 :
112
+ for line in warningLines :
113
+ print (line )
61
114
62
115
if travis :
63
116
print ('travis_fold:end:build-{}\\ r' .format (sketch ))
64
117
65
118
66
119
build_time = time .monotonic ()
67
120
68
- ENV_VARIABLE_NAME = 'VARIANT'
69
121
70
122
# build only one variant if the environment variable is specified
71
123
if (ENV_VARIABLE_NAME in os .environ ):
@@ -74,7 +126,7 @@ def build_examples(variant):
74
126
if (variant in variants_dict ):
75
127
build_examples (variant )
76
128
else :
77
- print ('\033 [31failed \033 [0m - invalid variant name "{}"' .format (variant ))
129
+ print ('\033 [31INTERNAL ERR \033 [0m - invalid variant name "{}"' .format (variant ))
78
130
fail_count += 1
79
131
exit_status = - 1
80
132
0 commit comments