blob: c2367342c3a8eba8bc2e3721dd9ac9164db50dba [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Development tool - package command plugin
2#
3# Copyright (C) 2014-2015 Intel Corporation
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007"""Devtool plugin containing the package subcommands"""
8
9import os
10import subprocess
11import logging
12from bb.process import ExecutionError
Patrick Williamsf1e5d692016-03-30 15:21:19 -050013from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
15logger = logging.getLogger('devtool')
16
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017def package(args, config, basepath, workspace):
18 """Entry point for the devtool 'package' subcommand"""
Patrick Williamsf1e5d692016-03-30 15:21:19 -050019 check_workspace_recipe(workspace, args.recipename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021 tinfoil = setup_tinfoil(basepath=basepath, config_only=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050023 image_pkgtype = config.get('Package', 'image_pkgtype', '')
24 if not image_pkgtype:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 image_pkgtype = tinfoil.config_data.getVar('IMAGE_PKGTYPE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 deploy_dir_pkg = tinfoil.config_data.getVar('DEPLOY_DIR_%s' % image_pkgtype.upper())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028 finally:
29 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
31 package_task = config.get('Package', 'package_task', 'package_write_%s' % image_pkgtype)
32 try:
33 exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (package_task, args.recipename), watch=True)
34 except bb.process.ExecutionError as e:
35 # We've already seen the output since watch=True, so just ensure we return something to the user
36 return e.exitcode
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037
38 logger.info('Your packages are in %s' % deploy_dir_pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40 return 0
41
42def register_commands(subparsers, context):
43 """Register devtool subcommands from the package plugin"""
44 if context.fixed_setup:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 parser_package = subparsers.add_parser('package',
46 help='Build packages for a recipe',
47 description='Builds packages for a recipe\'s output files',
48 group='testbuild', order=-5)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 parser_package.add_argument('recipename', help='Recipe to package')
50 parser_package.set_defaults(func=package)