blob: 2c014289feb7042394f5aad3cc294af8464d1b91 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
20import os
21import logging
22
23from bb.process import ExecutionError
24from devtool import exec_build_env_command, setup_tinfoil, parse_recipe
25
26logger = logging.getLogger('devtool')
27
28def _get_recipes(workspace, config):
29 """Get list of target recipes from the workspace."""
30 result = []
31 tinfoil = setup_tinfoil()
32 for recipe in workspace:
33 data = parse_recipe(config, tinfoil, recipe, True)
34 if 'class-target' in data.getVar('OVERRIDES', True).split(':'):
35 if recipe in data.getVar('PACKAGES', True):
36 result.append(recipe)
37 else:
38 logger.warning("Skipping recipe %s as it doesn't produce "
39 "package with the same name", recipe)
40 tinfoil.shutdown()
41 return result
42
43def build_image(args, config, basepath, workspace):
44 """Entry point for the devtool 'build-image' subcommand."""
45 image = args.recipe
46 appendfile = os.path.join(config.workspace_path, 'appends',
47 '%s.bbappend' % image)
48
49 # remove <image>.bbapend to make sure setup_tinfoil doesn't
50 # breake because of it
51 if os.path.isfile(appendfile):
52 os.unlink(appendfile)
53
54 recipes = _get_recipes(workspace, config)
55 if recipes:
56 with open(appendfile, 'w') as afile:
57 # include selected recipes into the image
58 afile.write('IMAGE_INSTALL_append = " %s"\n' % ' '.join(recipes))
59
60 # Generate notification callback devtool_warn_image_extended
61 afile.write('do_rootfs[prefuncs] += "devtool_warn_image_extended"\n\n')
62 afile.write("python devtool_warn_image_extended() {\n")
63 afile.write(" bb.plain('NOTE: %%s: building with additional '\n"
64 " 'packages due to \"devtool build-image\"'"
65 " %% d.getVar('PN', True))\n"
66 " bb.plain('NOTE: delete %%s to clear this' %% \\\n"
67 " '%s')\n" % os.path.relpath(appendfile, basepath))
68 afile.write("}\n")
69
70 logger.info('Building image %s with the following '
71 'additional packages: %s', image, ' '.join(recipes))
72 else:
73 logger.warning('No recipes in workspace, building image %s unmodified', image)
74
75 # run bitbake to build image
76 try:
77 exec_build_env_command(config.init_path, basepath,
78 'bitbake %s' % image, watch=True)
79 except ExecutionError as err:
80 return err.exitcode
81
82 logger.info('Successfully built %s', image)
83
84def register_commands(subparsers, context):
85 """Register devtool subcommands from the build-image plugin"""
86 parser = subparsers.add_parser('build-image',
87 help='Build image including workspace recipe packages',
88 description='Builds an image, extending it to include '
89 'packages from recipes in the workspace')
90 parser.add_argument('recipe', help='Image recipe to build')
91 parser.set_defaults(func=build_image)