Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """setup_board builds the sysroot for a board. |
| 7 | |
| 8 | The setup_board process includes the simple directory creations, installs |
| 9 | several configuration files, sets up portage command wrappers and configs, |
| 10 | and installs the toolchain and some core dependency packages (e.g. kernel |
| 11 | headers, gcc-libs). |
| 12 | """ |
| 13 | |
| 14 | from __future__ import print_function |
| 15 | |
| 16 | from chromite.lib import commandline |
| 17 | from chromite.lib.api import setup_board |
| 18 | |
| 19 | |
| 20 | def GetParser(): |
| 21 | """Build the argument parser.""" |
| 22 | # TODO(saklein) Remove underscore separated arguments after 2019-06-01 |
| 23 | # (crbug.com/922144). |
| 24 | parser = commandline.ArgumentParser(description=__doc__) |
| 25 | |
| 26 | parser.add_argument('--board', required=True, |
| 27 | help='The name of the board to set up.') |
| 28 | parser.add_argument('--default', action='store_true', default=False, |
| 29 | help='Set the board to the default board in your chroot.') |
| 30 | parser.add_argument('--force', action='store_true', default=False, |
| 31 | help='Force re-creating the board root.') |
| 32 | # The positive and negative versions of the arguments are used. |
| 33 | # TODO(saklein) Simplify usages to a single version of the argument. |
| 34 | parser.add_argument('--usepkg', action='store_true', default=True, |
| 35 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 36 | parser.add_argument('--nousepkg', action='store_false', default=True, |
| 37 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 38 | |
| 39 | advanced = parser.add_argument_group('Advanced Options') |
| 40 | advanced.add_argument('--accept-licenses', '--accept_licenses', |
| 41 | help='Licenses to append to the accept list.') |
| 42 | |
| 43 | # Build target related arguments. |
| 44 | target = parser.add_argument_group('Advanced Build Target Options') |
| 45 | target.add_argument('--profile', |
| 46 | help='The portage configuration profile to use. Profile ' |
| 47 | 'must be located in overlay-board/profiles.') |
| 48 | target.add_argument('--variant', help='Board variant.') |
| 49 | target.add_argument('--board-root', '--board_root', type='path', |
| 50 | help='Board root.') |
| 51 | |
| 52 | # Arguments related to the build itself. |
| 53 | build = parser.add_argument_group('Advanced Build Modification Options') |
| 54 | build.add_argument('--jobs', type=int, |
| 55 | help='Maximum number of packages to build in parallel.') |
| 56 | build.add_argument('--regen-configs', '--regen_configs', action='store_true', |
| 57 | default=False, |
| 58 | help='Regenerate all config files (useful for ' |
| 59 | 'modifying profiles w/out rebuild).') |
| 60 | build.add_argument('--quiet', action='store_true', default=False, |
| 61 | help="Don't print warnings when board already exists.") |
| 62 | build.add_argument('--skip-toolchain-update', '--skip_toolchain_update', |
| 63 | action='store_true', default=False, |
| 64 | help="Don't update toolchain automatically.") |
| 65 | build.add_argument('--skip-chroot-upgrade', '--skip_chroot_upgrade', |
| 66 | action='store_true', default=False, |
| 67 | help="Don't run the chroot upgrade automatically; " |
| 68 | 'use with care.') |
| 69 | build.add_argument('--skip-board-pkg-init', '--skip_board_pkg_init', |
| 70 | action='store_true', default=False, |
| 71 | help="Don't emerge any packages during setup_board into " |
| 72 | 'the board root.') |
| 73 | build.add_argument('--reuse-pkgs-from-local-boards', |
| 74 | '--reuse_pkgs_from_local_boards', |
| 75 | dest='reuse_local', action='store_true', default=False, |
| 76 | help='Bootstrap from local packages instead of remote ' |
| 77 | 'packages.') |
| 78 | |
| 79 | return parser |
| 80 | |
| 81 | |
| 82 | def _ParseArgs(args): |
| 83 | """Parse and validate arguments.""" |
| 84 | parser = GetParser() |
| 85 | opts = parser.parse_args(args) |
| 86 | |
| 87 | # Translate raw options to config objects. |
| 88 | opts.board_conf = setup_board.Board(board=opts.board, variant=opts.variant, |
| 89 | board_root=opts.board_root, |
| 90 | profile=opts.profile) |
| 91 | |
| 92 | opts.run_config = setup_board.SetupBoardRunConfig( |
| 93 | set_default=opts.default, force=opts.force, usepkg=opts.usepkg, |
| 94 | jobs=opts.jobs, regen_configs=opts.regen_configs, quiet=opts.quiet, |
| 95 | update_toolchain=not opts.skip_toolchain_update, |
| 96 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 97 | init_board_pkgs=not opts.skip_board_pkg_init, |
| 98 | local_build=opts.reuse_local) |
| 99 | |
| 100 | opts.Freeze() |
| 101 | return opts |
| 102 | |
| 103 | |
| 104 | def main(argv): |
| 105 | opts = _ParseArgs(argv) |
| 106 | setup_board.SetupBoard(opts.board_conf, opts.accept_licenses, opts.run_config) |