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