blob: e2d585d2c54e87391183a825e705a792d2a952e8 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3# Recipe creation tool
4#
5# Copyright (C) 2014 Intel Corporation
6#
Brad Bishopc342db32019-05-15 21:57:59 -04007# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
10import sys
11import os
12import argparse
13import glob
14import logging
15
16scripts_path = os.path.dirname(os.path.realpath(__file__))
17lib_path = scripts_path + '/lib'
18sys.path = sys.path + [lib_path]
19import scriptutils
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020import argparse_oe
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021logger = scriptutils.logger_create('recipetool')
22
23plugins = []
24
25def tinfoil_init(parserecipes):
26 import bb.tinfoil
27 import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028 tinfoil = bb.tinfoil.Tinfoil(tracking=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 tinfoil.logger.setLevel(logger.getEffectiveLevel())
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030 tinfoil.prepare(not parserecipes)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 return tinfoil
32
33def main():
34
35 if not os.environ.get('BUILDDIR', ''):
36 logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
37 sys.exit(1)
38
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039 parser = argparse_oe.ArgumentParser(description="OpenEmbedded recipe tool",
40 add_help=False,
41 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
43 parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
44 parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
45
46 global_args, unparsed_args = parser.parse_known_args()
47
48 # Help is added here rather than via add_help=True, as we don't want it to
49 # be handled by parse_known_args()
50 parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
51 help='show this help message and exit')
52 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054
55 if global_args.debug:
56 logger.setLevel(logging.DEBUG)
57 elif global_args.quiet:
58 logger.setLevel(logging.ERROR)
59
60 import scriptpath
61 bitbakepath = scriptpath.add_bitbake_lib_path()
62 if not bitbakepath:
63 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
64 sys.exit(1)
65 logger.debug('Found bitbake path: %s' % bitbakepath)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 scriptpath.add_oe_lib_path()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
68 scriptutils.logger_setup_color(logger, global_args.color)
69
70 tinfoil = tinfoil_init(False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 for path in (tinfoil.config_data.getVar('BBPATH').split(':')
73 + [scripts_path]):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 pluginpath = os.path.join(path, 'lib', 'recipetool')
75 scriptutils.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 elif hasattr(plugin, 'register_command'):
83 # Legacy function name
84 registered = True
85 plugin.register_command(subparsers)
86 if hasattr(plugin, 'tinfoil_init'):
87 plugin.tinfoil_init(tinfoil)
88
89 if not registered:
90 logger.error("No commands registered - missing plugins?")
91 sys.exit(1)
92
93 args = parser.parse_args(unparsed_args, namespace=global_args)
94
95 try:
96 if getattr(args, 'parserecipes', False):
97 tinfoil.config_data.disableTracking()
98 tinfoil.parseRecipes()
99 tinfoil.config_data.enableTracking()
100 ret = args.func(args)
101 except bb.BBHandledException:
102 ret = 1
103 finally:
104 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105
106 return ret
107
108
109if __name__ == "__main__":
110 try:
111 ret = main()
112 except Exception:
113 ret = 1
114 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500115 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 sys.exit(ret)