diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-03-02 23:44:20 +1300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-03-07 00:11:37 +0000 |
| commit | 41eb36dc4ce7feece2f63c7cae80478f5376459e (patch) | |
| tree | a1f9cd6e0ac24e69ae4d9e72bb495c77bd4719f3 /scripts/lib/devtool/build_image.py | |
| parent | 82d0c8ad1e6310888084409afe645239d8316b5b (diff) | |
| download | poky-41eb36dc4ce7feece2f63c7cae80478f5376459e.tar.gz | |
devtool: build-image: rename module
Hyphens aren't allowed in python identifiers, so you shouldn't use them
in module names or they are more difficult to import.
(From OE-Core rev: e8f6db9436dfc923e236f2cbc08f357e3b24fd5d)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool/build_image.py')
| -rw-r--r-- | scripts/lib/devtool/build_image.py | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/scripts/lib/devtool/build_image.py b/scripts/lib/devtool/build_image.py new file mode 100644 index 0000000000..ff764fa833 --- /dev/null +++ b/scripts/lib/devtool/build_image.py | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | # Development tool - build-image plugin | ||
| 2 | # | ||
| 3 | # Copyright (C) 2015 Intel Corporation | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify | ||
| 6 | # it under the terms of the GNU General Public License version 2 as | ||
| 7 | # published by the Free Software Foundation. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | |||
| 18 | """Devtool plugin containing the build-image subcommand.""" | ||
| 19 | |||
| 20 | import os | ||
| 21 | import logging | ||
| 22 | |||
| 23 | from bb.process import ExecutionError | ||
| 24 | from devtool import exec_build_env_command, setup_tinfoil, parse_recipe, DevtoolError | ||
| 25 | |||
| 26 | logger = logging.getLogger('devtool') | ||
| 27 | |||
| 28 | def _get_packages(tinfoil, workspace, config): | ||
| 29 | """Get list of packages from recipes in the workspace.""" | ||
| 30 | result = [] | ||
| 31 | for recipe in workspace: | ||
| 32 | data = parse_recipe(config, tinfoil, recipe, True) | ||
| 33 | if 'class-target' in data.getVar('OVERRIDES', True).split(':'): | ||
| 34 | if recipe in data.getVar('PACKAGES', True): | ||
| 35 | result.append(recipe) | ||
| 36 | else: | ||
| 37 | logger.warning("Skipping recipe %s as it doesn't produce a " | ||
| 38 | "package with the same name", recipe) | ||
| 39 | return result | ||
| 40 | |||
| 41 | def build_image(args, config, basepath, workspace): | ||
| 42 | """Entry point for the devtool 'build-image' subcommand.""" | ||
| 43 | |||
| 44 | image = args.imagename | ||
| 45 | auto_image = False | ||
| 46 | if not image: | ||
| 47 | sdk_targets = config.get('SDK', 'sdk_targets', '').split() | ||
| 48 | if sdk_targets: | ||
| 49 | image = sdk_targets[0] | ||
| 50 | auto_image = True | ||
| 51 | if not image: | ||
| 52 | raise DevtoolError('Unable to determine image to build, please specify one') | ||
| 53 | |||
| 54 | appendfile = os.path.join(config.workspace_path, 'appends', | ||
| 55 | '%s.bbappend' % image) | ||
| 56 | |||
| 57 | # remove <image>.bbappend to make sure setup_tinfoil doesn't | ||
| 58 | # break because of it | ||
| 59 | if os.path.isfile(appendfile): | ||
| 60 | os.unlink(appendfile) | ||
| 61 | |||
| 62 | tinfoil = setup_tinfoil(basepath=basepath) | ||
| 63 | rd = parse_recipe(config, tinfoil, image, True) | ||
| 64 | if not rd: | ||
| 65 | # Error already shown | ||
| 66 | return 1 | ||
| 67 | if not bb.data.inherits_class('image', rd): | ||
| 68 | if auto_image: | ||
| 69 | raise DevtoolError('Unable to determine image to build, please specify one') | ||
| 70 | else: | ||
| 71 | raise DevtoolError('Specified recipe %s is not an image recipe' % image) | ||
| 72 | |||
| 73 | try: | ||
| 74 | if workspace or args.add_packages: | ||
| 75 | if args.add_packages: | ||
| 76 | packages = args.add_packages.split(',') | ||
| 77 | else: | ||
| 78 | packages = _get_packages(tinfoil, workspace, config) | ||
| 79 | if packages: | ||
| 80 | with open(appendfile, 'w') as afile: | ||
| 81 | # include packages from workspace recipes into the image | ||
| 82 | afile.write('IMAGE_INSTALL_append = " %s"\n' % ' '.join(packages)) | ||
| 83 | logger.info('Building image %s with the following ' | ||
| 84 | 'additional packages: %s', image, ' '.join(packages)) | ||
| 85 | else: | ||
| 86 | logger.warning('No packages to add, building image %s unmodified', image) | ||
| 87 | else: | ||
| 88 | logger.warning('No recipes in workspace, building image %s unmodified', image) | ||
| 89 | |||
| 90 | deploy_dir_image = tinfoil.config_data.getVar('DEPLOY_DIR_IMAGE', True) | ||
| 91 | |||
| 92 | tinfoil.shutdown() | ||
| 93 | |||
| 94 | # run bitbake to build image | ||
| 95 | try: | ||
| 96 | exec_build_env_command(config.init_path, basepath, | ||
| 97 | 'bitbake %s' % image, watch=True) | ||
| 98 | except ExecutionError as err: | ||
| 99 | return err.exitcode | ||
| 100 | finally: | ||
| 101 | if os.path.isfile(appendfile): | ||
| 102 | os.unlink(appendfile) | ||
| 103 | |||
| 104 | logger.info('Successfully built %s. You can find output files in %s' | ||
| 105 | % (image, deploy_dir_image)) | ||
| 106 | |||
| 107 | def register_commands(subparsers, context): | ||
| 108 | """Register devtool subcommands from the build-image plugin""" | ||
| 109 | parser = subparsers.add_parser('build-image', | ||
| 110 | help='Build image including workspace recipe packages', | ||
| 111 | description='Builds an image, extending it to include ' | ||
| 112 | 'packages from recipes in the workspace', | ||
| 113 | group='testbuild', order=-10) | ||
| 114 | parser.add_argument('imagename', help='Image recipe to build', nargs='?') | ||
| 115 | parser.add_argument('-p', '--add-packages', help='Instead of adding packages for the ' | ||
| 116 | 'entire workspace, specify packages to be added to the image ' | ||
| 117 | '(separate multiple packages by commas)', | ||
| 118 | metavar='PACKAGES') | ||
| 119 | parser.set_defaults(func=build_image) | ||
