yocto-bsp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/env python3
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. #
  5. # Copyright (c) 2012, Intel Corporation.
  6. # All rights reserved.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. # DESCRIPTION
  22. # 'yocto-bsp' is the Yocto BSP Tool that helps users create a new
  23. # Yocto BSP. Invoking it without any arguments will display help
  24. # screens for the 'yocto-bsp' command and list the available
  25. # 'yocto-bsp' subcommands. Invoking a subcommand without any
  26. # arguments will likewise display help screens for the specified
  27. # subcommand. Please use that interface for detailed help.
  28. #
  29. # AUTHORS
  30. # Tom Zanussi <tom.zanussi (at] intel.com>
  31. #
  32. import os
  33. import sys
  34. import argparse
  35. import logging
  36. scripts_path = os.path.dirname(os.path.realpath(__file__))
  37. sys.path.insert(0, scripts_path + '/lib')
  38. import argparse_oe
  39. from bsp.help import *
  40. from bsp.engine import *
  41. def do_create_bsp(args):
  42. """
  43. Command-line handling for BSP creation. The real work is done by
  44. bsp.engine.yocto_bsp_create()
  45. """
  46. if args.outdir:
  47. bsp_output_dir = args.outdir
  48. else:
  49. bsp_output_dir = "meta-" + args.bspname
  50. if args.git_check and not args.properties_file:
  51. print("Checking basic git connectivity...")
  52. if not verify_git_repo(GIT_CHECK_URI):
  53. print("Couldn't verify git connectivity, exiting\n")
  54. print("Details: couldn't access %s" % GIT_CHECK_URI)
  55. print(" (this most likely indicates a network connectivity problem or")
  56. print(" a misconfigured git intallation)")
  57. sys.exit(1)
  58. else:
  59. print("Done.\n")
  60. yocto_bsp_create(args.bspname, args.karch, scripts_path, bsp_output_dir, args.codedump, args.properties_file)
  61. def do_list_bsp(args):
  62. """
  63. Command-line handling for listing available BSP properties and
  64. values. The real work is done by bsp.engine.yocto_bsp_list()
  65. """
  66. yocto_bsp_list(args, scripts_path)
  67. def do_help_bsp(args):
  68. """
  69. Command-line help tool
  70. """
  71. help_text = command_help.get(args.subcommand)
  72. pager = subprocess.Popen('less', stdin=subprocess.PIPE)
  73. pager.communicate(bytes(help_text,'UTF-8'))
  74. command_help = {
  75. "create": yocto_bsp_create_help,
  76. "list": yocto_bsp_list_help
  77. }
  78. def start_logging(loglevel):
  79. logging.basicConfig(filename = 'yocto-bsp.log', filemode = 'w', level=loglevel)
  80. def main():
  81. parser = argparse_oe.ArgumentParser(description='Create a customized Yocto BSP layer.',
  82. epilog="See '%(prog)s help <subcommand>' for more information on a specific command.")
  83. parser.add_argument("-D", "--debug", action = "store_true",
  84. default = False, help = "output debug information")
  85. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  86. subparsers.required = True
  87. create_parser = subparsers.add_parser('create', help='Create a new Yocto BSP',
  88. description='Create a new Yocto BSP')
  89. create_parser.add_argument('bspname', metavar='bsp-name', help='name for the new BSP')
  90. create_parser.add_argument('karch', help='kernel architecture')
  91. create_parser.add_argument("-o", "--outdir", help = "name of BSP dir to create")
  92. create_parser.add_argument("-i", "--infile", dest = "properties_file",
  93. help = "name of file containing the values for BSP properties as a JSON file")
  94. create_parser.add_argument("-c", "--codedump", action = "store_true", default = False,
  95. help = "dump the generated code to bspgen.out")
  96. create_parser.add_argument("-s", "--skip-git-check", dest = "git_check", action = "store_false",
  97. default = True, help = "skip the git connectivity check")
  98. create_parser.set_defaults(func=do_create_bsp)
  99. list_parser = subparsers.add_parser('list', help='List available values for options and BSP properties')
  100. list_parser.add_argument('karch', help='kernel architecture')
  101. prop_group = list_parser.add_mutually_exclusive_group()
  102. prop_group.add_argument("--properties", action = "store_true", default = False,
  103. help = "list all properties for the kernel architecture")
  104. prop_group.add_argument("--property", help = "list available values for the property")
  105. list_parser.add_argument("-o", "--outfile", dest = "properties_file",
  106. help = "dump the possible values for BSP properties to a JSON file")
  107. list_parser.set_defaults(func=do_list_bsp)
  108. help_parser = subparsers.add_parser('help',
  109. description='This command displays detailed help for the specified subcommand.')
  110. help_parser.add_argument('subcommand', nargs='?')
  111. help_parser.set_defaults(func=do_help_bsp)
  112. args = parser.parse_args()
  113. loglevel = logging.INFO
  114. if args.debug:
  115. loglevel = logging.DEBUG
  116. start_logging(loglevel)
  117. if args._subparser_name == "list":
  118. if not args.karch == "karch" and not args.properties and not args.property:
  119. print ("yocto-bsp list: error: one of the arguments --properties --property is required")
  120. list_parser.print_help()
  121. if args._subparser_name == "help":
  122. if not args.subcommand:
  123. parser.print_help()
  124. return 0
  125. elif not command_help.get(args.subcommand):
  126. print ("yocto-bsp help: No manual entry for %s" % args.subcommand)
  127. return 1
  128. return args.func(args)
  129. if __name__ == "__main__":
  130. try:
  131. ret = main()
  132. except Exception:
  133. ret = 1
  134. import traceback
  135. traceback.print_exc()
  136. sys.exit(ret)