blob: a4d3fbf95146654fea63d910ed27e712091c96d0 [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
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070013from chromite.lib import brick_lib
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070014from chromite.lib import commandline
15from chromite.lib import cros_build_lib
16from chromite.lib import sysroot_lib
17
18
19def ParseArgs(argv):
20 """Parse arguments.
21
22 Args:
23 argv: array of arguments passed to the script.
24 """
25 parser = commandline.ArgumentParser(description=__doc__)
Bertrand SIMONNETba364242015-03-30 15:02:44 -070026 parser.set_defaults(out_file=None)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070027 subparser = parser.add_subparsers()
28 wrapper = subparser.add_parser('create-wrappers')
29 wrapper.add_argument('--sysroot', help='Path to the sysroot.', required=True)
30 wrapper.add_argument('--friendlyname', help='Name to append to the commands.')
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070031 wrapper.set_defaults(command='create-wrappers')
32
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070033 config = subparser.add_parser('generate-config')
34 target = config.add_mutually_exclusive_group(required=True)
35 target.add_argument('--board', help='Board to generate the config for.')
36 target.add_argument('--brick', help='Brick to generate the config for.')
37 config.add_argument('--out-file', dest='out_file',
38 help='File to write into. If not specified, the '
39 'configuration will be printed to stdout.')
40 config.add_argument('--sysroot', help='Path to the sysroot.', required=True)
41 config.set_defaults(command='generate-config')
42
Bertrand SIMONNETba364242015-03-30 15:02:44 -070043 makeconf = subparser.add_parser('generate-make-conf')
44 makeconf.add_argument('--sysroot', help='Sysroot to use.')
45 makeconf.add_argument('--out-file', dest='out_file',
46 help='File to write the configuration into. If not '
47 'specified, the configuration will be printed to '
48 'stdout.')
49 makeconf.add_argument('--accepted-licenses',
50 help='List of accepted licenses.')
51 makeconf.set_defaults(command='generate-make-conf')
52
53 binhost = subparser.add_parser('generate-binhosts')
54 binhost.add_argument('--sysroot', help='Sysroot to use.')
55 binhost.add_argument('--out-file', dest='out_file',
56 help='File to write the configuration into. If not '
57 'specified, the configuration will be printed to '
58 'stdout.')
59 binhost.add_argument('--chrome-only', dest='chrome_only', action='store_true',
60 help='Generate only the chrome binhost.')
61 binhost.add_argument('--local-only', dest='local_only', action='store_true',
62 help='Use compatible local boards only.')
63 binhost.set_defaults(command='generate-binhosts')
64
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070065 options = parser.parse_args(argv)
66 options.Freeze()
67 return options
68
69
70def main(argv):
71 opts = ParseArgs(argv)
72 if not cros_build_lib.IsInsideChroot():
73 raise commandline.ChrootRequiredError()
74
75 if os.geteuid() != 0:
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070076 cros_build_lib.SudoRunCommand(sys.argv, print_cmd=False)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070077 return
78
Bertrand SIMONNETba364242015-03-30 15:02:44 -070079 output = sys.stdout
80 if opts.out_file:
81 output = open(opts.out_file, 'w')
82
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070083 sysroot = sysroot_lib.Sysroot(opts.sysroot)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070084 if opts.command == 'create-wrappers':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070085 sysroot.CreateAllWrappers(opts.friendlyname)
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070086 elif opts.command == 'generate-config':
87 if opts.brick:
Bertrand SIMONNET8eff43b2015-05-06 16:46:55 -070088 config = sysroot.GenerateBrickConfig(
89 brick_lib.Brick(opts.brick).BrickStack())
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070090 else:
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070091 config = sysroot.GenerateBoardConfig(opts.board)
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070092
Bertrand SIMONNETba364242015-03-30 15:02:44 -070093 output.write('\n' + config)
94 elif opts.command == 'generate-make-conf':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070095 output.write('\n' + sysroot.GenerateMakeConf(opts.accepted_licenses))
Bertrand SIMONNETba364242015-03-30 15:02:44 -070096 elif opts.command == 'generate-binhosts':
Bertrand SIMONNETe2cec3f2015-04-06 16:12:54 -070097 output.write('\n' + sysroot.GenerateBinhostConf(opts.chrome_only,
98 opts.local_only))