package.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Development tool - package command plugin
  2. #
  3. # Copyright (C) 2014-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. """Devtool plugin containing the package subcommands"""
  18. import os
  19. import subprocess
  20. import logging
  21. from bb.process import ExecutionError
  22. from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
  23. logger = logging.getLogger('devtool')
  24. def package(args, config, basepath, workspace):
  25. """Entry point for the devtool 'package' subcommand"""
  26. check_workspace_recipe(workspace, args.recipename)
  27. tinfoil = setup_tinfoil(basepath=basepath, config_only=True)
  28. try:
  29. image_pkgtype = config.get('Package', 'image_pkgtype', '')
  30. if not image_pkgtype:
  31. image_pkgtype = tinfoil.config_data.getVar('IMAGE_PKGTYPE')
  32. deploy_dir_pkg = tinfoil.config_data.getVar('DEPLOY_DIR_%s' % image_pkgtype.upper())
  33. finally:
  34. tinfoil.shutdown()
  35. package_task = config.get('Package', 'package_task', 'package_write_%s' % image_pkgtype)
  36. try:
  37. exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (package_task, args.recipename), watch=True)
  38. except bb.process.ExecutionError as e:
  39. # We've already seen the output since watch=True, so just ensure we return something to the user
  40. return e.exitcode
  41. logger.info('Your packages are in %s' % deploy_dir_pkg)
  42. return 0
  43. def register_commands(subparsers, context):
  44. """Register devtool subcommands from the package plugin"""
  45. if context.fixed_setup:
  46. parser_package = subparsers.add_parser('package',
  47. help='Build packages for a recipe',
  48. description='Builds packages for a recipe\'s output files',
  49. group='testbuild', order=-5)
  50. parser_package.add_argument('recipename', help='Recipe to package')
  51. parser_package.set_defaults(func=package)