| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | import os | 
 | 34 | import sys | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 35 | import argparse | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | import logging | 
 | 37 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | 
 | 39 | sys.path.insert(0, scripts_path + '/lib') | 
 | 40 | import argparse_oe | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 |  | 
 | 42 | from bsp.help import * | 
 | 43 | from bsp.engine import * | 
 | 44 |  | 
 | 45 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | def do_create_bsp(args): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 |     """ | 
 | 48 |     Command-line handling for BSP creation.  The real work is done by | 
 | 49 |     bsp.engine.yocto_bsp_create() | 
 | 50 |     """ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 |     if args.outdir: | 
 | 52 |         bsp_output_dir = args.outdir | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 |     else: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 |         bsp_output_dir = "meta-" + args.bspname | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 56 |     if args.git_check and not args.properties_file: | 
 | 57 |         print("Checking basic git connectivity...") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 |         if not verify_git_repo(GIT_CHECK_URI): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 |             print("Couldn't verify git connectivity, exiting\n") | 
 | 60 |             print("Details: couldn't access %s" % GIT_CHECK_URI) | 
 | 61 |             print("         (this most likely indicates a network connectivity problem or") | 
 | 62 |             print("         a misconfigured git intallation)") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 |             sys.exit(1) | 
 | 64 |         else: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 65 |             print("Done.\n") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 67 |     yocto_bsp_create(args.bspname, args.karch, scripts_path, bsp_output_dir, args.codedump, args.properties_file) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 |  | 
 | 69 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | def do_list_bsp(args): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 |     """ | 
 | 72 |     Command-line handling for listing available BSP properties and | 
 | 73 |     values.  The real work is done by bsp.engine.yocto_bsp_list() | 
 | 74 |     """ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 |     yocto_bsp_list(args, scripts_path) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | def do_help_bsp(args): | 
 | 78 |     """ | 
 | 79 |     Command-line help tool | 
 | 80 |     """ | 
 | 81 |     help_text = command_help.get(args.subcommand) | 
 | 82 |     pager = subprocess.Popen('less', stdin=subprocess.PIPE) | 
 | 83 |     pager.communicate(bytes(help_text,'UTF-8')) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 85 | command_help = { | 
 | 86 |     "create": yocto_bsp_create_help, | 
 | 87 |     "list":  yocto_bsp_list_help | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | } | 
 | 89 |  | 
 | 90 |  | 
 | 91 | def start_logging(loglevel): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 92 |     logging.basicConfig(filename = 'yocto-bsp.log', filemode = 'w', level=loglevel) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 93 |  | 
 | 94 |  | 
 | 95 | def main(): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 96 |     parser = argparse_oe.ArgumentParser(description='Create a customized Yocto BSP layer.', | 
 | 97 |                       epilog="See '%(prog)s help <subcommand>' for more information on a specific command.") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 99 |     parser.add_argument("-D", "--debug", action = "store_true", | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 |                       default = False, help = "output debug information") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 101 |     subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>') | 
 | 102 |     subparsers.required = True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 104 |     create_parser = subparsers.add_parser('create', help='Create a new Yocto BSP', | 
 | 105 |                                           description='Create a new Yocto BSP') | 
 | 106 |     create_parser.add_argument('bspname', metavar='bsp-name', help='name for the new BSP') | 
 | 107 |     create_parser.add_argument('karch', help='kernel architecture') | 
 | 108 |     create_parser.add_argument("-o", "--outdir", help = "name of BSP dir to create") | 
 | 109 |     create_parser.add_argument("-i", "--infile", dest = "properties_file", | 
 | 110 |                       help = "name of file containing the values for BSP properties as a JSON file") | 
 | 111 |     create_parser.add_argument("-c", "--codedump", action = "store_true", default = False, | 
 | 112 |                       help = "dump the generated code to bspgen.out") | 
 | 113 |     create_parser.add_argument("-s", "--skip-git-check", dest = "git_check", action = "store_false", | 
 | 114 |                       default = True, help = "skip the git connectivity check") | 
 | 115 |     create_parser.set_defaults(func=do_create_bsp) | 
 | 116 |  | 
 | 117 |  | 
 | 118 |     list_parser = subparsers.add_parser('list', help='List available values for options and BSP properties') | 
 | 119 |     list_parser.add_argument('karch', help='kernel architecture') | 
 | 120 |     prop_group = list_parser.add_mutually_exclusive_group() | 
 | 121 |     prop_group.add_argument("--properties", action = "store_true", default = False, | 
 | 122 |                       help = "list all properties for the kernel architecture") | 
 | 123 |     prop_group.add_argument("--property", help = "list available values for the property") | 
 | 124 |     list_parser.add_argument("-o", "--outfile", dest = "properties_file", | 
 | 125 |                       help = "dump the possible values for BSP properties to a JSON file") | 
 | 126 |  | 
 | 127 |     list_parser.set_defaults(func=do_list_bsp) | 
 | 128 |  | 
 | 129 |     help_parser = subparsers.add_parser('help', | 
 | 130 |                       description='This command displays detailed help for the specified subcommand.') | 
 | 131 |     help_parser.add_argument('subcommand', nargs='?') | 
 | 132 |     help_parser.set_defaults(func=do_help_bsp) | 
 | 133 |  | 
 | 134 |     args = parser.parse_args() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 |  | 
 | 136 |     loglevel = logging.INFO | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 137 |     if args.debug: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 |         loglevel = logging.DEBUG | 
 | 139 |     start_logging(loglevel) | 
 | 140 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 141 |     if args._subparser_name == "list": | 
 | 142 |         if not args.karch == "karch" and not args.properties and not args.property: | 
 | 143 |             print ("yocto-bsp list: error: one of the arguments --properties --property is required") | 
 | 144 |             list_parser.print_help() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 |     if args._subparser_name == "help": | 
 | 147 |         if not args.subcommand: | 
 | 148 |             parser.print_help() | 
 | 149 |             return 0 | 
 | 150 |         elif not command_help.get(args.subcommand): | 
 | 151 |             print ("yocto-bsp help: No manual entry for %s" % args.subcommand) | 
 | 152 |             return 1 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 154 |     return args.func(args) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 |  | 
 | 156 | if __name__ == "__main__": | 
 | 157 |     try: | 
 | 158 |         ret = main() | 
 | 159 |     except Exception: | 
 | 160 |         ret = 1 | 
 | 161 |         import traceback | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 162 |         traceback.print_exc() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 |     sys.exit(ret) |