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 |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 17 | from chromite.service import setup_board |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def GetParser(): |
| 21 | """Build the argument parser.""" |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 22 | # TODO(crbug.com/922144) Remove underscore separated arguments and the |
| 23 | # deprecated message after 2019-06-01. |
| 24 | deprecated = 'Argument will be removed 2019-06-01. Use %s instead.' |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 25 | parser = commandline.ArgumentParser(description=__doc__) |
| 26 | |
| 27 | parser.add_argument('--board', required=True, |
| 28 | help='The name of the board to set up.') |
| 29 | parser.add_argument('--default', action='store_true', default=False, |
| 30 | help='Set the board to the default board in your chroot.') |
| 31 | parser.add_argument('--force', action='store_true', default=False, |
| 32 | help='Force re-creating the board root.') |
| 33 | # The positive and negative versions of the arguments are used. |
| 34 | # TODO(saklein) Simplify usages to a single version of the argument. |
| 35 | parser.add_argument('--usepkg', action='store_true', default=True, |
| 36 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 37 | parser.add_argument('--nousepkg', action='store_false', default=True, |
| 38 | dest='usepkg', help='Use binary packages to bootstrap.') |
| 39 | |
| 40 | advanced = parser.add_argument_group('Advanced Options') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 41 | advanced.add_argument('--accept-licenses', |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 42 | help='Licenses to append to the accept list.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 43 | advanced.add_argument('--accept_licenses', |
| 44 | deprecated=deprecated % '--accept-licenses', |
| 45 | help='Deprecated form of --accept-licenses.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 46 | |
| 47 | # Build target related arguments. |
| 48 | target = parser.add_argument_group('Advanced Build Target Options') |
| 49 | target.add_argument('--profile', |
| 50 | help='The portage configuration profile to use. Profile ' |
| 51 | 'must be located in overlay-board/profiles.') |
| 52 | target.add_argument('--variant', help='Board variant.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 53 | target.add_argument('--board-root', type='path', help='Board root.') |
| 54 | target.add_argument('--board_root', type='path', |
| 55 | deprecated=deprecated % '--board-root', |
| 56 | help='Deprecated form of --board-root.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 57 | |
| 58 | # Arguments related to the build itself. |
| 59 | build = parser.add_argument_group('Advanced Build Modification Options') |
| 60 | build.add_argument('--jobs', type=int, |
| 61 | help='Maximum number of packages to build in parallel.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 62 | build.add_argument('--regen-configs', action='store_true', default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 63 | help='Regenerate all config files (useful for ' |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 64 | 'modifying profiles without rebuild).') |
| 65 | build.add_argument('--regen_configs', action='store_true', default=False, |
| 66 | deprecated=deprecated % '--regen-configs', |
| 67 | help='Deprecated form of --regen-configs.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 68 | build.add_argument('--quiet', action='store_true', default=False, |
| 69 | help="Don't print warnings when board already exists.") |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 70 | build.add_argument('--skip-toolchain-update', action='store_true', |
| 71 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 72 | help="Don't update toolchain automatically.") |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 73 | build.add_argument('--skip_toolchain_update', action='store_true', |
| 74 | default=False, |
| 75 | deprecated=deprecated % '--skip-toolchain-update', |
| 76 | help='Deprecated form of --skip-toolchain-update.') |
| 77 | build.add_argument('--skip-chroot-upgrade', action='store_true', |
| 78 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 79 | help="Don't run the chroot upgrade automatically; " |
| 80 | 'use with care.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 81 | build.add_argument('--skip_chroot_upgrade', action='store_true', |
| 82 | default=False, |
| 83 | deprecated=deprecated % '--skip-chroot-upgrade', |
| 84 | help='Deprecated form of --skip-chroot-upgrade.') |
| 85 | build.add_argument('--skip-board-pkg-init', action='store_true', |
| 86 | default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 87 | help="Don't emerge any packages during setup_board into " |
| 88 | 'the board root.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 89 | build.add_argument('--skip_board_pkg_init', action='store_true', |
| 90 | default=False, |
| 91 | deprecated=deprecated % '--skip-board-pkg-init', |
| 92 | help='Deprecated form of --skip-board-pkg-init.') |
| 93 | build.add_argument('--reuse-pkgs-from-local-boards', dest='reuse_local', |
| 94 | action='store_true', default=False, |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 95 | help='Bootstrap from local packages instead of remote ' |
| 96 | 'packages.') |
Alex Klein | 6893e71 | 2019-01-16 14:43:29 -0700 | [diff] [blame] | 97 | build.add_argument('--reuse_pkgs_from_local_boards', dest='reuse_local', |
| 98 | action='store_true', default=False, |
| 99 | deprecated=deprecated % '--reuse-pkgs-from-local-boards', |
| 100 | help='Deprecated form of --reuse-pkgs-from-local-boards.') |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 101 | |
| 102 | return parser |
| 103 | |
| 104 | |
| 105 | def _ParseArgs(args): |
| 106 | """Parse and validate arguments.""" |
| 107 | parser = GetParser() |
| 108 | opts = parser.parse_args(args) |
| 109 | |
| 110 | # Translate raw options to config objects. |
| 111 | opts.board_conf = setup_board.Board(board=opts.board, variant=opts.variant, |
| 112 | board_root=opts.board_root, |
| 113 | profile=opts.profile) |
| 114 | |
| 115 | opts.run_config = setup_board.SetupBoardRunConfig( |
| 116 | set_default=opts.default, force=opts.force, usepkg=opts.usepkg, |
| 117 | jobs=opts.jobs, regen_configs=opts.regen_configs, quiet=opts.quiet, |
| 118 | update_toolchain=not opts.skip_toolchain_update, |
| 119 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 120 | init_board_pkgs=not opts.skip_board_pkg_init, |
| 121 | local_build=opts.reuse_local) |
| 122 | |
| 123 | opts.Freeze() |
| 124 | return opts |
| 125 | |
| 126 | |
| 127 | def main(argv): |
| 128 | opts = _ParseArgs(argv) |
| 129 | setup_board.SetupBoard(opts.board_conf, opts.accept_licenses, opts.run_config) |