xref: /openbmc/openbmc/poky/meta/lib/bblayers/machines.py (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7import logging
8import pathlib
9
10from bblayers.common import LayerPlugin
11
12logger = logging.getLogger('bitbake-layers')
13
14def plugin_init(plugins):
15    return ShowMachinesPlugin()
16
17class ShowMachinesPlugin(LayerPlugin):
18    def do_show_machines(self, args):
19        """List the machines available in the currently configured layers."""
20
21        for layer_dir in self.bblayers:
22            layer_name = self.get_layer_name(layer_dir)
23
24            if args.layer and args.layer != layer_name:
25                continue
26
27            for p in sorted(pathlib.Path(layer_dir).glob("conf/machine/*.conf")):
28                if args.bare:
29                    logger.plain("%s" % (p.stem))
30                else:
31                    logger.plain("%s (%s)" % (p.stem, layer_name))
32
33
34    def register_commands(self, sp):
35        parser_show_machines = self.add_command(sp, "show-machines", self.do_show_machines)
36        parser_show_machines.add_argument('-b', '--bare', help='output just the machine names, not the source layer', action='store_true')
37        parser_show_machines.add_argument('-l', '--layer', help='Limit to machines in the specified layer')
38