Skip to content

Commit fa9ad03

Browse files
committed
ci(arduino_ci): rework build index to ignore skipped
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 887a4e8 commit fa9ad03

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

CI/build/arduino-cli.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
fskip = "\033[33mskipped\033[0m"
106106
nl = "\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

109115
def cat(file):
110116
with open(file, "r") as f:
@@ -557,17 +563,17 @@ def find_board():
557563

558564

559565
# Check the status
560-
def check_status(status, build_conf, boardKo):
566+
def check_status(status, build_conf, boardKo, nb_build_conf):
561567
global nb_build_passed
562568
global nb_build_failed
563-
sketch_name = build_conf[4][-1].name
569+
sketch_name = build_conf[idx_cmd][-1].name
564570

565571
if status[1] == 0:
566572
result = fsucc
567573
nb_build_passed += 1
568574
elif status[1] == 1:
569575
# 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"
571577
error_found = False
572578
for i, line in enumerate(open(logFile)):
573579
if error_pattern.search(line):
@@ -580,7 +586,7 @@ def check_status(status, build_conf, boardKo):
580586
error_found = True
581587
if error_found:
582588
result = ffail
583-
boardKo.append(build_conf[0])
589+
boardKo.append(build_conf[idx_b_name])
584590
if args.ci:
585591
cat(logFile)
586592
nb_build_failed += 1
@@ -591,12 +597,12 @@ def check_status(status, build_conf, boardKo):
591597
nb_build_passed += 1
592598
else:
593599
result = "\033[31merror\033[0m"
594-
boardKo.append(build_conf[0])
600+
boardKo.append(build_conf[idx_b_name])
595601
nb_build_failed += 1
596602
print(
597603
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],
600606
result,
601607
status[0],
602608
)
@@ -702,47 +708,46 @@ def genBasicCommand(b_name):
702708

703709
def create_build_conf_list():
704710
build_conf_list = []
705-
idx = 1
706-
for b_name in board_fqbn:
711+
for idx, b_name in enumerate(board_fqbn, start=1):
707712
build_conf_list.append(
708-
(
713+
[
709714
b_name,
710715
idx,
711-
len(board_fqbn),
712716
output_dir / b_name,
713717
genBasicCommand(b_name),
714-
)
718+
]
715719
)
716-
idx += 1
717720
return build_conf_list
718721

719722

720723
def build_config(sketch, boardSkipped):
721724
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)
746751
return build_conf_list
747752

748753

@@ -773,11 +778,12 @@ def build_all():
773778
print(build_separator)
774779

775780
build_conf_list = build_config(sketch, boardSkipped)
781+
nb_build_conf = len(build_conf_list)
776782
with concurrent.futures.ProcessPoolExecutor(os.cpu_count() - 1) as executor:
777783
for build_conf, res in zip(
778784
build_conf_list, executor.map(build, build_conf_list)
779785
):
780-
check_status(res, build_conf, boardKo)
786+
check_status(res, build_conf, boardKo, nb_build_conf)
781787
log_sketch_build_result(sketch, boardKo, boardSkipped)
782788
# Ensure no cache issue
783789
deleteFolder(build_output_cache_dir)
@@ -786,9 +792,9 @@ def build_all():
786792

787793
# Run arduino-cli command
788794
def real_build(build_conf):
789-
cmd = build_conf[4]
795+
cmd = build_conf[idx_cmd]
790796
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:
792798
res = subprocess.Popen(cmd, stdout=stdout, stderr=subprocess.STDOUT)
793799
res.wait()
794800
status[0] = time.monotonic() - status[0]
@@ -802,7 +808,7 @@ def dry_build(build_conf):
802808
status = [random.random() * 10, random.randint(0, 1)]
803809
if status[1] == 1:
804810
# 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"
806812
# random failed
807813
dummy = open(logFile, "w")
808814
if random.randint(0, 1) == 1:

0 commit comments

Comments
 (0)