105105fskip = "\033 [33mskipped\033 [0m"
106106nl = "\n "
107107
108+ # index build configuration
109+ idx_b_name = 0
110+ idx_build = 1
111+ idx_log = 2
112+ idx_cmd = 3
113+
108114
109115def cat (file ):
110116 with open (file , "r" ) as f :
@@ -556,17 +562,17 @@ def find_board():
556562
557563
558564# Check the status
559- def check_status (status , build_conf , boardKo ):
565+ def check_status (status , build_conf , boardKo , nb_build_conf ):
560566 global nb_build_passed
561567 global nb_build_failed
562- sketch_name = build_conf [4 ][- 1 ].name
568+ sketch_name = build_conf [idx_cmd ][- 1 ].name
563569
564570 if status [1 ] == 0 :
565571 result = fsucc
566572 nb_build_passed += 1
567573 elif status [1 ] == 1 :
568574 # 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"
570576 error_found = False
571577 for i , line in enumerate (open (logFile )):
572578 if error_pattern .search (line ):
@@ -579,7 +585,7 @@ def check_status(status, build_conf, boardKo):
579585 error_found = True
580586 if error_found :
581587 result = ffail
582- boardKo .append (build_conf [0 ])
588+ boardKo .append (build_conf [idx_b_name ])
583589 if args .ci :
584590 cat (logFile )
585591 nb_build_failed += 1
@@ -590,12 +596,12 @@ def check_status(status, build_conf, boardKo):
590596 nb_build_passed += 1
591597 else :
592598 result = "\033 [31merror\033 [0m"
593- boardKo .append (build_conf [0 ])
599+ boardKo .append (build_conf [idx_b_name ])
594600 nb_build_failed += 1
595601 print (
596602 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 ],
599605 result ,
600606 status [0 ],
601607 )
@@ -701,47 +707,46 @@ def genBasicCommand(b_name):
701707
702708def create_build_conf_list ():
703709 build_conf_list = []
704- idx = 1
705- for b_name in board_fqbn :
710+ for idx , b_name in enumerate (board_fqbn , start = 1 ):
706711 build_conf_list .append (
707- (
712+ [
708713 b_name ,
709714 idx ,
710- len (board_fqbn ),
711715 output_dir / b_name ,
712716 genBasicCommand (b_name ),
713- )
717+ ]
714718 )
715- idx += 1
716719 return build_conf_list
717720
718721
719722def build_config (sketch , boardSkipped ):
720723 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 )
745750 return build_conf_list
746751
747752
@@ -772,11 +777,12 @@ def build_all():
772777 print (build_separator )
773778
774779 build_conf_list = build_config (sketch , boardSkipped )
780+ nb_build_conf = len (build_conf_list )
775781 with concurrent .futures .ProcessPoolExecutor (os .cpu_count () - 1 ) as executor :
776782 for build_conf , res in zip (
777783 build_conf_list , executor .map (build , build_conf_list )
778784 ):
779- check_status (res , build_conf , boardKo )
785+ check_status (res , build_conf , boardKo , nb_build_conf )
780786 log_sketch_build_result (sketch , boardKo , boardSkipped )
781787 # Ensure no cache issue
782788 deleteFolder (build_output_cache_dir )
@@ -785,9 +791,9 @@ def build_all():
785791
786792# Run arduino-cli command
787793def real_build (build_conf ):
788- cmd = build_conf [4 ]
794+ cmd = build_conf [idx_cmd ]
789795 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 :
791797 res = subprocess .Popen (cmd , stdout = stdout , stderr = subprocess .STDOUT )
792798 res .wait ()
793799 status [0 ] = time .monotonic () - status [0 ]
@@ -801,7 +807,7 @@ def dry_build(build_conf):
801807 status = [random .random () * 10 , random .randint (0 , 1 )]
802808 if status [1 ] == 1 :
803809 # 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"
805811 # random failed
806812 dummy = open (logFile , "w" )
807813 if random .randint (0 , 1 ) == 1 :
0 commit comments