Skip to content

Commit abc3e61

Browse files
committed
ci(generic_board_to_skip): update dynamically config files
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 1b0f20d commit abc3e61

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

Diff for: CI/build/generic_boards_to_skip.py

+43-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import json
23
from pathlib import Path
34

45

@@ -7,14 +8,49 @@
78
core_path = script_path.parent.parent
89
variant_path = core_path / "variants"
910
boards_entry_filename = "boards_entry.txt"
10-
output_filemane = script_path / "generic_boards_to_skip.json"
11+
# Config files
12+
conf_path = script_path / "conf"
13+
cores_file = conf_path / "cores_config.json"
14+
ci_file = conf_path / "cores_config_ci.json"
1115

1216
# Parser
1317
parser = argparse.ArgumentParser(
1418
description="Generate list of generic boards to skip for ci core config"
1519
)
1620

1721

22+
def update_config(config_file, boards_list):
23+
if not config_file.is_file():
24+
print(f"{config_file} not found!")
25+
exit(1)
26+
try:
27+
config = open(config_file, "r")
28+
json_data = json.load(config)
29+
config.close()
30+
# Update the values for generic boards
31+
# First search correct value
32+
core_index = -1
33+
sketch_index = -1
34+
for index, core in enumerate(json_data["cores"]):
35+
if core["architecture"] == "stm32":
36+
core_index = index
37+
for index2, sketch in enumerate(core["sketches"]):
38+
if sketch["pattern"] == "^.*$":
39+
sketch_index = index2
40+
old_boards_list = json_data["cores"][core_index]["sketches"][sketch_index][
41+
"boards"
42+
]
43+
old_boards_list = [x for x in old_boards_list if not x.startswith("GENERIC_")]
44+
new_boards_list = old_boards_list + boards_list
45+
new_boards_list.sort()
46+
json_data["cores"][core_index]["sketches"][index]["boards"] = new_boards_list
47+
config = open(config_file, "w")
48+
config.write(json.dumps(json_data, indent=2))
49+
config.close()
50+
except IOError:
51+
print(f"Failed to open {config_file}!")
52+
53+
1854
def main():
1955
# Get mcu_family directories
2056
mcu_families = sorted(variant_path.glob("STM32*/"))
@@ -31,18 +67,12 @@ def main():
3167
boards_list.append(line.partition("=")[-1].strip())
3268
# Remove last board of the boards_entry to not skip it
3369
boards_list.pop()
34-
# Create file
35-
try:
36-
output_file = open(output_filemane, "w", newline="\n")
37-
for count, board in enumerate(sorted(boards_list), start=1):
38-
if count % 4 == 0:
39-
output_file.write(f'"{board}",\n')
40-
else:
41-
output_file.write(f'"{board}", ')
42-
output_file.close()
43-
except IOError:
44-
print(f"Failed to open {output_filemane}")
45-
exit(1)
70+
boards_list.sort()
71+
72+
# Update each config files
73+
update_config(ci_file, boards_list)
74+
update_config(cores_file, boards_list)
75+
4676
exit(0)
4777

4878

0 commit comments

Comments
 (0)