Skip to content

west build: display closest matches when an invalid board is given #91110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmake/modules/boards.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,9 @@ elseif(BOARD_DIR)
"Please run a pristine build."
)
else()
message("No board named '${BOARD}' found.\n\n"
"Please choose one of the following boards:\n"
)
execute_process(${list_boards_commands})
message("No board named '${BOARD}' found. Did you mean:\n")
execute_process(${list_boards_commands} --fuzzy-match ${BOARD})
message("\nRun 'west boards' for the full list.")
unset(CACHED_BOARD CACHE)
message(FATAL_ERROR "Invalid BOARD; see above.")
endif()
Expand Down
13 changes: 12 additions & 1 deletion scripts/list_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0

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


def add_args_formatting(parser):
Expand Down Expand Up @@ -414,6 +417,9 @@ def board_v2_qualifiers_csv(board):

def dump_v2_boards(args):
boards = find_v2_boards(args)
if args.fuzzy_match is not None:
close_boards = difflib.get_close_matches(args.fuzzy_match, boards.keys())
boards = {b: boards[b] for b in close_boards}

for b in boards.values():
qualifiers_list = board_v2_qualifiers(b)
Expand Down Expand Up @@ -442,6 +448,11 @@ def notfound(x):
def dump_boards(args):
arch2boards = find_arch2boards(args)
for arch, boards in arch2boards.items():
if args.fuzzy_match is not None:
close_boards = difflib.get_close_matches(args.fuzzy_match, [b.name for b in boards])
if not close_boards:
continue
boards = [b for b in boards if b.name in close_boards]
if args.cmakeformat is None:
print(f'{arch}:')
for board in boards:
Expand Down
Loading