* [PATCH 2/3] recipetool: also load plugins from BBPATH
2015-06-29 20:49 [PATCH 0/3] One recipetool fix and a couple enhancements Christopher Larson
2015-06-29 20:50 ` [PATCH 1/3] recipetool: catch BBHandledException from parsing Christopher Larson
@ 2015-06-29 20:50 ` Christopher Larson
2015-06-29 20:50 ` [PATCH 3/3] recipetool.append: add extralines arg to appendsrc Christopher Larson
2 siblings, 0 replies; 4+ messages in thread
From: Christopher Larson @ 2015-06-29 20:50 UTC (permalink / raw)
To: openembedded-core
This makes it easier to extend, as a layer can add its own sub-commands.
Signed-off-by: Christopher Larson <kergoth@gmail.com>
---
scripts/recipetool | 67 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/scripts/recipetool b/scripts/recipetool
index 3063cf7..5ebef6b 100755
--- a/scripts/recipetool
+++ b/scripts/recipetool
@@ -36,11 +36,8 @@ def tinfoil_init(parserecipes):
import logging
tinfoil = bb.tinfoil.Tinfoil()
tinfoil.prepare(not parserecipes)
-
- for plugin in plugins:
- if hasattr(plugin, 'tinfoil_init'):
- plugin.tinfoil_init(tinfoil)
tinfoil.logger.setLevel(logger.getEffectiveLevel())
+ return tinfoil
def main():
@@ -48,42 +45,58 @@ def main():
logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
sys.exit(1)
- parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
- epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
- parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
- parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
- parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
- subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+ def create_global_parser(**kwargs):
+ parser = argparse.ArgumentParser(description="OpenEmbedded recipe tool",
+ epilog="Use %(prog)s <subcommand> --help to get help on a specific command", **kwargs)
+ parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
+ parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
+ parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
+ return parser
+
+ parser = create_global_parser(add_help=False)
+ initial_args, unparsed_args = parser.parse_known_args(sys.argv[1:])
+ if initial_args.debug:
+ logger.setLevel(logging.DEBUG)
+ elif initial_args.quiet:
+ logger.setLevel(logging.ERROR)
+
+ # Re-create the parser here because adding the subparsers doesn't cause
+ # ArgumentParser to re-generate the formatted help text after
+ # parse_known_args()
+ parser = create_global_parser()
+
+ import scriptpath
+ bitbakepath = scriptpath.add_bitbake_lib_path()
+ if not bitbakepath:
+ logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
+ sys.exit(1)
+ logger.debug('Found bitbake path: %s' % bitbakepath)
- scriptutils.load_plugins(logger, plugins, os.path.join(scripts_path, 'lib', 'recipetool'))
+ scriptutils.logger_setup_color(logger, initial_args.color)
+
+ subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
+ tinfoil = tinfoil_init(False)
+ for path in ([scripts_path] +
+ tinfoil.config_data.getVar('BBPATH', True).split(':')):
+ pluginpath = os.path.join(path, 'lib', 'recipetool')
+ scriptutils.load_plugins(logger, plugins, pluginpath)
registered = False
for plugin in plugins:
if hasattr(plugin, 'register_command'):
registered = True
plugin.register_command(subparsers)
+ if hasattr(plugin, 'tinfoil_init'):
+ plugin.tinfoil_init(tinfoil)
if not registered:
logger.error("No commands registered - missing plugins?")
sys.exit(1)
- args = parser.parse_args()
-
- if args.debug:
- logger.setLevel(logging.DEBUG)
- elif args.quiet:
- logger.setLevel(logging.ERROR)
-
- import scriptpath
- bitbakepath = scriptpath.add_bitbake_lib_path()
- if not bitbakepath:
- logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
- sys.exit(1)
- logger.debug('Found bitbake path: %s' % bitbakepath)
-
- scriptutils.logger_setup_color(logger, args.color)
+ args = parser.parse_args(unparsed_args, namespace=initial_args)
try:
- tinfoil_init(getattr(args, 'parserecipes', False))
+ if getattr(args, 'parserecipes', False):
+ tinfoil.parseRecipes()
ret = args.func(args)
except bb.BBHandledException:
ret = 1
--
2.2.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] recipetool.append: add extralines arg to appendsrc
2015-06-29 20:49 [PATCH 0/3] One recipetool fix and a couple enhancements Christopher Larson
2015-06-29 20:50 ` [PATCH 1/3] recipetool: catch BBHandledException from parsing Christopher Larson
2015-06-29 20:50 ` [PATCH 2/3] recipetool: also load plugins from BBPATH Christopher Larson
@ 2015-06-29 20:50 ` Christopher Larson
2 siblings, 0 replies; 4+ messages in thread
From: Christopher Larson @ 2015-06-29 20:50 UTC (permalink / raw)
To: openembedded-core
This makes the function more reusable for other sub-commands.
Signed-off-by: Christopher Larson <kergoth@gmail.com>
---
scripts/lib/recipetool/append.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/lib/recipetool/append.py b/scripts/lib/recipetool/append.py
index 9903871..24a7903 100644
--- a/scripts/lib/recipetool/append.py
+++ b/scripts/lib/recipetool/append.py
@@ -334,7 +334,7 @@ def appendfile(args):
return 3
-def appendsrc(args, files, rd):
+def appendsrc(args, files, rd, extralines=None):
import oe.recipeutils
srcdir = rd.getVar('S', True)
@@ -349,7 +349,7 @@ def appendsrc(args, files, rd):
simplified[simple_uri] = uri
copyfiles = {}
- extralines = []
+ extralines = extralines or []
for newfile, srcfile in files.iteritems():
src_destdir = os.path.dirname(srcfile)
if not args.use_workdir:
--
2.2.1
^ permalink raw reply related [flat|nested] 4+ messages in thread