blob: 614153e9fe83e30ee4f397cdda45a6e548b9eec2 [file] [log] [blame]
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -07001# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Collection of tools to create sysroots."""
6
7
8from __future__ import print_function
9
10import os
11import sys
12
13from chromite.lib import commandline
14from chromite.lib import cros_build_lib
15from chromite.lib import sysroot_lib
16
17
18def ParseArgs(argv):
19 """Parse arguments.
20
21 Args:
22 argv: array of arguments passed to the script.
23 """
24 parser = commandline.ArgumentParser(description=__doc__)
Bertrand SIMONNETba364242015-03-30 15:02:44 -070025 parser.set_defaults(out_file=None)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070026 subparser = parser.add_subparsers()
27 wrapper = subparser.add_parser('create-wrappers')
28 wrapper.add_argument('--sysroot', help='Path to the sysroot.', required=True)
29 wrapper.add_argument('--friendlyname', help='Name to append to the commands.')
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070030 wrapper.set_defaults(command='create-wrappers')
31
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070032 config = subparser.add_parser('generate-config')
33 target = config.add_mutually_exclusive_group(required=True)
34 target.add_argument('--board', help='Board to generate the config for.')
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070035 config.add_argument('--out-file', dest='out_file',
36 help='File to write into. If not specified, the '
37 'configuration will be printed to stdout.')
38 config.add_argument('--sysroot', help='Path to the sysroot.', required=True)
39 config.set_defaults(command='generate-config')
40
Bertrand SIMONNETba364242015-03-30 15:02:44 -070041 makeconf = subparser.add_parser('generate-make-conf')
42 makeconf.add_argument('--sysroot', help='Sysroot to use.')
43 makeconf.add_argument('--out-file', dest='out_file',
44 help='File to write the configuration into. If not '
45 'specified, the configuration will be printed to '
46 'stdout.')
47 makeconf.add_argument('--accepted-licenses',
48 help='List of accepted licenses.')
49 makeconf.set_defaults(command='generate-make-conf')
50
51 binhost = subparser.add_parser('generate-binhosts')
52 binhost.add_argument('--sysroot', help='Sysroot to use.')
53 binhost.add_argument('--out-file', dest='out_file',
54 help='File to write the configuration into. If not '
55 'specified, the configuration will be printed to '
56 'stdout.')
57 binhost.add_argument('--chrome-only', dest='chrome_only', action='store_true',
58 help='Generate only the chrome binhost.')
59 binhost.add_argument('--local-only', dest='local_only', action='store_true',
60 help='Use compatible local boards only.')
61 binhost.set_defaults(command='generate-binhosts')
62
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070063 options = parser.parse_args(argv)
64 options.Freeze()
65 return options
66
67
68def main(argv):
69 opts = ParseArgs(argv)
70 if not cros_build_lib.IsInsideChroot():
71 raise commandline.ChrootRequiredError()
72
73 if os.geteuid() != 0:
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070074 cros_build_lib.SudoRunCommand(sys.argv, print_cmd=False)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070075 return
76
Bertrand SIMONNETba364242015-03-30 15:02:44 -070077 output = sys.stdout
78 if opts.out_file:
79 output = open(opts.out_file, 'w')
80
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070081 sysroot = sysroot_lib.Sysroot(opts.sysroot)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070082 if opts.command == 'create-wrappers':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070083 sysroot.CreateAllWrappers(opts.friendlyname)
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070084 elif opts.command == 'generate-config':
Don Garrettc0c74002015-10-09 12:58:19 -070085 config = sysroot.GenerateBoardConfig(opts.board)
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070086
Bertrand SIMONNETba364242015-03-30 15:02:44 -070087 output.write('\n' + config)
88 elif opts.command == 'generate-make-conf':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070089 output.write('\n' + sysroot.GenerateMakeConf(opts.accepted_licenses))
Bertrand SIMONNETba364242015-03-30 15:02:44 -070090 elif opts.command == 'generate-binhosts':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070091 output.write('\n' + sysroot.GenerateBinhostConf(opts.chrome_only,
92 opts.local_only))