Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 1 | # Copyright 2018 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 | """setup_board builds the sysroot for a board. |
| 6 | |
| 7 | The setup_board process includes the simple directory creations, installs |
| 8 | several configuration files, sets up portage command wrappers and configs, |
| 9 | and installs the toolchain and some core dependency packages (e.g. kernel |
| 10 | headers, gcc-libs). |
| 11 | """ |
| 12 | |
Alex Klein | 0754704 | 2021-03-12 11:47:03 -0700 | [diff] [blame] | 13 | import argparse |
Mike Frysinger | 6a2b0f2 | 2020-02-20 13:34:07 -0500 | [diff] [blame] | 14 | |
Alex Klein | 2960c75 | 2020-03-09 13:43:38 -0600 | [diff] [blame] | 15 | from chromite.lib import build_target_lib |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 16 | from chromite.lib import commandline |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 17 | from chromite.lib import cros_build_lib |
Mike Frysinger | c14d9a0 | 2019-08-26 15:44:16 -0400 | [diff] [blame] | 18 | from chromite.lib import portage_util |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 19 | from chromite.service import sysroot |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 20 | |
| 21 | |
| 22 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 23 | """Build the argument parser.""" |
| 24 | # TODO(crbug.com/922144) Remove underscore separated arguments and the |
| 25 | # deprecated message after 2019-06-01. |
| 26 | deprecated = "Argument will be removed 2019-06-01. Use %s instead." |
| 27 | parser = commandline.ArgumentParser(description=__doc__) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 28 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 29 | parser.add_argument( |
| 30 | "-b", |
| 31 | "--board", |
| 32 | "--build-target", |
| 33 | required=True, |
| 34 | dest="board", |
| 35 | help="The name of the board to set up.", |
| 36 | ) |
| 37 | parser.add_argument( |
| 38 | "--default", |
| 39 | action="store_true", |
| 40 | default=False, |
| 41 | help="Set the board to the default board in your chroot.", |
| 42 | ) |
| 43 | parser.add_argument( |
| 44 | "--force", |
| 45 | action="store_true", |
| 46 | default=False, |
| 47 | help="Force re-creating the board root.", |
| 48 | ) |
| 49 | # The positive and negative versions of the arguments are used. |
| 50 | # TODO(saklein) Simplify usages to a single version of the argument. |
| 51 | parser.add_argument( |
| 52 | "--usepkg", |
| 53 | action="store_true", |
| 54 | default=True, |
| 55 | dest="usepkg", |
| 56 | help="Use binary packages to bootstrap.", |
| 57 | ) |
| 58 | parser.add_argument( |
| 59 | "--nousepkg", |
| 60 | action="store_false", |
| 61 | default=True, |
| 62 | dest="usepkg", |
| 63 | help="Do not use binary packages to bootstrap.", |
| 64 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 65 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 66 | advanced = parser.add_argument_group("Advanced Options") |
| 67 | advanced.add_argument( |
| 68 | "--accept-licenses", help="Licenses to append to the accept list." |
| 69 | ) |
| 70 | advanced.add_argument( |
| 71 | "--accept_licenses", |
| 72 | deprecated=deprecated % "--accept-licenses", |
| 73 | help="Deprecated form of --accept-licenses.", |
| 74 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 75 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 76 | # Build target related arguments. |
| 77 | target = parser.add_argument_group("Advanced Build Target Options") |
| 78 | target.add_argument( |
| 79 | "--profile", |
| 80 | help="The portage configuration profile to use. Profile " |
| 81 | "must be located in overlay-board/profiles.", |
| 82 | ) |
| 83 | target.add_argument("--variant", help="Board variant.") |
| 84 | target.add_argument("--board-root", type="path", help="Board root.") |
| 85 | target.add_argument( |
| 86 | "--board_root", |
| 87 | type="path", |
| 88 | deprecated=deprecated % "--board-root", |
| 89 | help="Deprecated form of --board-root.", |
| 90 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 91 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 92 | # Arguments related to the build itself. |
| 93 | build = parser.add_argument_group("Advanced Build Modification Options") |
| 94 | build.add_argument( |
| 95 | "--jobs", |
| 96 | type=int, |
| 97 | help="Maximum number of packages to build in parallel.", |
| 98 | ) |
| 99 | build.add_argument( |
| 100 | "--regen-configs", |
| 101 | action="store_true", |
| 102 | default=False, |
| 103 | help="Regenerate all config files (useful for " |
| 104 | "modifying profiles without rebuild).", |
| 105 | ) |
| 106 | build.add_argument( |
| 107 | "--regen_configs", |
| 108 | action="store_true", |
| 109 | default=False, |
| 110 | deprecated=deprecated % "--regen-configs", |
| 111 | help="Deprecated form of --regen-configs.", |
| 112 | ) |
| 113 | build.add_argument( |
| 114 | "--quiet", |
| 115 | action="store_true", |
| 116 | default=False, |
| 117 | help="Don't print warnings when board already exists.", |
| 118 | ) |
| 119 | build.add_argument( |
| 120 | "--skip-toolchain-update", |
| 121 | action="store_true", |
| 122 | default=False, |
| 123 | help="Don't update toolchain automatically.", |
| 124 | ) |
| 125 | build.add_argument( |
| 126 | "--skip_toolchain_update", |
| 127 | action="store_true", |
| 128 | default=False, |
| 129 | deprecated=deprecated % "--skip-toolchain-update", |
| 130 | help="Deprecated form of --skip-toolchain-update.", |
| 131 | ) |
| 132 | build.add_argument( |
| 133 | "--skip-chroot-upgrade", |
| 134 | action="store_true", |
| 135 | default=False, |
| 136 | help="Don't run the chroot upgrade automatically; " "use with care.", |
| 137 | ) |
| 138 | build.add_argument( |
| 139 | "--skip_chroot_upgrade", |
| 140 | action="store_true", |
| 141 | default=False, |
| 142 | deprecated=deprecated % "--skip-chroot-upgrade", |
| 143 | help="Deprecated form of --skip-chroot-upgrade.", |
| 144 | ) |
| 145 | build.add_argument( |
| 146 | "--skip-board-pkg-init", |
| 147 | action="store_true", |
| 148 | default=False, |
| 149 | help="Don't emerge any packages during setup_board into " |
| 150 | "the board root.", |
| 151 | ) |
| 152 | build.add_argument( |
| 153 | "--skip_board_pkg_init", |
| 154 | action="store_true", |
| 155 | default=False, |
| 156 | deprecated=deprecated % "--skip-board-pkg-init", |
| 157 | help="Deprecated form of --skip-board-pkg-init.", |
| 158 | ) |
| 159 | build.add_argument( |
| 160 | "--reuse-pkgs-from-local-boards", |
| 161 | dest="reuse_local", |
| 162 | action="store_true", |
| 163 | default=False, |
| 164 | help="Bootstrap from local packages instead of remote " "packages.", |
| 165 | ) |
| 166 | build.add_argument( |
| 167 | "--reuse_pkgs_from_local_boards", |
| 168 | dest="reuse_local", |
| 169 | action="store_true", |
| 170 | default=False, |
| 171 | deprecated=deprecated % "--reuse-pkgs-from-local-boards", |
| 172 | help="Deprecated form of --reuse-pkgs-from-local-boards.", |
| 173 | ) |
| 174 | build.add_argument( |
| 175 | "--backtrack", |
| 176 | type=int, |
| 177 | default=sysroot.BACKTRACK_DEFAULT, |
| 178 | help="See emerge --backtrack.", |
| 179 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 180 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 181 | parser.add_argument( |
| 182 | "--fewer-binhosts", |
| 183 | dest="expanded_binhost_inheritance", |
| 184 | default=True, |
| 185 | action="store_false", |
| 186 | help=argparse.SUPPRESS, |
| 187 | ) |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 188 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 189 | return parser |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 190 | |
| 191 | |
| 192 | def _ParseArgs(args): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 193 | """Parse and validate arguments.""" |
| 194 | parser = GetParser() |
| 195 | opts = parser.parse_args(args) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 196 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 197 | # Translate raw options to config objects. |
| 198 | name = "%s_%s" % (opts.board, opts.variant) if opts.variant else opts.board |
| 199 | opts.build_target = build_target_lib.BuildTarget( |
| 200 | name, build_root=opts.board_root, profile=opts.profile |
| 201 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 202 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 203 | opts.run_config = sysroot.SetupBoardRunConfig( |
| 204 | set_default=opts.default, |
| 205 | force=opts.force, |
| 206 | usepkg=opts.usepkg, |
| 207 | jobs=opts.jobs, |
| 208 | regen_configs=opts.regen_configs, |
| 209 | quiet=opts.quiet, |
| 210 | update_toolchain=not opts.skip_toolchain_update, |
| 211 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 212 | init_board_pkgs=not opts.skip_board_pkg_init, |
| 213 | local_build=opts.reuse_local, |
| 214 | expanded_binhost_inheritance=opts.expanded_binhost_inheritance, |
| 215 | backtrack=opts.backtrack, |
| 216 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 217 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 218 | opts.Freeze() |
| 219 | return opts |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 220 | |
| 221 | |
| 222 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 223 | opts = _ParseArgs(argv) |
| 224 | try: |
| 225 | sysroot.SetupBoard( |
| 226 | opts.build_target, opts.accept_licenses, opts.run_config |
| 227 | ) |
| 228 | except portage_util.MissingOverlayError as e: |
| 229 | # Add a bit more user friendly message as people can typo names easily. |
| 230 | cros_build_lib.Die( |
| 231 | "%s\n" |
| 232 | "Double check the --board setting and make sure you're syncing the " |
| 233 | "right manifest (internal-vs-external).", |
| 234 | e, |
| 235 | ) |
| 236 | except sysroot.Error as e: |
| 237 | cros_build_lib.Die(e) |