2015-08-21 13:00:57 +00:00
|
|
|
# Development tool - build-image plugin
|
|
|
|
#
|
|
|
|
# Copyright (C) 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""Devtool plugin containing the build-image subcommand."""
|
|
|
|
|
|
|
|
import os
|
2016-05-09 22:46:27 +00:00
|
|
|
import errno
|
2015-08-21 13:00:57 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from bb.process import ExecutionError
|
2015-09-22 16:21:37 +00:00
|
|
|
from devtool import exec_build_env_command, setup_tinfoil, parse_recipe, DevtoolError
|
2015-08-21 13:00:57 +00:00
|
|
|
|
2015-08-30 14:28:38 +00:00
|
|
|
logger = logging.getLogger('devtool')
|
2015-08-21 13:00:57 +00:00
|
|
|
|
2016-03-02 10:44:21 +00:00
|
|
|
class TargetNotImageError(Exception):
|
|
|
|
pass
|
|
|
|
|
2015-09-22 16:21:36 +00:00
|
|
|
def _get_packages(tinfoil, workspace, config):
|
2015-09-22 16:21:35 +00:00
|
|
|
"""Get list of packages from recipes in the workspace."""
|
2015-08-30 14:41:29 +00:00
|
|
|
result = []
|
|
|
|
for recipe in workspace:
|
|
|
|
data = parse_recipe(config, tinfoil, recipe, True)
|
2016-12-14 21:13:05 +00:00
|
|
|
if 'class-target' in data.getVar('OVERRIDES').split(':'):
|
|
|
|
if recipe in data.getVar('PACKAGES').split():
|
2015-08-30 14:41:29 +00:00
|
|
|
result.append(recipe)
|
|
|
|
else:
|
2015-09-22 16:21:35 +00:00
|
|
|
logger.warning("Skipping recipe %s as it doesn't produce a "
|
2015-08-30 14:41:29 +00:00
|
|
|
"package with the same name", recipe)
|
|
|
|
return result
|
|
|
|
|
2015-08-21 13:00:57 +00:00
|
|
|
def build_image(args, config, basepath, workspace):
|
|
|
|
"""Entry point for the devtool 'build-image' subcommand."""
|
2015-09-22 16:21:37 +00:00
|
|
|
|
|
|
|
image = args.imagename
|
|
|
|
auto_image = False
|
|
|
|
if not image:
|
|
|
|
sdk_targets = config.get('SDK', 'sdk_targets', '').split()
|
|
|
|
if sdk_targets:
|
|
|
|
image = sdk_targets[0]
|
|
|
|
auto_image = True
|
|
|
|
if not image:
|
|
|
|
raise DevtoolError('Unable to determine image to build, please specify one')
|
|
|
|
|
2016-03-02 10:44:21 +00:00
|
|
|
try:
|
|
|
|
if args.add_packages:
|
|
|
|
add_packages = args.add_packages.split(',')
|
|
|
|
else:
|
|
|
|
add_packages = None
|
|
|
|
result, outputdir = build_image_task(config, basepath, workspace, image, add_packages)
|
|
|
|
except TargetNotImageError:
|
|
|
|
if auto_image:
|
|
|
|
raise DevtoolError('Unable to determine image to build, please specify one')
|
|
|
|
else:
|
|
|
|
raise DevtoolError('Specified recipe %s is not an image recipe' % image)
|
|
|
|
|
|
|
|
if result == 0:
|
|
|
|
logger.info('Successfully built %s. You can find output files in %s'
|
|
|
|
% (image, outputdir))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def build_image_task(config, basepath, workspace, image, add_packages=None, task=None, extra_append=None):
|
2015-09-22 16:21:35 +00:00
|
|
|
# remove <image>.bbappend to make sure setup_tinfoil doesn't
|
|
|
|
# break because of it
|
2016-05-09 22:46:27 +00:00
|
|
|
target_basename = config.get('SDK', 'target_basename', '')
|
|
|
|
if target_basename:
|
|
|
|
appendfile = os.path.join(config.workspace_path, 'appends',
|
|
|
|
'%s.bbappend' % target_basename)
|
|
|
|
try:
|
|
|
|
os.unlink(appendfile)
|
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno != errno.ENOENT:
|
|
|
|
raise
|
2015-08-30 15:41:38 +00:00
|
|
|
|
2015-09-23 10:05:23 +00:00
|
|
|
tinfoil = setup_tinfoil(basepath=basepath)
|
2015-09-22 16:21:38 +00:00
|
|
|
try:
|
2015-08-05 14:48:00 +00:00
|
|
|
rd = parse_recipe(config, tinfoil, image, True)
|
|
|
|
if not rd:
|
|
|
|
# Error already shown
|
|
|
|
return (1, None)
|
|
|
|
if not bb.data.inherits_class('image', rd):
|
|
|
|
raise TargetNotImageError()
|
|
|
|
|
|
|
|
# Get the actual filename used and strip the .bb and full path
|
2016-12-14 21:13:05 +00:00
|
|
|
target_basename = rd.getVar('FILE')
|
2015-08-05 14:48:00 +00:00
|
|
|
target_basename = os.path.splitext(os.path.basename(target_basename))[0]
|
|
|
|
config.set('SDK', 'target_basename', target_basename)
|
|
|
|
config.write()
|
2015-09-22 16:21:36 +00:00
|
|
|
|
2015-08-05 14:48:00 +00:00
|
|
|
appendfile = os.path.join(config.workspace_path, 'appends',
|
|
|
|
'%s.bbappend' % target_basename)
|
2016-03-02 10:44:21 +00:00
|
|
|
|
2015-08-05 14:48:00 +00:00
|
|
|
outputdir = None
|
2015-09-22 16:21:38 +00:00
|
|
|
try:
|
2015-08-05 14:48:00 +00:00
|
|
|
if workspace or add_packages:
|
|
|
|
if add_packages:
|
|
|
|
packages = add_packages
|
|
|
|
else:
|
|
|
|
packages = _get_packages(tinfoil, workspace, config)
|
|
|
|
else:
|
|
|
|
packages = None
|
|
|
|
if not task:
|
|
|
|
if not packages and not add_packages and workspace:
|
|
|
|
logger.warning('No recipes in workspace, building image %s unmodified', image)
|
|
|
|
elif not packages:
|
|
|
|
logger.warning('No packages to add, building image %s unmodified', image)
|
|
|
|
|
|
|
|
if packages or extra_append:
|
|
|
|
bb.utils.mkdirhier(os.path.dirname(appendfile))
|
|
|
|
with open(appendfile, 'w') as afile:
|
|
|
|
if packages:
|
|
|
|
# include packages from workspace recipes into the image
|
|
|
|
afile.write('IMAGE_INSTALL_append = " %s"\n' % ' '.join(packages))
|
|
|
|
if not task:
|
|
|
|
logger.info('Building image %s with the following '
|
|
|
|
'additional packages: %s', image, ' '.join(packages))
|
|
|
|
if extra_append:
|
|
|
|
for line in extra_append:
|
|
|
|
afile.write('%s\n' % line)
|
|
|
|
|
|
|
|
if task in ['populate_sdk', 'populate_sdk_ext']:
|
2016-12-14 21:13:05 +00:00
|
|
|
outputdir = rd.getVar('SDK_DEPLOY')
|
2015-08-05 14:48:00 +00:00
|
|
|
else:
|
2016-12-14 21:13:05 +00:00
|
|
|
outputdir = rd.getVar('DEPLOY_DIR_IMAGE')
|
2015-08-05 14:48:00 +00:00
|
|
|
|
|
|
|
tmp_tinfoil = tinfoil
|
|
|
|
tinfoil = None
|
|
|
|
tmp_tinfoil.shutdown()
|
|
|
|
|
|
|
|
options = ''
|
|
|
|
if task:
|
|
|
|
options += '-c %s' % task
|
|
|
|
|
|
|
|
# run bitbake to build image (or specified task)
|
|
|
|
try:
|
|
|
|
exec_build_env_command(config.init_path, basepath,
|
|
|
|
'bitbake %s %s' % (options, image), watch=True)
|
|
|
|
except ExecutionError as err:
|
|
|
|
return (err.exitcode, None)
|
|
|
|
finally:
|
|
|
|
if os.path.isfile(appendfile):
|
|
|
|
os.unlink(appendfile)
|
2015-09-22 16:21:38 +00:00
|
|
|
finally:
|
2015-08-05 14:48:00 +00:00
|
|
|
if tinfoil:
|
|
|
|
tinfoil.shutdown()
|
2016-03-02 10:44:21 +00:00
|
|
|
return (0, outputdir)
|
2015-08-21 13:00:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def register_commands(subparsers, context):
|
|
|
|
"""Register devtool subcommands from the build-image plugin"""
|
2015-08-30 14:34:08 +00:00
|
|
|
parser = subparsers.add_parser('build-image',
|
|
|
|
help='Build image including workspace recipe packages',
|
|
|
|
description='Builds an image, extending it to include '
|
devtool: categorise and order subcommands in help output
The listing of subcommands in the --help output for devtool was starting
to get difficult to follow, with commands appearing in no particular
order (due to some being in separate modules and the order of those
modules being parsed). Logically grouping the subcommands as well as
being able to exercise some control over the order of the subcommands
and groups would help, if we do so without losing the dynamic nature of
the list (i.e. that it comes from the plugins). Argparse provides no
built-in way to handle this and really, really makes it a pain to add,
but with some subclassing and hacking it's now possible, and can be
extended by any plugin as desired.
To put a subcommand into a group, all you need to do is specify a group=
parameter in the call to subparsers.add_parser(). you can also specify
an order= parameter to make the subcommand sort higher or lower in the
list (higher order numbers appear first, so use negative numbers to
force items to the end if that's what you want). To add a new group, use
subparsers.add_subparser_group(), supplying the name, description and
optionally an order number for the group itself (again, higher numbers
appear first).
(From OE-Core rev: e1b9d31e6ea3c254ecfe940fe795af44761e0e69)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-02-19 09:38:53 +00:00
|
|
|
'packages from recipes in the workspace',
|
|
|
|
group='testbuild', order=-10)
|
2015-09-22 16:21:37 +00:00
|
|
|
parser.add_argument('imagename', help='Image recipe to build', nargs='?')
|
2016-01-26 02:53:55 +00:00
|
|
|
parser.add_argument('-p', '--add-packages', help='Instead of adding packages for the '
|
|
|
|
'entire workspace, specify packages to be added to the image '
|
|
|
|
'(separate multiple packages by commas)',
|
|
|
|
metavar='PACKAGES')
|
2015-08-30 14:34:08 +00:00
|
|
|
parser.set_defaults(func=build_image)
|