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