recipetool 3.9 KB

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