blob: 6fb1f419cc92f533073175416675c6d4226681f4 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002# 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 Williamsc124f4f2015-09-15 14:41:29 -050033import os
34import sys
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035import argparse
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036import logging
37
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038scripts_path = os.path.dirname(os.path.realpath(__file__))
39sys.path.insert(0, scripts_path + '/lib')
40import argparse_oe
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041
42from bsp.help import *
43from bsp.engine import *
44
45
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046def do_create_bsp(args):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 """
48 Command-line handling for BSP creation. The real work is done by
49 bsp.engine.yocto_bsp_create()
50 """
Patrick Williamsc0f7c042017-02-23 20:41:17 -060051 if args.outdir:
52 bsp_output_dir = args.outdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054 bsp_output_dir = "meta-" + args.bspname
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056 if args.git_check and not args.properties_file:
57 print("Checking basic git connectivity...")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 if not verify_git_repo(GIT_CHECK_URI):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 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 Williamsc124f4f2015-09-15 14:41:29 -050063 sys.exit(1)
64 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060065 print("Done.\n")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
Patrick Williamsc0f7c042017-02-23 20:41:17 -060067 yocto_bsp_create(args.bspname, args.karch, scripts_path, bsp_output_dir, args.codedump, args.properties_file)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
69
Patrick Williamsc0f7c042017-02-23 20:41:17 -060070def do_list_bsp(args):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071 """
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 Williamsc0f7c042017-02-23 20:41:17 -060075 yocto_bsp_list(args, scripts_path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077def 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 Williamsc124f4f2015-09-15 14:41:29 -050084
Patrick Williamsc0f7c042017-02-23 20:41:17 -060085command_help = {
86 "create": yocto_bsp_create_help,
87 "list": yocto_bsp_list_help
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088}
89
90
91def start_logging(loglevel):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060092 logging.basicConfig(filename = 'yocto-bsp.log', filemode = 'w', level=loglevel)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093
94
95def main():
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096 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 Williamsc124f4f2015-09-15 14:41:29 -050098
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099 parser.add_argument("-D", "--debug", action = "store_true",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 default = False, help = "output debug information")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600101 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
102 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600104 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 Williamsc124f4f2015-09-15 14:41:29 -0500135
136 loglevel = logging.INFO
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 if args.debug:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138 loglevel = logging.DEBUG
139 start_logging(loglevel)
140
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 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 Williamsc124f4f2015-09-15 14:41:29 -0500145
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146 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 Williamsc124f4f2015-09-15 14:41:29 -0500153
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154 return args.func(args)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155
156if __name__ == "__main__":
157 try:
158 ret = main()
159 except Exception:
160 ret = 1
161 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500162 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163 sys.exit(ret)