recipetool 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. # Recipe creation tool
  3. #
  4. # Copyright (C) 2014 Intel Corporation
  5. #
  6. # SPDX-License-Identifier: GPL-2.0-only
  7. #
  8. import sys
  9. import os
  10. import argparse
  11. import glob
  12. import logging
  13. scripts_path = os.path.dirname(os.path.realpath(__file__))
  14. lib_path = scripts_path + '/lib'
  15. sys.path = sys.path + [lib_path]
  16. import scriptutils
  17. import argparse_oe
  18. logger = scriptutils.logger_create('recipetool')
  19. plugins = []
  20. def tinfoil_init(parserecipes):
  21. import bb.tinfoil
  22. import logging
  23. tinfoil = bb.tinfoil.Tinfoil(tracking=True)
  24. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  25. tinfoil.prepare(not parserecipes)
  26. return tinfoil
  27. def main():
  28. if not os.environ.get('BUILDDIR', ''):
  29. logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
  30. sys.exit(1)
  31. parser = argparse_oe.ArgumentParser(description="OpenEmbedded recipe tool",
  32. add_help=False,
  33. epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
  34. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  35. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  36. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  37. global_args, unparsed_args = parser.parse_known_args()
  38. # Help is added here rather than via add_help=True, as we don't want it to
  39. # be handled by parse_known_args()
  40. parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
  41. help='show this help message and exit')
  42. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  43. subparsers.required = True
  44. if global_args.debug:
  45. logger.setLevel(logging.DEBUG)
  46. elif global_args.quiet:
  47. logger.setLevel(logging.ERROR)
  48. import scriptpath
  49. bitbakepath = scriptpath.add_bitbake_lib_path()
  50. if not bitbakepath:
  51. logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
  52. sys.exit(1)
  53. logger.debug('Found bitbake path: %s' % bitbakepath)
  54. scriptpath.add_oe_lib_path()
  55. scriptutils.logger_setup_color(logger, global_args.color)
  56. tinfoil = tinfoil_init(False)
  57. try:
  58. for path in (tinfoil.config_data.getVar('BBPATH').split(':')
  59. + [scripts_path]):
  60. pluginpath = os.path.join(path, 'lib', 'recipetool')
  61. scriptutils.load_plugins(logger, plugins, pluginpath)
  62. registered = False
  63. for plugin in plugins:
  64. if hasattr(plugin, 'register_commands'):
  65. registered = True
  66. plugin.register_commands(subparsers)
  67. elif hasattr(plugin, 'register_command'):
  68. # Legacy function name
  69. registered = True
  70. plugin.register_command(subparsers)
  71. if hasattr(plugin, 'tinfoil_init'):
  72. plugin.tinfoil_init(tinfoil)
  73. if not registered:
  74. logger.error("No commands registered - missing plugins?")
  75. sys.exit(1)
  76. args = parser.parse_args(unparsed_args, namespace=global_args)
  77. try:
  78. if getattr(args, 'parserecipes', False):
  79. tinfoil.config_data.disableTracking()
  80. tinfoil.parseRecipes()
  81. tinfoil.config_data.enableTracking()
  82. ret = args.func(args)
  83. except bb.BBHandledException:
  84. ret = 1
  85. finally:
  86. tinfoil.shutdown()
  87. return ret
  88. if __name__ == "__main__":
  89. try:
  90. ret = main()
  91. except Exception:
  92. ret = 1
  93. import traceback
  94. traceback.print_exc()
  95. sys.exit(ret)