summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/build_image.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/devtool/build_image.py')
-rw-r--r--scripts/lib/devtool/build_image.py140
1 files changed, 68 insertions, 72 deletions
diff --git a/scripts/lib/devtool/build_image.py b/scripts/lib/devtool/build_image.py
index 1e5d09b39e..980f90ddd6 100644
--- a/scripts/lib/devtool/build_image.py
+++ b/scripts/lib/devtool/build_image.py
@@ -2,18 +2,8 @@
#
# 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.
+# 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.
"""Devtool plugin containing the build-image subcommand."""
@@ -34,8 +24,8 @@ def _get_packages(tinfoil, workspace, config):
result = []
for recipe in workspace:
data = parse_recipe(config, tinfoil, recipe, True)
- if 'class-target' in data.getVar('OVERRIDES', True).split(':'):
- if recipe in data.getVar('PACKAGES', True):
+ if 'class-target' in data.getVar('OVERRIDES').split(':'):
+ if recipe in data.getVar('PACKAGES').split():
result.append(recipe)
else:
logger.warning("Skipping recipe %s as it doesn't produce a "
@@ -86,70 +76,76 @@ def build_image_task(config, basepath, workspace, image, add_packages=None, task
raise
tinfoil = setup_tinfoil(basepath=basepath)
- 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
- target_basename = rd.getVar('FILE', True)
- target_basename = os.path.splitext(os.path.basename(target_basename))[0]
- config.set('SDK', 'target_basename', target_basename)
- config.write()
-
- appendfile = os.path.join(config.workspace_path, 'appends',
- '%s.bbappend' % target_basename)
-
- outputdir = None
try:
- 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']:
- outputdir = rd.getVar('SDK_DEPLOY', True)
- else:
- outputdir = rd.getVar('DEPLOY_DIR_IMAGE', True)
-
- tinfoil.shutdown()
+ 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
+ target_basename = rd.getVar('FILE')
+ target_basename = os.path.splitext(os.path.basename(target_basename))[0]
+ config.set('SDK', 'target_basename', target_basename)
+ config.write()
- options = ''
- if task:
- options += '-c %s' % task
+ appendfile = os.path.join(config.workspace_path, 'appends',
+ '%s.bbappend' % target_basename)
- # run bitbake to build image (or specified task)
+ outputdir = None
try:
- exec_build_env_command(config.init_path, basepath,
- 'bitbake %s %s' % (options, image), watch=True)
- except ExecutionError as err:
- return (err.exitcode, None)
+ 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']:
+ outputdir = rd.getVar('SDK_DEPLOY')
+ else:
+ outputdir = rd.getVar('DEPLOY_DIR_IMAGE')
+
+ 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)
finally:
- if os.path.isfile(appendfile):
- os.unlink(appendfile)
+ if tinfoil:
+ tinfoil.shutdown()
return (0, outputdir)