recipetool 4.4 KB

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