recipetool 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 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.prepare(not parserecipes)
  35. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  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. if global_args.debug:
  54. logger.setLevel(logging.DEBUG)
  55. elif global_args.quiet:
  56. logger.setLevel(logging.ERROR)
  57. import scriptpath
  58. bitbakepath = scriptpath.add_bitbake_lib_path()
  59. if not bitbakepath:
  60. logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
  61. sys.exit(1)
  62. logger.debug('Found bitbake path: %s' % bitbakepath)
  63. scriptutils.logger_setup_color(logger, global_args.color)
  64. tinfoil = tinfoil_init(False)
  65. for path in ([scripts_path] +
  66. tinfoil.config_data.getVar('BBPATH', True).split(':')):
  67. pluginpath = os.path.join(path, 'lib', 'recipetool')
  68. scriptutils.load_plugins(logger, plugins, pluginpath)
  69. registered = False
  70. for plugin in plugins:
  71. if hasattr(plugin, 'register_commands'):
  72. registered = True
  73. plugin.register_commands(subparsers)
  74. elif hasattr(plugin, 'register_command'):
  75. # Legacy function name
  76. registered = True
  77. plugin.register_command(subparsers)
  78. if hasattr(plugin, 'tinfoil_init'):
  79. plugin.tinfoil_init(tinfoil)
  80. if not registered:
  81. logger.error("No commands registered - missing plugins?")
  82. sys.exit(1)
  83. args = parser.parse_args(unparsed_args, namespace=global_args)
  84. try:
  85. if getattr(args, 'parserecipes', False):
  86. tinfoil.config_data.disableTracking()
  87. tinfoil.parseRecipes()
  88. tinfoil.config_data.enableTracking()
  89. ret = args.func(args)
  90. except bb.BBHandledException:
  91. ret = 1
  92. return ret
  93. if __name__ == "__main__":
  94. try:
  95. ret = main()
  96. except Exception:
  97. ret = 1
  98. import traceback
  99. traceback.print_exc()
  100. sys.exit(ret)