blob: d184011ea6b3c406b5cc09a4da1f70c4a005d923 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/env python3
2
3# This script has subcommands which operate against your bitbake layers, either
4# displaying useful information, or acting against them.
5# See the help output for details on available commands.
6
7# Copyright (C) 2011 Mentor Graphics Corporation
8# Copyright (C) 2011-2015 Intel Corporation
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License version 2 as
12# published by the Free Software Foundation.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23import logging
24import os
25import sys
26import argparse
27import signal
28
29bindir = os.path.dirname(__file__)
30topdir = os.path.dirname(bindir)
31sys.path[0:0] = [os.path.join(topdir, 'lib')]
32
33import bb.tinfoil
34import bb.msg
35
36logger = bb.msg.logger_create('bitbake-layers', sys.stdout)
37
38def main():
39 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
40 parser = argparse.ArgumentParser(
41 description="BitBake layers utility",
42 epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
43 add_help=False)
44 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
45 parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
46 parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true')
47 parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
48
49 global_args, unparsed_args = parser.parse_known_args()
50
51 # Help is added here rather than via add_help=True, as we don't want it to
52 # be handled by parse_known_args()
53 parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
54 help='show this help message and exit')
55 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
56 subparsers.required = True
57
58 if global_args.debug:
59 logger.setLevel(logging.DEBUG)
60 elif global_args.quiet:
61 logger.setLevel(logging.ERROR)
62
63 # Need to re-run logger_create with color argument
64 # (will be the same logger since it has the same name)
65 bb.msg.logger_create('bitbake-layers', output=sys.stdout, color=global_args.color)
66
67 plugins = []
68 tinfoil = bb.tinfoil.Tinfoil(tracking=True)
69 tinfoil.logger.setLevel(logger.getEffectiveLevel())
70 try:
71 tinfoil.prepare(True)
72 for path in ([topdir] +
73 tinfoil.config_data.getVar('BBPATH').split(':')):
74 pluginpath = os.path.join(path, 'lib', 'bblayers')
75 bb.utils.load_plugins(logger, plugins, pluginpath)
76
77 registered = False
78 for plugin in plugins:
79 if hasattr(plugin, 'register_commands'):
80 registered = True
81 plugin.register_commands(subparsers)
82 if hasattr(plugin, 'tinfoil_init'):
83 plugin.tinfoil_init(tinfoil)
84
85 if not registered:
86 logger.error("No commands registered - missing plugins?")
87 sys.exit(1)
88
89 args = parser.parse_args(unparsed_args, namespace=global_args)
90
91 if getattr(args, 'parserecipes', False):
92 tinfoil.config_data.disableTracking()
93 tinfoil.parse_recipes()
94 tinfoil.config_data.enableTracking()
95
96 return args.func(args)
97 finally:
98 tinfoil.shutdown()
99
100
101if __name__ == "__main__":
102 try:
103 ret = main()
104 except bb.BBHandledException:
105 ret = 1
106 except Exception:
107 ret = 1
108 import traceback
109 traceback.print_exc()
110 sys.exit(ret)