|
1 | 1 | import os |
2 | | -import glob |
3 | 2 | import sys |
4 | | -import subprocess |
5 | 3 | import time |
| 4 | +import subprocess |
| 5 | +from multiprocessing import Pool |
6 | 6 |
|
7 | 7 | import build_utils |
8 | 8 |
|
9 | 9 | SUCCEEDED = "\033[32msucceeded\033[0m" |
10 | 10 | FAILED = "\033[31mfailed\033[0m" |
11 | 11 | SKIPPED = "\033[33mskipped\033[0m" |
12 | 12 |
|
13 | | -success_count = 0 |
14 | | -fail_count = 0 |
15 | | -skip_count = 0 |
16 | | -exit_status = 0 |
17 | | - |
18 | | -total_time = time.monotonic() |
19 | | - |
20 | | -build_format = '| {:29} | {:30} | {:18} | {:7} | {:6} | {:6} |' |
21 | 13 | build_separator = '-' * 106 |
22 | 14 |
|
| 15 | + |
23 | 16 | def filter_with_input(mylist): |
24 | 17 | if len(sys.argv) > 1: |
25 | 18 | input_args = list(set(mylist).intersection(sys.argv)) |
26 | 19 | if len(input_args) > 0: |
27 | 20 | mylist[:] = input_args |
28 | 21 |
|
29 | | -# If examples are not specified in arguments, build all |
30 | | -all_examples = [] |
31 | | -for dir1 in os.scandir("examples"): |
32 | | - if dir1.is_dir(): |
33 | | - for entry in os.scandir(dir1.path): |
34 | | - if entry.is_dir(): |
35 | | - all_examples.append(dir1.name + '/' + entry.name) |
36 | | -filter_with_input(all_examples) |
37 | | -all_examples.sort() |
38 | | - |
39 | | -# If boards are not specified in arguments, build all |
40 | | -all_boards = [] |
41 | | -for entry in os.scandir("hw/bsp"): |
42 | | - if entry.is_dir() and os.path.exists(entry.path + "/board.mk"): |
43 | | - all_boards.append(entry.name) |
44 | | -filter_with_input(all_boards) |
45 | | -all_boards.sort() |
46 | | - |
47 | | -def build_board(example, board): |
48 | | - global success_count, fail_count, skip_count, exit_status |
49 | | - start_time = time.monotonic() |
50 | | - flash_size = "-" |
51 | | - sram_size = "-" |
52 | | - |
53 | | - # Check if board is skipped |
54 | | - if build_utils.skip_example(example, board): |
55 | | - success = SKIPPED |
56 | | - skip_count += 1 |
57 | | - print(build_format.format(example, board, success, '-', flash_size, sram_size)) |
58 | | - else: |
59 | | - subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
60 | | - build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
61 | 22 |
|
62 | | - if build_result.returncode == 0: |
63 | | - success = SUCCEEDED |
64 | | - success_count += 1 |
65 | | - (flash_size, sram_size) = build_size(example, board) |
66 | | - else: |
67 | | - exit_status = build_result.returncode |
68 | | - success = FAILED |
69 | | - fail_count += 1 |
| 23 | +if __name__ == '__main__': |
| 24 | + # If examples are not specified in arguments, build all |
| 25 | + all_examples = [] |
| 26 | + for dir1 in os.scandir("examples"): |
| 27 | + if dir1.is_dir(): |
| 28 | + for entry in os.scandir(dir1.path): |
| 29 | + if entry.is_dir(): |
| 30 | + all_examples.append(dir1.name + '/' + entry.name) |
| 31 | + filter_with_input(all_examples) |
| 32 | + all_examples.sort() |
| 33 | + |
| 34 | + # If boards are not specified in arguments, build all |
| 35 | + all_boards = [] |
| 36 | + for entry in os.scandir("hw/bsp"): |
| 37 | + if entry.is_dir() and os.path.exists(entry.path + "/board.mk"): |
| 38 | + all_boards.append(entry.name) |
| 39 | + filter_with_input(all_boards) |
| 40 | + all_boards.sort() |
| 41 | + |
| 42 | + # Get dependencies |
| 43 | + for b in all_boards: |
| 44 | + subprocess.run("make -C examples/device/board_test BOARD={} get-deps".format(b), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
70 | 45 |
|
71 | | - build_duration = time.monotonic() - start_time |
72 | | - print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) |
73 | | - |
74 | | - if build_result.returncode != 0: |
75 | | - print(build_result.stdout.decode("utf-8")) |
76 | | - |
77 | | -def build_size(example, board): |
78 | | - #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) |
79 | | - elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board) |
80 | | - size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") |
81 | | - size_list = size_output.split('\n')[1].split('\t') |
82 | | - flash_size = int(size_list[0]) |
83 | | - sram_size = int(size_list[1]) + int(size_list[2]) |
84 | | - return (flash_size, sram_size) |
85 | | - |
86 | | -print(build_separator) |
87 | | -print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) |
88 | | - |
89 | | -for example in all_examples: |
90 | 46 | print(build_separator) |
91 | | - for board in all_boards: |
92 | | - build_board(example, board) |
93 | | - |
94 | | -total_time = time.monotonic() - total_time |
95 | | -print(build_separator) |
96 | | -print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) |
97 | | -print(build_separator) |
| 47 | + print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) |
| 48 | + total_time = time.monotonic() |
| 49 | + |
| 50 | + # succeeded, failed, skipped |
| 51 | + total_result = [0, 0, 0] |
| 52 | + for example in all_examples: |
| 53 | + print(build_separator) |
| 54 | + with Pool(processes=os.cpu_count()) as pool: |
| 55 | + pool_args = list((map(lambda b, e=example: [e, b], all_boards))) |
| 56 | + result = pool.starmap(build_utils.build_example, pool_args) |
| 57 | + # sum all element of same index (column sum) |
| 58 | + result = list(map(sum, list(zip(*result)))) |
| 59 | + |
| 60 | + # add to total result |
| 61 | + total_result = list(map(lambda x, y: x + y, total_result, result)) |
| 62 | + |
| 63 | + total_time = time.monotonic() - total_time |
| 64 | + print(build_separator) |
| 65 | + print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1], |
| 66 | + FAILED, total_result[2], SKIPPED, total_time)) |
| 67 | + print(build_separator) |
98 | 68 |
|
99 | | -sys.exit(exit_status) |
| 69 | + sys.exit(total_result[1]) |
0 commit comments