blob: 449434d468e881e4d2cb240f06fcc9d1d55dd3d8 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
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#
Brad Bishopc342db32019-05-15 21:57:59 -040010# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
13import logging
14import os
15import sys
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016import argparse
Andrew Geissler5199d832021-09-24 16:47:35 -050017import warnings
18warnings.simplefilter("default")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20bindir = os.path.dirname(__file__)
21topdir = os.path.dirname(bindir)
22sys.path[0:0] = [os.path.join(topdir, 'lib')]
23
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024import bb.tinfoil
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025import bb.msg
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027logger = bb.msg.logger_create('bitbake-layers', sys.stdout)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029def main():
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 parser = argparse.ArgumentParser(
31 description="BitBake layers utility",
32 epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
33 add_help=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
35 parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036 parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037 parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
38
39 global_args, unparsed_args = parser.parse_known_args()
40
41 # Help is added here rather than via add_help=True, as we don't want it to
42 # be handled by parse_known_args()
43 parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
44 help='show this help message and exit')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048 if global_args.debug:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 logger.setLevel(logging.DEBUG)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 elif global_args.quiet:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 logger.setLevel(logging.ERROR)
52
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053 # Need to re-run logger_create with color argument
54 # (will be the same logger since it has the same name)
Andrew Geissler82c905d2020-04-13 13:39:40 -050055 bb.msg.logger_create('bitbake-layers', output=sys.stdout,
56 color=global_args.color,
57 level=logger.getEffectiveLevel())
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 plugins = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 tinfoil = bb.tinfoil.Tinfoil(tracking=True)
61 tinfoil.logger.setLevel(logger.getEffectiveLevel())
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063 tinfoil.prepare(True)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060064 for path in ([topdir] +
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 tinfoil.config_data.getVar('BBPATH').split(':')):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066 pluginpath = os.path.join(path, 'lib', 'bblayers')
67 bb.utils.load_plugins(logger, plugins, pluginpath)
68
69 registered = False
70 for plugin in plugins:
71 if hasattr(plugin, 'register_commands'):
72 registered = True
73 plugin.register_commands(subparsers)
74 if hasattr(plugin, 'tinfoil_init'):
75 plugin.tinfoil_init(tinfoil)
76
77 if not registered:
78 logger.error("No commands registered - missing plugins?")
79 sys.exit(1)
80
81 args = parser.parse_args(unparsed_args, namespace=global_args)
82
83 if getattr(args, 'parserecipes', False):
84 tinfoil.config_data.disableTracking()
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085 tinfoil.parse_recipes()
Patrick Williamsc0f7c042017-02-23 20:41:17 -060086 tinfoil.config_data.enableTracking()
87
88 return args.func(args)
89 finally:
90 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091
92
93if __name__ == "__main__":
94 try:
95 ret = main()
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096 except bb.BBHandledException:
97 ret = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 except Exception:
99 ret = 1
100 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500101 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 sys.exit(ret)