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