blob: 87fb35ed72abaedf5052988789cc807cac6b3f6b [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
2
3# Recipe creation tool
4#
5# Copyright (C) 2014 Intel Corporation
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20import sys
21import os
22import argparse
23import glob
24import logging
25
26scripts_path = os.path.dirname(os.path.realpath(__file__))
27lib_path = scripts_path + '/lib'
28sys.path = sys.path + [lib_path]
29import scriptutils
30logger = scriptutils.logger_create('recipetool')
31
32plugins = []
33
34def tinfoil_init(parserecipes):
35 import bb.tinfoil
36 import logging
37 tinfoil = bb.tinfoil.Tinfoil()
38 tinfoil.prepare(not parserecipes)
39 tinfoil.logger.setLevel(logger.getEffectiveLevel())
40 return tinfoil
41
42def main():
43
44 if not os.environ.get('BUILDDIR', ''):
45 logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
46 sys.exit(1)
47
48 parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
49 add_help=False,
50 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
51 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
52 parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
53 parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
54
55 global_args, unparsed_args = parser.parse_known_args()
56
57 # Help is added here rather than via add_help=True, as we don't want it to
58 # be handled by parse_known_args()
59 parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
60 help='show this help message and exit')
61 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
62
63 if global_args.debug:
64 logger.setLevel(logging.DEBUG)
65 elif global_args.quiet:
66 logger.setLevel(logging.ERROR)
67
68 import scriptpath
69 bitbakepath = scriptpath.add_bitbake_lib_path()
70 if not bitbakepath:
71 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
72 sys.exit(1)
73 logger.debug('Found bitbake path: %s' % bitbakepath)
74
75 scriptutils.logger_setup_color(logger, global_args.color)
76
77 tinfoil = tinfoil_init(False)
78 for path in ([scripts_path] +
79 tinfoil.config_data.getVar('BBPATH', True).split(':')):
80 pluginpath = os.path.join(path, 'lib', 'recipetool')
81 scriptutils.load_plugins(logger, plugins, pluginpath)
82
83 registered = False
84 for plugin in plugins:
85 if hasattr(plugin, 'register_command'):
86 registered = True
87 plugin.register_command(subparsers)
88 if hasattr(plugin, 'tinfoil_init'):
89 plugin.tinfoil_init(tinfoil)
90
91 if not registered:
92 logger.error("No commands registered - missing plugins?")
93 sys.exit(1)
94
95 args = parser.parse_args(unparsed_args, namespace=global_args)
96
97 try:
98 if getattr(args, 'parserecipes', False):
99 tinfoil.parseRecipes()
100 ret = args.func(args)
101 except bb.BBHandledException:
102 ret = 1
103
104 return ret
105
106
107if __name__ == "__main__":
108 try:
109 ret = main()
110 except Exception:
111 ret = 1
112 import traceback
113 traceback.print_exc(5)
114 sys.exit(ret)