summaryrefslogtreecommitdiffstats
path: root/scripts/devtool
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/devtool')
-rwxr-xr-xscripts/devtool155
1 files changed, 101 insertions, 54 deletions
diff --git a/scripts/devtool b/scripts/devtool
index e4d9db301a..af4811b922 100755
--- a/scripts/devtool
+++ b/scripts/devtool
@@ -1,28 +1,18 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# OpenEmbedded Development tool
#
# Copyright (C) 2014-2015 Intel Corporation
#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
+# SPDX-License-Identifier: GPL-2.0-only
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import os
import argparse
import glob
import re
-import ConfigParser
+import configparser
import subprocess
import logging
@@ -37,6 +27,7 @@ lib_path = scripts_path + '/lib'
sys.path = sys.path + [lib_path]
from devtool import DevtoolError, setup_tinfoil
import scriptutils
+import argparse_oe
logger = scriptutils.logger_create('devtool')
plugins = []
@@ -50,12 +41,12 @@ class ConfigHandler(object):
def __init__(self, filename):
self.config_file = filename
- self.config_obj = ConfigParser.SafeConfigParser()
+ self.config_obj = configparser.ConfigParser()
def get(self, section, option, default=None):
try:
ret = self.config_obj.get(section, option)
- except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
+ except (configparser.NoOptionError, configparser.NoSectionError):
if default != None:
ret = default
else:
@@ -85,6 +76,11 @@ class ConfigHandler(object):
with open(self.config_file, 'w') as f:
self.config_obj.write(f)
+ def set(self, section, option, value):
+ if not self.config_obj.has_section(section):
+ self.config_obj.add_section(section)
+ self.config_obj.set(section, option, value)
+
class Context:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
@@ -104,15 +100,33 @@ def read_workspace():
_enable_workspace_layer(config.workspace_path, config, basepath)
logger.debug('Reading workspace in %s' % config.workspace_path)
- externalsrc_re = re.compile(r'^EXTERNALSRC(_pn-([^ =]+))? *= *"([^"]*)"$')
+ externalsrc_re = re.compile(r'^EXTERNALSRC(:pn-([^ =]+))? *= *"([^"]*)"$')
for fn in glob.glob(os.path.join(config.workspace_path, 'appends', '*.bbappend')):
with open(fn, 'r') as f:
+ pnvalues = {}
for line in f:
res = externalsrc_re.match(line.rstrip())
if res:
- pn = res.group(2) or os.path.splitext(os.path.basename(fn))[0].split('_')[0]
- workspace[pn] = {'srctree': res.group(3),
- 'bbappend': fn}
+ recipepn = os.path.splitext(os.path.basename(fn))[0].split('_')[0]
+ pn = res.group(2) or recipepn
+ # Find the recipe file within the workspace, if any
+ bbfile = os.path.basename(fn).replace('.bbappend', '.bb').replace('%', '*')
+ recipefile = glob.glob(os.path.join(config.workspace_path,
+ 'recipes',
+ recipepn,
+ bbfile))
+ if recipefile:
+ recipefile = recipefile[0]
+ pnvalues['srctree'] = res.group(3)
+ pnvalues['bbappend'] = fn
+ pnvalues['recipefile'] = recipefile
+ elif line.startswith('# srctreebase: '):
+ pnvalues['srctreebase'] = line.split(':', 1)[1].strip()
+ if pnvalues:
+ if not pnvalues.get('srctreebase', None):
+ pnvalues['srctreebase'] = pnvalues['srctree']
+ logger.debug('Found recipe %s' % pnvalues)
+ workspace[pn] = pnvalues
def create_workspace(args, config, basepath, workspace):
if args.layerpath:
@@ -141,16 +155,24 @@ def _create_workspace(workspacedir, config, basepath):
f.write('BBFILE_PATTERN_workspacelayer = "^$' + '{LAYERDIR}/"\n')
f.write('BBFILE_PATTERN_IGNORE_EMPTY_workspacelayer = "1"\n')
f.write('BBFILE_PRIORITY_workspacelayer = "99"\n')
+ f.write('LAYERSERIES_COMPAT_workspacelayer = "${LAYERSERIES_COMPAT_core}"\n')
# Add a README file
with open(os.path.join(workspacedir, 'README'), 'w') as f:
f.write('This layer was created by the OpenEmbedded devtool utility in order to\n')
- f.write('contain recipes and bbappends. In most instances you should use the\n')
+ f.write('contain recipes and bbappends that are currently being worked on. The idea\n')
+ f.write('is that the contents is temporary - once you have finished working on a\n')
+ f.write('recipe you use the appropriate method to move the files you have been\n')
+ f.write('working on to a proper layer. In most instances you should use the\n')
f.write('devtool utility to manage files within it rather than modifying files\n')
f.write('directly (although recipes added with "devtool add" will often need\n')
f.write('direct modification.)\n')
- f.write('\nIf you no longer need to use devtool you can remove the path to this\n')
- f.write('workspace layer from your conf/bblayers.conf file (and then delete the\n')
- f.write('layer, if you wish).\n')
+ f.write('\nIf you no longer need to use devtool or the workspace layer\'s contents\n')
+ f.write('you can remove the path to this workspace layer from your conf/bblayers.conf\n')
+ f.write('file (and then delete the layer, if you wish).\n')
+ f.write('\nNote that by default, if devtool fetches and unpacks source code, it\n')
+ f.write('will place it in a subdirectory of a "sources" subdirectory of the\n')
+ f.write('layer. If you prefer it to be elsewhere you can specify the source\n')
+ f.write('tree path on the command line.\n')
def _enable_workspace_layer(workspacedir, config, basepath):
"""Ensure the workspace layer is in bblayers.conf"""
@@ -159,7 +181,11 @@ def _enable_workspace_layer(workspacedir, config, basepath):
if not os.path.exists(bblayers_conf):
logger.error('Unable to find bblayers.conf')
return
- _, added = bb.utils.edit_bblayers_conf(bblayers_conf, workspacedir, config.workspace_path)
+ if os.path.abspath(workspacedir) != os.path.abspath(config.workspace_path):
+ removedir = config.workspace_path
+ else:
+ removedir = None
+ _, added = bb.utils.edit_bblayers_conf(bblayers_conf, workspacedir, removedir)
if added:
logger.info('Enabling workspace layer in bblayers.conf')
if config.workspace_path != workspacedir:
@@ -173,21 +199,17 @@ def main():
global config
global context
+ if sys.getfilesystemencoding() != "utf-8":
+ sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.")
+
context = Context(fixed_setup=False)
# Default basepath
basepath = os.path.dirname(os.path.abspath(__file__))
- pth = basepath
- while pth != '' and pth != os.sep:
- if os.path.exists(os.path.join(pth, '.devtoolbase')):
- context.fixed_setup = True
- basepath = pth
- break
- pth = os.path.dirname(pth)
- parser = argparse.ArgumentParser(description="OpenEmbedded development tool",
- add_help=False,
- epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
+ parser = argparse_oe.ArgumentParser(description="OpenEmbedded development tool",
+ add_help=False,
+ epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
parser.add_argument('--basepath', help='Base directory of SDK / build directory')
parser.add_argument('--bbpath', help='Explicitly specify the BBPATH, rather than getting it from the metadata')
parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
@@ -209,17 +231,29 @@ def main():
if global_args.basepath:
# Override
basepath = global_args.basepath
- elif not context.fixed_setup:
- basepath = os.environ.get('BUILDDIR')
- if not basepath:
- logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
- sys.exit(1)
+ if os.path.exists(os.path.join(basepath, '.devtoolbase')):
+ context.fixed_setup = True
+ else:
+ pth = basepath
+ while pth != '' and pth != os.sep:
+ if os.path.exists(os.path.join(pth, '.devtoolbase')):
+ context.fixed_setup = True
+ basepath = pth
+ break
+ pth = os.path.dirname(pth)
+
+ if not context.fixed_setup:
+ basepath = os.environ.get('BUILDDIR')
+ if not basepath:
+ logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
+ sys.exit(1)
logger.debug('Using basepath %s' % basepath)
config = ConfigHandler(os.path.join(basepath, 'conf', 'devtool.conf'))
if not config.read():
return -1
+ context.config = config
bitbake_subdir = config.get('General', 'bitbake_subdir', '')
if bitbake_subdir:
@@ -241,27 +275,38 @@ def main():
scriptutils.logger_setup_color(logger, global_args.color)
if global_args.bbpath is None:
- tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
- global_args.bbpath = tinfoil.config_data.getVar('BBPATH', True)
- else:
- tinfoil = None
-
- for path in [scripts_path] + global_args.bbpath.split(':'):
+ try:
+ tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
+ try:
+ global_args.bbpath = tinfoil.config_data.getVar('BBPATH')
+ finally:
+ tinfoil.shutdown()
+ except bb.BBHandledException:
+ return 2
+
+ # Search BBPATH first to allow layers to override plugins in scripts_path
+ for path in global_args.bbpath.split(':') + [scripts_path]:
pluginpath = os.path.join(path, 'lib', 'devtool')
scriptutils.load_plugins(logger, plugins, pluginpath)
- if tinfoil:
- tinfoil.shutdown()
-
subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
+ subparsers.required = True
+
+ subparsers.add_subparser_group('sdk', 'SDK maintenance', -2)
+ subparsers.add_subparser_group('advanced', 'Advanced', -1)
+ subparsers.add_subparser_group('starting', 'Beginning work on a recipe', 100)
+ subparsers.add_subparser_group('info', 'Getting information')
+ subparsers.add_subparser_group('working', 'Working on a recipe in the workspace')
+ subparsers.add_subparser_group('testbuild', 'Testing changes on target')
if not context.fixed_setup:
parser_create_workspace = subparsers.add_parser('create-workspace',
- help='Set up a workspace',
- description='Sets up a new workspace. NOTE: other devtool subcommands will create a workspace automatically as needed, so you only need to use %(prog)s if you want to specify where the workspace should be located.')
+ help='Set up workspace in an alternative location',
+ description='Sets up a new workspace. NOTE: other devtool subcommands will create a workspace automatically as needed, so you only need to use %(prog)s if you want to specify where the workspace should be located.',
+ group='advanced')
parser_create_workspace.add_argument('layerpath', nargs='?', help='Path in which the workspace layer should be created')
parser_create_workspace.add_argument('--create-only', action="store_true", help='Only create the workspace layer, do not alter configuration')
- parser_create_workspace.set_defaults(func=create_workspace)
+ parser_create_workspace.set_defaults(func=create_workspace, no_workspace=True)
for plugin in plugins:
if hasattr(plugin, 'register_commands'):
@@ -269,7 +314,7 @@ def main():
args = parser.parse_args(unparsed_args, namespace=global_args)
- if args.subparser_name != 'create-workspace':
+ if not getattr(args, 'no_workspace', False):
read_workspace()
try:
@@ -277,7 +322,9 @@ def main():
except DevtoolError as err:
if str(err):
logger.error(str(err))
- ret = 1
+ ret = err.exitcode
+ except argparse_oe.ArgumentUsageError as ae:
+ parser.error_subcommand(ae.message, ae.subcommand)
return ret
@@ -288,5 +335,5 @@ if __name__ == "__main__":
except Exception:
ret = 1
import traceback
- traceback.print_exc(5)
+ traceback.print_exc()
sys.exit(ret)