Skip to content

Commit 77950d9

Browse files
committed
west build: display closest matching board names on error
This commit modifies the 'west build' command to display the closest matching boards when an invalid board is specified, making it easier for users to find a typo in the used board name. The user is also instructed to run 'west boards' if he wants to get the full list of available boards. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent e3ed029 commit 77950d9

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cmake/modules/boards.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,9 @@ elseif(BOARD_DIR)
218218
"Please run a pristine build."
219219
)
220220
else()
221-
message("No board named '${BOARD}' found.\n\n"
222-
"Please choose one of the following boards:\n"
223-
)
224-
execute_process(${list_boards_commands})
221+
message("No board named '${BOARD}' found. Did you mean:\n")
222+
execute_process(${list_boards_commands} --fuzzy-match ${BOARD})
223+
message("\nRun 'west boards' for the full list.")
225224
unset(CACHED_BOARD CACHE)
226225
message(FATAL_ERROR "Invalid BOARD; see above.")
227226
endif()

scripts/list_boards.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
import argparse
7+
import difflib
78
import itertools
89
import sys
910
from collections import Counter, defaultdict
@@ -372,7 +373,9 @@ def add_args(parser):
372373
parser.add_argument("--board", dest='board', default=None,
373374
help='lookup the specific board, fail if not found')
374375
parser.add_argument("--board-dir", default=[], type=Path, action='append',
375-
help='Only look for boards at the specific location')
376+
help='only look for boards at the specific location')
377+
parser.add_argument("--fuzzy-match", default=None,
378+
help='lookup boards similar to the given board name')
376379

377380

378381
def add_args_formatting(parser):
@@ -414,6 +417,9 @@ def board_v2_qualifiers_csv(board):
414417

415418
def dump_v2_boards(args):
416419
boards = find_v2_boards(args)
420+
if args.fuzzy_match is not None:
421+
close_boards = difflib.get_close_matches(args.fuzzy_match, boards.keys())
422+
boards = {b: boards[b] for b in close_boards}
417423

418424
for b in boards.values():
419425
qualifiers_list = board_v2_qualifiers(b)
@@ -442,6 +448,11 @@ def notfound(x):
442448
def dump_boards(args):
443449
arch2boards = find_arch2boards(args)
444450
for arch, boards in arch2boards.items():
451+
if args.fuzzy_match is not None:
452+
close_boards = difflib.get_close_matches(args.fuzzy_match, [b.name for b in boards])
453+
if not close_boards:
454+
continue
455+
boards = [b for b in boards if b.name in close_boards]
445456
if args.cmakeformat is None:
446457
print(f'{arch}:')
447458
for board in boards:

0 commit comments

Comments
 (0)