blob: ef73a50a2c89af208b7d9b010defb6974d1e7e57 [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 SIMONNET41af2652015-03-27 13:21:29 -070031 wrapper.add_argument('--toolchain', help='Toolchain used in this sysroot.')
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070032 wrapper.set_defaults(command='create-wrappers')
33
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070034 config = subparser.add_parser('generate-config')
35 target = config.add_mutually_exclusive_group(required=True)
36 target.add_argument('--board', help='Board to generate the config for.')
37 target.add_argument('--brick', help='Brick to generate the config for.')
38 config.add_argument('--out-file', dest='out_file',
39 help='File to write into. If not specified, the '
40 'configuration will be printed to stdout.')
41 config.add_argument('--sysroot', help='Path to the sysroot.', required=True)
42 config.set_defaults(command='generate-config')
43
Bertrand SIMONNETba364242015-03-30 15:02:44 -070044 makeconf = subparser.add_parser('generate-make-conf')
45 makeconf.add_argument('--sysroot', help='Sysroot to use.')
46 makeconf.add_argument('--out-file', dest='out_file',
47 help='File to write the configuration into. If not '
48 'specified, the configuration will be printed to '
49 'stdout.')
50 makeconf.add_argument('--accepted-licenses',
51 help='List of accepted licenses.')
52 makeconf.set_defaults(command='generate-make-conf')
53
54 binhost = subparser.add_parser('generate-binhosts')
55 binhost.add_argument('--sysroot', help='Sysroot to use.')
56 binhost.add_argument('--out-file', dest='out_file',
57 help='File to write the configuration into. If not '
58 'specified, the configuration will be printed to '
59 'stdout.')
60 binhost.add_argument('--chrome-only', dest='chrome_only', action='store_true',
61 help='Generate only the chrome binhost.')
62 binhost.add_argument('--local-only', dest='local_only', action='store_true',
63 help='Use compatible local boards only.')
64 binhost.set_defaults(command='generate-binhosts')
65
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070066 options = parser.parse_args(argv)
67 options.Freeze()
68 return options
69
70
71def main(argv):
72 opts = ParseArgs(argv)
73 if not cros_build_lib.IsInsideChroot():
74 raise commandline.ChrootRequiredError()
75
76 if os.geteuid() != 0:
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070077 cros_build_lib.SudoRunCommand(sys.argv, print_cmd=False)
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070078 return
79
Bertrand SIMONNETba364242015-03-30 15:02:44 -070080 output = sys.stdout
81 if opts.out_file:
82 output = open(opts.out_file, 'w')
83
Bertrand SIMONNET9562e2c2015-03-13 13:57:43 -070084 if opts.command == 'create-wrappers':
85 sysroot_lib.CreateAllWrappers(opts.sysroot, opts.toolchain,
86 opts.friendlyname)
Bertrand SIMONNET7d66e232015-03-24 17:45:50 -070087 elif opts.command == 'generate-config':
88 if opts.brick:
89 config = sysroot_lib.GenerateBrickConfig(
90 opts.sysroot, brick=brick_lib.Brick(opts.brick))
91 else:
92 config = sysroot_lib.GenerateBoardConfig(opts.sysroot, board=opts.board)
93
Bertrand SIMONNETba364242015-03-30 15:02:44 -070094 output.write('\n' + config)
95 elif opts.command == 'generate-make-conf':
96 output.write('\n' + sysroot_lib.GenerateMakeConf(opts.sysroot,
97 opts.accepted_licenses))
98 elif opts.command == 'generate-binhosts':
99 output.write('\n' + sysroot_lib.GenerateBinhostConf(opts.sysroot,
100 opts.chrome_only,
101 opts.local_only))