1# Development tool - package command plugin
2#
3# Copyright (C) 2014-2015 Intel Corporation
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7"""Devtool plugin containing the package subcommands"""
8
9import os
10import subprocess
11import logging
12from bb.process import ExecutionError
13from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
14
15logger = logging.getLogger('devtool')
16
17def package(args, config, basepath, workspace):
18    """Entry point for the devtool 'package' subcommand"""
19    check_workspace_recipe(workspace, args.recipename)
20
21    tinfoil = setup_tinfoil(basepath=basepath, config_only=True)
22    try:
23        image_pkgtype = config.get('Package', 'image_pkgtype', '')
24        if not image_pkgtype:
25            image_pkgtype = tinfoil.config_data.getVar('IMAGE_PKGTYPE')
26
27        deploy_dir_pkg = tinfoil.config_data.getVar('DEPLOY_DIR_%s' % image_pkgtype.upper())
28    finally:
29        tinfoil.shutdown()
30
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
37
38    logger.info('Your packages are in %s' % deploy_dir_pkg)
39
40    return 0
41
42def register_commands(subparsers, context):
43    """Register devtool subcommands from the package plugin"""
44    if context.fixed_setup:
45        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)
49        parser_package.add_argument('recipename', help='Recipe to package')
50        parser_package.set_defaults(func=package)
51