105
105
fskip = "\033 [33mskipped\033 [0m"
106
106
nl = "\n "
107
107
108
+ # index build configuration
109
+ idx_b_name = 0
110
+ idx_build = 1
111
+ idx_log = 2
112
+ idx_cmd = 3
113
+
108
114
109
115
def cat (file ):
110
116
with open (file , "r" ) as f :
@@ -556,17 +562,17 @@ def find_board():
556
562
557
563
558
564
# Check the status
559
- def check_status (status , build_conf , boardKo ):
565
+ def check_status (status , build_conf , boardKo , nb_build_conf ):
560
566
global nb_build_passed
561
567
global nb_build_failed
562
- sketch_name = build_conf [4 ][- 1 ].name
568
+ sketch_name = build_conf [idx_cmd ][- 1 ].name
563
569
564
570
if status [1 ] == 0 :
565
571
result = fsucc
566
572
nb_build_passed += 1
567
573
elif status [1 ] == 1 :
568
574
# Check if failed due to a region overflowed
569
- logFile = build_conf [3 ] / f"{ sketch_name } .log"
575
+ logFile = build_conf [idx_log ] / f"{ sketch_name } .log"
570
576
error_found = False
571
577
for i , line in enumerate (open (logFile )):
572
578
if error_pattern .search (line ):
@@ -579,7 +585,7 @@ def check_status(status, build_conf, boardKo):
579
585
error_found = True
580
586
if error_found :
581
587
result = ffail
582
- boardKo .append (build_conf [0 ])
588
+ boardKo .append (build_conf [idx_b_name ])
583
589
if args .ci :
584
590
cat (logFile )
585
591
nb_build_failed += 1
@@ -590,12 +596,12 @@ def check_status(status, build_conf, boardKo):
590
596
nb_build_passed += 1
591
597
else :
592
598
result = "\033 [31merror\033 [0m"
593
- boardKo .append (build_conf [0 ])
599
+ boardKo .append (build_conf [idx_b_name ])
594
600
nb_build_failed += 1
595
601
print (
596
602
f"{ build_format_result } " .format (
597
- f"{ build_conf [1 ]} /{ build_conf [ 2 ] } " ,
598
- build_conf [0 ],
603
+ f"{ build_conf [idx_build ]} /{ nb_build_conf } " ,
604
+ build_conf [idx_b_name ],
599
605
result ,
600
606
status [0 ],
601
607
)
@@ -701,47 +707,46 @@ def genBasicCommand(b_name):
701
707
702
708
def create_build_conf_list ():
703
709
build_conf_list = []
704
- idx = 1
705
- for b_name in board_fqbn :
710
+ for idx , b_name in enumerate (board_fqbn , start = 1 ):
706
711
build_conf_list .append (
707
- (
712
+ [
708
713
b_name ,
709
714
idx ,
710
- len (board_fqbn ),
711
715
output_dir / b_name ,
712
716
genBasicCommand (b_name ),
713
- )
717
+ ]
714
718
)
715
- idx += 1
716
719
return build_conf_list
717
720
718
721
719
722
def build_config (sketch , boardSkipped ):
720
723
global nb_build_skipped
721
- build_conf_list = create_build_conf_list ()
722
-
723
- for idx in reversed (range (len (build_conf_list ))):
724
- build_conf_list [idx ][4 ][- 1 ] = sketch
725
- if na_sketch_pattern :
726
- if build_conf_list [idx ][0 ] in na_sketch_pattern :
727
- for pattern in na_sketch_pattern [build_conf_list [idx ][0 ]]:
728
- if re .search (pattern , str (sketch ), re .IGNORECASE ):
729
- boardSkipped .append (build_conf_list [idx ][0 ])
730
- del build_conf_list [idx ]
731
- nb_build_skipped += 1
732
- break
733
- else :
734
- # get specific sketch options to append to the fqbn
735
- for pattern in sketch_options :
736
- if re .search (pattern , str (sketch ), re .IGNORECASE ):
737
- if build_conf_list [idx ][4 ][- 2 ].count (":" ) == 3 :
738
- build_conf_list [idx ][4 ][- 2 ] += (
739
- "," + sketch_options [pattern ]
740
- )
741
- else :
742
- build_conf_list [idx ][4 ][- 2 ] += (
743
- ":" + sketch_options [pattern ]
744
- )
724
+ build_conf_list = []
725
+ build_conf_list_tmp = create_build_conf_list ()
726
+
727
+ while len (build_conf_list_tmp ):
728
+ build_conf = build_conf_list_tmp .pop (0 )
729
+ build_conf [idx_cmd ][- 1 ] = sketch
730
+ b_name = build_conf [idx_b_name ]
731
+ s_sketch = str (sketch )
732
+ build_conf [idx_build ] = len (build_conf_list ) + 1
733
+ if b_name in na_sketch_pattern :
734
+ for pattern in na_sketch_pattern [b_name ]:
735
+ if re .search (pattern , s_sketch , re .IGNORECASE ):
736
+ boardSkipped .append (b_name )
737
+ nb_build_skipped += 1
738
+ break
739
+ else :
740
+ # Get specific sketch options to append to the fqbn
741
+ for pattern in sketch_options :
742
+ if re .search (pattern , s_sketch , re .IGNORECASE ):
743
+ if build_conf [idx_cmd ][- 2 ].count (":" ) == 3 :
744
+ build_conf [idx_cmd ][- 2 ] += f",{ sketch_options [pattern ]} "
745
+ else :
746
+ build_conf [idx_cmd ][- 2 ] += f":{ sketch_options [pattern ]} "
747
+ build_conf_list .append (build_conf )
748
+ else :
749
+ build_conf_list .append (build_conf )
745
750
return build_conf_list
746
751
747
752
@@ -772,11 +777,12 @@ def build_all():
772
777
print (build_separator )
773
778
774
779
build_conf_list = build_config (sketch , boardSkipped )
780
+ nb_build_conf = len (build_conf_list )
775
781
with concurrent .futures .ProcessPoolExecutor (os .cpu_count () - 1 ) as executor :
776
782
for build_conf , res in zip (
777
783
build_conf_list , executor .map (build , build_conf_list )
778
784
):
779
- check_status (res , build_conf , boardKo )
785
+ check_status (res , build_conf , boardKo , nb_build_conf )
780
786
log_sketch_build_result (sketch , boardKo , boardSkipped )
781
787
# Ensure no cache issue
782
788
deleteFolder (build_output_cache_dir )
@@ -785,9 +791,9 @@ def build_all():
785
791
786
792
# Run arduino-cli command
787
793
def real_build (build_conf ):
788
- cmd = build_conf [4 ]
794
+ cmd = build_conf [idx_cmd ]
789
795
status = [time .monotonic ()]
790
- with open (build_conf [3 ] / f"{ cmd [- 1 ].name } .log" , "w" ) as stdout :
796
+ with open (build_conf [idx_log ] / f"{ cmd [- 1 ].name } .log" , "w" ) as stdout :
791
797
res = subprocess .Popen (cmd , stdout = stdout , stderr = subprocess .STDOUT )
792
798
res .wait ()
793
799
status [0 ] = time .monotonic () - status [0 ]
@@ -801,7 +807,7 @@ def dry_build(build_conf):
801
807
status = [random .random () * 10 , random .randint (0 , 1 )]
802
808
if status [1 ] == 1 :
803
809
# Create dummy log file
804
- logFile = build_conf [3 ] / f"{ build_conf [4 ][- 1 ].name } .log"
810
+ logFile = build_conf [idx_log ] / f"{ build_conf [idx_cmd ][- 1 ].name } .log"
805
811
# random failed
806
812
dummy = open (logFile , "w" )
807
813
if random .randint (0 , 1 ) == 1 :
0 commit comments