bitbake-layers 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. # This script has subcommands which operate against your bitbake layers, either
  3. # displaying useful information, or acting against them.
  4. # See the help output for details on available commands.
  5. # Copyright (C) 2011 Mentor Graphics Corporation
  6. # Copyright (C) 2011-2015 Intel Corporation
  7. #
  8. # SPDX-License-Identifier: GPL-2.0-only
  9. #
  10. import logging
  11. import os
  12. import sys
  13. import argparse
  14. import warnings
  15. warnings.simplefilter("default")
  16. bindir = os.path.dirname(__file__)
  17. toolname = os.path.basename(__file__).split(".")[0]
  18. topdir = os.path.dirname(bindir)
  19. sys.path[0:0] = [os.path.join(topdir, 'lib')]
  20. import bb.tinfoil
  21. import bb.msg
  22. logger = bb.msg.logger_create(toolname, sys.stdout)
  23. def main():
  24. parser = argparse.ArgumentParser(
  25. description="BitBake layers utility",
  26. epilog="Use %(prog)s <subcommand> --help to get help on a specific command",
  27. add_help=False)
  28. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  29. parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
  30. parser.add_argument('-F', '--force', help='Forced execution: can be specified multiple times. -F will force add without recipe parse verification and -FF will additionally force the run withput layer parsing.', action='count', default=0)
  31. parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR')
  32. global_args, unparsed_args = parser.parse_known_args()
  33. # Help is added here rather than via add_help=True, as we don't want it to
  34. # be handled by parse_known_args()
  35. parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
  36. help='show this help message and exit')
  37. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  38. subparsers.required = True
  39. if global_args.debug:
  40. logger.setLevel(logging.DEBUG)
  41. elif global_args.quiet:
  42. logger.setLevel(logging.ERROR)
  43. # Need to re-run logger_create with color argument
  44. # (will be the same logger since it has the same name)
  45. bb.msg.logger_create('bitbake-layers', output=sys.stdout,
  46. color=global_args.color,
  47. level=logger.getEffectiveLevel())
  48. plugins = []
  49. with bb.tinfoil.Tinfoil(tracking=True) as tinfoil:
  50. tinfoil.logger.setLevel(logger.getEffectiveLevel())
  51. if global_args.force > 1:
  52. bbpaths = []
  53. else:
  54. tinfoil.prepare(True)
  55. bbpaths = tinfoil.config_data.getVar('BBPATH').split(':')
  56. for path in ([topdir] + bbpaths):
  57. pluginbasepath = {"bitbake-layers":'bblayers', 'bitbake-config-build':'bbconfigbuild'}[toolname]
  58. pluginpath = os.path.join(path, 'lib', pluginbasepath)
  59. bb.utils.load_plugins(logger, plugins, pluginpath)
  60. registered = False
  61. for plugin in plugins:
  62. if hasattr(plugin, 'tinfoil_init') and global_args.force <= 1:
  63. plugin.tinfoil_init(tinfoil)
  64. if hasattr(plugin, 'register_commands'):
  65. registered = True
  66. plugin.register_commands(subparsers)
  67. if not registered:
  68. logger.error("No commands registered - missing plugins?")
  69. sys.exit(1)
  70. args = parser.parse_args(unparsed_args, namespace=global_args)
  71. if getattr(args, 'parserecipes', False):
  72. tinfoil.config_data.disableTracking()
  73. tinfoil.parse_recipes()
  74. tinfoil.config_data.enableTracking()
  75. return args.func(args)
  76. if __name__ == "__main__":
  77. try:
  78. ret = main()
  79. except bb.BBHandledException:
  80. ret = 1
  81. except Exception:
  82. ret = 1
  83. import traceback
  84. traceback.print_exc()
  85. sys.exit(ret)