zephyr/scripts/west_commands/boards.py
Martí Bolívar 0d5e6c13e9 boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.

Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.

Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.

Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.

Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.

Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-01-15 15:07:49 -05:00

75 lines
2.3 KiB
Python

# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
from pathlib import Path
import re
import sys
import textwrap
from west import log
from west.commands import WestCommand
sys.path.append(os.fspath(Path(__file__).parent.parent))
import list_boards
class Boards(WestCommand):
def __init__(self):
super().__init__(
'boards',
# Keep this in sync with the string in west-commands.yml.
'display information about supported boards',
'Display information about boards',
accepts_unknown_args=False)
def do_add_parser(self, parser_adder):
default_fmt = '{name}'
parser = parser_adder.add_parser(
self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description,
epilog=textwrap.dedent(f'''\
FORMAT STRINGS
--------------
Boards are listed using a Python 3 format string. Arguments
to the format string are accessed by name.
The default format string is:
"{default_fmt}"
The following arguments are available:
- name: board name
- arch: board architecture
- dir: directory that contains the board definition
'''))
# Remember to update west-completion.bash if you add or remove
# flags
parser.add_argument('-f', '--format', default=default_fmt,
help='''Format string to use to list each board;
see FORMAT STRINGS below.''')
parser.add_argument('-n', '--name', dest='name_re',
help='''a regular expression; only boards whose
names match NAME_RE will be listed''')
list_boards.add_args(parser)
return parser
def do_run(self, args, _):
if args.name_re is not None:
name_re = re.compile(args.name_re)
else:
name_re = None
for board in list_boards.find_boards(args):
if name_re is not None and not name_re.search(board.name):
continue
log.inf(args.format.format(name=board.name, arch=board.arch,
dir=board.dir))