]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blame - scripts/recipetool
cargo.bbclass: use offline mode for building
[thirdparty/openembedded/openembedded-core.git] / scripts / recipetool
CommitLineData
dad96178 1#!/usr/bin/env python3
fa07ada1
PE
2
3# Recipe creation tool
4#
5# Copyright (C) 2014 Intel Corporation
6#
f8c9c511 7# SPDX-License-Identifier: GPL-2.0-only
fa07ada1 8#
fa07ada1
PE
9
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
d62fe7c9 20import argparse_oe
fa07ada1
PE
21logger = scriptutils.logger_create('recipetool')
22
23plugins = []
24
dd2aa93b 25def tinfoil_init(parserecipes):
fa07ada1
PE
26 import bb.tinfoil
27 import logging
7c33ef77 28 tinfoil = bb.tinfoil.Tinfoil(tracking=True)
69f426a2 29 tinfoil.logger.setLevel(logger.getEffectiveLevel())
e124eb73 30 tinfoil.prepare(not parserecipes)
5753f20a 31 return tinfoil
fa07ada1
PE
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
d62fe7c9
PE
39 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")
fa07ada1
PE
42 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')
2c59b2b2 44 parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
899288a1
CL
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')
2c59b2b2 52 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
d36fdea1 53 subparsers.required = True
fa07ada1 54
899288a1
CL
55 if global_args.debug:
56 logger.setLevel(logging.DEBUG)
57 elif global_args.quiet:
58 logger.setLevel(logging.ERROR)
59
5753f20a
CL
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)
a61d7bf8 66 scriptpath.add_oe_lib_path()
5753f20a 67
899288a1
CL
68 scriptutils.logger_setup_color(logger, global_args.color)
69
5753f20a 70 tinfoil = tinfoil_init(False)
22ba003f 71 try:
0a36bd96 72 for path in (tinfoil.config_data.getVar('BBPATH').split(':')
7a8726a3 73 + [scripts_path]):
5ec6d9ef
PE
74 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()
fa07ada1
PE
105
106 return ret
107
108
109if __name__ == "__main__":
110 try:
111 ret = main()
112 except Exception:
113 ret = 1
114 import traceback
6069175e 115 traceback.print_exc()
fa07ada1 116 sys.exit(ret)