diff options
Diffstat (limited to 'scripts/lib/devtool')
-rw-r--r-- | scripts/lib/devtool/build_image.py | 79 | ||||
-rw-r--r-- | scripts/lib/devtool/build_sdk.py | 65 |
2 files changed, 122 insertions, 22 deletions
diff --git a/scripts/lib/devtool/build_image.py b/scripts/lib/devtool/build_image.py index ff764fa833..e51d766474 100644 --- a/scripts/lib/devtool/build_image.py +++ b/scripts/lib/devtool/build_image.py @@ -25,6 +25,9 @@ from devtool import exec_build_env_command, setup_tinfoil, parse_recipe, Devtool logger = logging.getLogger('devtool') +class TargetNotImageError(Exception): + pass + def _get_packages(tinfoil, workspace, config): """Get list of packages from recipes in the workspace.""" result = [] @@ -51,6 +54,24 @@ def build_image(args, config, basepath, workspace): if not image: raise DevtoolError('Unable to determine image to build, please specify one') + 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): appendfile = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % image) @@ -63,46 +84,60 @@ def build_image(args, config, basepath, workspace): rd = parse_recipe(config, tinfoil, image, True) if not rd: # Error already shown - return 1 + return (1, None) if not bb.data.inherits_class('image', rd): - 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) + raise TargetNotImageError() + outputdir = None try: - if workspace or args.add_packages: - if args.add_packages: - packages = args.add_packages.split(',') + if workspace or add_packages: + if add_packages: + packages = add_packages else: packages = _get_packages(tinfoil, workspace, config) - if packages: - with open(appendfile, 'w') as afile: + 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)) - logger.info('Building image %s with the following ' - 'additional packages: %s', image, ' '.join(packages)) - else: - logger.warning('No packages to add, building image %s unmodified', image) + 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']: + outputdir = rd.getVar('SDK_DEPLOY', True) else: - logger.warning('No recipes in workspace, building image %s unmodified', image) - - deploy_dir_image = tinfoil.config_data.getVar('DEPLOY_DIR_IMAGE', True) + outputdir = rd.getVar('DEPLOY_DIR_IMAGE', True) tinfoil.shutdown() - # run bitbake to build image + 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' % image, watch=True) + 'bitbake %s %s' % (options, image), watch=True) except ExecutionError as err: - return err.exitcode + return (err.exitcode, None) finally: if os.path.isfile(appendfile): os.unlink(appendfile) + return (0, outputdir) - logger.info('Successfully built %s. You can find output files in %s' - % (image, deploy_dir_image)) def register_commands(subparsers, context): """Register devtool subcommands from the build-image plugin""" diff --git a/scripts/lib/devtool/build_sdk.py b/scripts/lib/devtool/build_sdk.py new file mode 100644 index 0000000000..b89d65b0cb --- /dev/null +++ b/scripts/lib/devtool/build_sdk.py @@ -0,0 +1,65 @@ +# Development tool - build-sdk command plugin +# +# Copyright (C) 2015-2016 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. + +import os +import subprocess +import logging +import glob +import shutil +import errno +import sys +import tempfile +from devtool import exec_build_env_command, setup_tinfoil, parse_recipe, DevtoolError +from devtool import build_image + +logger = logging.getLogger('devtool') + + +def build_sdk(args, config, basepath, workspace): + """Entry point for the devtool build-sdk command""" + + sdk_targets = config.get('SDK', 'sdk_targets', '').split() + if sdk_targets: + image = sdk_targets[0] + else: + raise DevtoolError('Unable to determine image to build SDK for') + + extra_append = ['SDK_DERIVATIVE = "1"'] + try: + result, outputdir = build_image.build_image_task(config, + basepath, + workspace, + image, + task='populate_sdk_ext', + extra_append=extra_append) + except build_image.TargetNotImageError: + raise DevtoolError('Unable to determine image to build SDK for') + + if result == 0: + logger.info('Successfully built SDK. You can find output files in %s' + % outputdir) + return result + + +def register_commands(subparsers, context): + """Register devtool subcommands""" + if context.fixed_setup: + parser_build_sdk = subparsers.add_parser('build-sdk', + help='Build a derivative SDK of this one', + description='Builds an extensible SDK based upon this one and the items in your workspace', + group='advanced') + parser_build_sdk.set_defaults(func=build_sdk) |