Bertrand SIMONNET | 9562e2c | 2015-03-13 13:57:43 -0700 | [diff] [blame^] | 1 | # 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 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | |
| 13 | from chromite.lib import commandline |
| 14 | from chromite.lib import cros_build_lib |
| 15 | from chromite.lib import sysroot_lib |
| 16 | |
| 17 | |
| 18 | def ParseArgs(argv): |
| 19 | """Parse arguments. |
| 20 | |
| 21 | Args: |
| 22 | argv: array of arguments passed to the script. |
| 23 | """ |
| 24 | parser = commandline.ArgumentParser(description=__doc__) |
| 25 | subparser = parser.add_subparsers() |
| 26 | wrapper = subparser.add_parser('create-wrappers') |
| 27 | wrapper.add_argument('--sysroot', help='Path to the sysroot.', required=True) |
| 28 | wrapper.add_argument('--friendlyname', help='Name to append to the commands.') |
| 29 | wrapper.add_argument('--toolchain', help='Toolchain used in this sysroot.', |
| 30 | required=True) |
| 31 | wrapper.set_defaults(command='create-wrappers') |
| 32 | |
| 33 | options = parser.parse_args(argv) |
| 34 | options.Freeze() |
| 35 | return options |
| 36 | |
| 37 | |
| 38 | def main(argv): |
| 39 | opts = ParseArgs(argv) |
| 40 | if not cros_build_lib.IsInsideChroot(): |
| 41 | raise commandline.ChrootRequiredError() |
| 42 | |
| 43 | if os.geteuid() != 0: |
| 44 | cros_build_lib.SudoRunCommand(sys.argv) |
| 45 | return |
| 46 | |
| 47 | if opts.command == 'create-wrappers': |
| 48 | sysroot_lib.CreateAllWrappers(opts.sysroot, opts.toolchain, |
| 49 | opts.friendlyname) |