88if "TRAVIS" in os .environ and os .environ ["TRAVIS" ] == "true" :
99 travis = True
1010
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+
1118exit_status = 0
1219success_count = 0
1320fail_count = 0
2128 'feather52832' : 'Feather nRF52832'
2229}
2330
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+
2450
2551def build_examples (variant ):
2652 global exit_status , success_count , fail_count , build_format , build_separator
@@ -33,18 +59,39 @@ def build_examples(variant):
3359 print (build_separator )
3460 subprocess .run ("arduino --board adafruit:nrf52:{}:softdevice={},debug=l0 --save-prefs" .format (variant , 's140v6' if variant != 'feather52832' else 's132v6' ), shell = True ,
3561 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 )
3666
3767 for sketch in glob .iglob ('libraries/**/*.ino' , recursive = True ):
3868 start_time = time .monotonic ()
3969
4070 if os .path .exists (os .path .dirname (sketch ) + '/.skip' ) or os .path .exists (os .path .dirname (sketch ) + '/.skip.' + variant ):
4171 success = "skipped"
4272 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+
4487 if build_result .returncode != 0 :
4588 exit_status = build_result .returncode
4689 success = "\033 [31mfailed\033 [0m "
4790 fail_count += 1
91+ elif len (warningLines ) != 0 :
92+ exit_status = - 1
93+ success = "\033 [31mwarnings\033 [0m "
94+ fail_count += 1
4895 else :
4996 success = "\033 [32msucceeded\033 [0m"
5097 success_count += 1
@@ -56,16 +103,21 @@ def build_examples(variant):
56103
57104 print ((build_format + '| {:5.2f}s |' ).format (sketch .split (os .path .sep )[1 ], os .path .basename (sketch ), success , build_duration ))
58105
59- if build_result .returncode != 0 :
60- print (build_result .stdout .decode ("utf-8" ))
106+ if success != "skipped" :
107+ if build_result .returncode != 0 :
108+ print (build_result .stdout .decode ("utf-8" ))
109+ if (build_result .stderr ):
110+ print (build_result .stderr .decode ("utf-8" ))
111+ if len (warningLines ) != 0 :
112+ for line in warningLines :
113+ print (line )
61114
62115 if travis :
63116 print ('travis_fold:end:build-{}\\ r' .format (sketch ))
64117
65118
66119build_time = time .monotonic ()
67120
68- ENV_VARIABLE_NAME = 'VARIANT'
69121
70122# build only one variant if the environment variable is specified
71123if (ENV_VARIABLE_NAME in os .environ ):
@@ -74,7 +126,7 @@ def build_examples(variant):
74126 if (variant in variants_dict ):
75127 build_examples (variant )
76128 else :
77- print ('\033 [31failed \033 [0m - invalid variant name "{}"' .format (variant ))
129+ print ('\033 [31INTERNAL ERR \033 [0m - invalid variant name "{}"' .format (variant ))
78130 fail_count += 1
79131 exit_status = - 1
80132
0 commit comments