Skip to content

Commit 42f65a8

Browse files
committed
update build_all.py for parallel build
1 parent d75bb2a commit 42f65a8

File tree

2 files changed

+89
-74
lines changed

2 files changed

+89
-74
lines changed

libraries/Bluefruit52Lib/examples/Hardware/blinky/blinky.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
*/
2020

2121
#include <Arduino.h>
22-
#include <Adafruit_TinyUSB.h> // for Serial
2322

23+
#if defined(USE_TINYUSB)
24+
#include <Adafruit_TinyUSB.h> // for Serial
25+
#endif
2426

2527
// the setup function runs once when you press reset or power the board
2628
void setup() {

tools/build_all.py

Lines changed: 86 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,109 @@
44
import subprocess
55
from subprocess import Popen, PIPE
66
import time
7+
from multiprocessing import Pool
78

89
SUCCEEDED = "\033[32msucceeded\033[0m"
910
FAILED = "\033[31mfailed\033[0m"
1011
SKIPPED = "\033[35mskipped\033[0m"
1112
WARNING = "\033[33mwarnings\033[0m "
1213

13-
exit_status = 0
14-
success_count = 0
15-
fail_count = 0
16-
skip_count = 0
17-
1814
build_format = '| {:25} | {:35} | {:18} | {:6} |'
1915
build_separator = '-' * 88
2016

21-
default_boards = [ 'cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840' ]
22-
build_boards = []
23-
24-
# build all variants if input not existed
25-
if len(sys.argv) > 1:
26-
build_boards.append(sys.argv[1])
27-
else:
28-
build_boards = default_boards
29-
30-
all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True))
31-
all_examples.sort()
32-
33-
def build_examples(variant):
34-
global exit_status, success_count, fail_count, skip_count, build_format, build_separator
35-
17+
default_boards = [
18+
'cluenrf52840',
19+
'cplaynrf52840',
20+
'feather52832',
21+
'feather52840',
22+
'feather52840sense',
23+
'itsybitsy52840'
24+
]
25+
26+
# return [succeeded, failed, skipped]
27+
def build_sketch(variant, sketch):
28+
fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant,
29+
's140v6' if variant != 'feather52832' else 's132v6')
30+
ret = [0, 0, 0]
31+
32+
# skip TinyUSB library examples for nRF52832
33+
if variant == 'feather52832' and "libraries/Adafruit_TinyUSB_Arduino" in sketch:
34+
return ret
35+
36+
start_time = time.monotonic()
37+
# Skip if contains: ".board.test.skip" or ".all.test.skip"
38+
# Skip if not contains: ".board.test.only" for a specific board
39+
sketchdir = os.path.dirname(sketch)
40+
if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip') or \
41+
(glob.glob(sketchdir + "/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only')):
42+
success = SKIPPED
43+
ret[2] = 1
44+
else:
45+
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch),
46+
shell=True, stdout=PIPE, stderr=PIPE)
47+
48+
# get stderr into a form where warning/error was output to stderr
49+
if build_result.returncode != 0:
50+
success = FAILED
51+
ret[1] = 1
52+
else:
53+
ret[0] = 1
54+
if build_result.stderr:
55+
success = WARNING
56+
else:
57+
success = SUCCEEDED
58+
59+
build_duration = time.monotonic() - start_time
60+
print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success,
61+
'{:5.2f}s'.format(build_duration)))
62+
if success != SKIPPED:
63+
# Build failed
64+
if build_result.returncode != 0:
65+
print(build_result.stdout.decode("utf-8"))
66+
67+
# Build with warnings
68+
if build_result.stderr:
69+
print(build_result.stderr.decode("utf-8"))
70+
return ret
71+
72+
# return [succeeded, failed, skipped]
73+
def build_variant(variant):
3674
print('\n')
3775
print(build_separator)
3876
print('| {:^84} |'.format('Board ' + variant))
3977
print(build_separator)
4078
print(build_format.format('Library', 'Example', '\033[39mResult\033[0m', 'Time'))
4179
print(build_separator)
42-
43-
fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, 's140v6' if variant != 'feather52832' else 's132v6')
44-
45-
for sketch in all_examples:
46-
# skip TinyUSB library examples for nRF52832
47-
if variant == 'feather52832' and "libraries/Adafruit_TinyUSB_Arduino" in sketch:
48-
continue
49-
50-
start_time = time.monotonic()
51-
52-
# Skip if contains: ".board.test.skip" or ".all.test.skip"
53-
# Skip if not contains: ".board.test.only" for a specific board
54-
sketchdir = os.path.dirname(sketch)
55-
if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'):
56-
success = SKIPPED
57-
skip_count += 1
58-
elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'):
59-
success = SKIPPED
60-
skip_count += 1
61-
else:
62-
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
6380

64-
# get stderr into a form where warning/error was output to stderr
65-
if build_result.returncode != 0:
66-
exit_status = build_result.returncode
67-
success = FAILED
68-
fail_count += 1
69-
else:
70-
success_count += 1
71-
if build_result.stderr:
72-
success = WARNING
73-
else:
74-
success = SUCCEEDED
75-
76-
build_duration = time.monotonic() - start_time
77-
78-
print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration)))
79-
80-
if success != SKIPPED:
81-
# Build failed
82-
if build_result.returncode != 0:
83-
print(build_result.stdout.decode("utf-8"))
84-
85-
# Build with warnings
86-
if build_result.stderr:
87-
print(build_result.stderr.decode("utf-8"))
81+
with Pool(processes=os.cpu_count()) as pool:
82+
pool_args = list((map(lambda e, b=variant: [b, e], all_examples)))
83+
result = pool.starmap(build_sketch, pool_args)
84+
# sum all element of same index (column sum)
85+
return list(map(sum, list(zip(*result))))
86+
87+
if __name__ == '__main__':
88+
build_boards = []
8889

89-
build_time = time.monotonic()
90+
# build all variants if input not existed
91+
if len(sys.argv) > 1:
92+
build_boards.append(sys.argv[1])
93+
else:
94+
build_boards = default_boards
9095

91-
for board in build_boards:
92-
build_examples(board)
96+
all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True))
97+
all_examples.sort()
9398

94-
print(build_separator)
95-
build_time = time.monotonic() - build_time
96-
print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, build_time))
97-
print(build_separator)
99+
total_time = time.monotonic()
100+
101+
total_result = [0, 0, 0]
102+
for board in build_boards:
103+
ret = build_variant(board)
104+
total_result = list(map(lambda x, y: x + y, total_result, ret))
105+
106+
print(build_separator)
107+
total_time = time.monotonic() - total_time
108+
print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1],
109+
FAILED, total_result[2], SKIPPED, total_time))
110+
print(build_separator)
98111

99-
sys.exit(exit_status)
112+
sys.exit(total_result[1])

0 commit comments

Comments
 (0)