Skip to content

Commit f779d6a

Browse files
committed
ci(arduino_ci): review find board function
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 21a9c5c commit f779d6a

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

CI/build/arduino-cli.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -458,22 +458,17 @@ def find_board():
458458
if args.board:
459459
arg_board_pattern = re.compile(args.board, re.IGNORECASE)
460460

461-
fqbn_list_tmp = []
462461
try:
463462
output = subprocess.check_output(
464-
[arduino_cli, "board", "listall", "--format", "json"],
463+
[arduino_cli, "board", "search", arduino_platform, "--format", "json"],
465464
stderr=subprocess.STDOUT,
466465
).decode("utf-8")
467466
except subprocess.CalledProcessError as e:
468467
print(f"'{' '.join(e.cmd)}' failed with code: {e.returncode}!")
469468
print(e.stdout.decode("utf-8"))
470469
quit(e.returncode)
471470
else:
472-
boards_list = json.loads(output)
473-
if boards_list is not None:
474-
for board in boards_list["boards"]:
475-
if arduino_platform in board["fqbn"]:
476-
fqbn_list_tmp.append(board["fqbn"])
471+
fqbn_list_tmp = [board["fqbn"] for board in json.loads(output)]
477472
if not len(fqbn_list_tmp):
478473
print(f"No boards found for {arduino_platform}")
479474
quit(1)
@@ -490,6 +485,7 @@ def find_board():
490485
stm32_url,
491486
"--format",
492487
"json",
488+
"-b",
493489
fqbn,
494490
],
495491
stderr=subprocess.STDOUT,
@@ -500,22 +496,18 @@ def find_board():
500496
quit(e.returncode)
501497
else:
502498
board_detail = json.loads(output)
503-
if board_detail is not None:
504-
if "config_options" not in board_detail:
505-
print("No config_options found for " + fqbn)
506-
quit(1)
507-
for option in board_detail["config_options"]:
508-
if option["option"] == "pnum":
509-
for value in option["values"]:
510-
if args.board:
511-
if arg_board_pattern.search(value["value"]) is None:
512-
continue
513-
board_found[
514-
value["value"]
515-
] = f"{fqbn}:pnum={value['value']}"
516-
break
517-
else:
518-
print(f"No detail found for:'{fqbn}'!")
499+
for val in next(
500+
(
501+
item
502+
for item in board_detail.get("config_options", [])
503+
if item["option"] == "pnum"
504+
),
505+
{},
506+
).get("values", []):
507+
if args.board:
508+
if arg_board_pattern.search(val["value"]) is None:
509+
continue
510+
board_found[val["value"]] = f"{fqbn}:pnum={val['value']}"
519511
if board_found:
520512
board_fqbn = collections.OrderedDict(sorted(board_found.items()))
521513
else:

0 commit comments

Comments
 (0)