Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 10 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
| 13 | import logging |
| 14 | import os |
| 15 | import sys |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | import argparse |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | import signal |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
| 19 | bindir = os.path.dirname(__file__) |
| 20 | topdir = os.path.dirname(bindir) |
| 21 | sys.path[0:0] = [os.path.join(topdir, 'lib')] |
| 22 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | import bb.tinfoil |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | import bb.msg |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 26 | logger = bb.msg.logger_create('bitbake-layers', sys.stdout) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | def main(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 29 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 30 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | parser.add_argument('-F', '--force', help='Force add without recipe parse verification', action='store_true') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | subparsers.required = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 48 | if global_args.debug: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | logger.setLevel(logging.DEBUG) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 50 | elif global_args.quiet: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | logger.setLevel(logging.ERROR) |
| 52 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | # Need to re-run logger_create with color argument |
| 54 | # (will be the same logger since it has the same name) |
| 55 | bb.msg.logger_create('bitbake-layers', output=sys.stdout, color=global_args.color) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | plugins = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | tinfoil = bb.tinfoil.Tinfoil(tracking=True) |
| 59 | tinfoil.logger.setLevel(logger.getEffectiveLevel()) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 60 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 61 | tinfoil.prepare(True) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 62 | for path in ([topdir] + |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 63 | tinfoil.config_data.getVar('BBPATH').split(':')): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | pluginpath = os.path.join(path, 'lib', 'bblayers') |
| 65 | bb.utils.load_plugins(logger, plugins, pluginpath) |
| 66 | |
| 67 | registered = False |
| 68 | for plugin in plugins: |
| 69 | if hasattr(plugin, 'register_commands'): |
| 70 | registered = True |
| 71 | plugin.register_commands(subparsers) |
| 72 | if hasattr(plugin, 'tinfoil_init'): |
| 73 | plugin.tinfoil_init(tinfoil) |
| 74 | |
| 75 | if not registered: |
| 76 | logger.error("No commands registered - missing plugins?") |
| 77 | sys.exit(1) |
| 78 | |
| 79 | args = parser.parse_args(unparsed_args, namespace=global_args) |
| 80 | |
| 81 | if getattr(args, 'parserecipes', False): |
| 82 | tinfoil.config_data.disableTracking() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | tinfoil.parse_recipes() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 84 | tinfoil.config_data.enableTracking() |
| 85 | |
| 86 | return args.func(args) |
| 87 | finally: |
| 88 | tinfoil.shutdown() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
| 90 | |
| 91 | if __name__ == "__main__": |
| 92 | try: |
| 93 | ret = main() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 94 | except bb.BBHandledException: |
| 95 | ret = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | except Exception: |
| 97 | ret = 1 |
| 98 | import traceback |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 99 | traceback.print_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | sys.exit(ret) |