Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2018 The ChromiumOS Authors |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 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 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 70 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 71 | # Build target related arguments. |
| 72 | target = parser.add_argument_group("Advanced Build Target Options") |
| 73 | target.add_argument( |
| 74 | "--profile", |
| 75 | help="The portage configuration profile to use. Profile " |
| 76 | "must be located in overlay-board/profiles.", |
| 77 | ) |
| 78 | target.add_argument("--variant", help="Board variant.") |
| 79 | target.add_argument("--board-root", type="path", help="Board root.") |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 80 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 81 | # Arguments related to the build itself. |
| 82 | build = parser.add_argument_group("Advanced Build Modification Options") |
| 83 | build.add_argument( |
| 84 | "--jobs", |
| 85 | type=int, |
| 86 | help="Maximum number of packages to build in parallel.", |
| 87 | ) |
| 88 | build.add_argument( |
| 89 | "--regen-configs", |
| 90 | action="store_true", |
| 91 | default=False, |
| 92 | help="Regenerate all config files (useful for " |
| 93 | "modifying profiles without rebuild).", |
| 94 | ) |
| 95 | build.add_argument( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 96 | "--quiet", |
| 97 | action="store_true", |
| 98 | default=False, |
| 99 | help="Don't print warnings when board already exists.", |
| 100 | ) |
| 101 | build.add_argument( |
| 102 | "--skip-toolchain-update", |
| 103 | action="store_true", |
| 104 | default=False, |
| 105 | help="Don't update toolchain automatically.", |
| 106 | ) |
| 107 | build.add_argument( |
| 108 | "--skip_toolchain_update", |
| 109 | action="store_true", |
| 110 | default=False, |
| 111 | deprecated=deprecated % "--skip-toolchain-update", |
| 112 | help="Deprecated form of --skip-toolchain-update.", |
| 113 | ) |
| 114 | build.add_argument( |
| 115 | "--skip-chroot-upgrade", |
| 116 | action="store_true", |
| 117 | default=False, |
Jack Rosenthal | 17414e8 | 2023-05-12 13:18:03 -0600 | [diff] [blame] | 118 | help="Don't run the chroot upgrade automatically; use with care.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 119 | ) |
| 120 | build.add_argument( |
| 121 | "--skip_chroot_upgrade", |
| 122 | action="store_true", |
| 123 | default=False, |
| 124 | deprecated=deprecated % "--skip-chroot-upgrade", |
| 125 | help="Deprecated form of --skip-chroot-upgrade.", |
| 126 | ) |
| 127 | build.add_argument( |
| 128 | "--skip-board-pkg-init", |
| 129 | action="store_true", |
| 130 | default=False, |
| 131 | help="Don't emerge any packages during setup_board into " |
| 132 | "the board root.", |
| 133 | ) |
| 134 | build.add_argument( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 135 | "--reuse-pkgs-from-local-boards", |
| 136 | dest="reuse_local", |
| 137 | action="store_true", |
| 138 | default=False, |
Jack Rosenthal | 17414e8 | 2023-05-12 13:18:03 -0600 | [diff] [blame] | 139 | help="Bootstrap from local packages instead of remote packages.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 140 | ) |
| 141 | build.add_argument( |
| 142 | "--backtrack", |
| 143 | type=int, |
| 144 | default=sysroot.BACKTRACK_DEFAULT, |
| 145 | help="See emerge --backtrack.", |
| 146 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 147 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 148 | parser.add_argument( |
| 149 | "--fewer-binhosts", |
| 150 | dest="expanded_binhost_inheritance", |
| 151 | default=True, |
| 152 | action="store_false", |
| 153 | help=argparse.SUPPRESS, |
| 154 | ) |
Alex Klein | 1b031e3 | 2021-03-08 15:28:30 -0700 | [diff] [blame] | 155 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 156 | return parser |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 157 | |
| 158 | |
| 159 | def _ParseArgs(args): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 160 | """Parse and validate arguments.""" |
| 161 | parser = GetParser() |
| 162 | opts = parser.parse_args(args) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 163 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 164 | # Translate raw options to config objects. |
| 165 | name = "%s_%s" % (opts.board, opts.variant) if opts.variant else opts.board |
| 166 | opts.build_target = build_target_lib.BuildTarget( |
| 167 | name, build_root=opts.board_root, profile=opts.profile |
| 168 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 169 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 170 | opts.run_config = sysroot.SetupBoardRunConfig( |
| 171 | set_default=opts.default, |
| 172 | force=opts.force, |
| 173 | usepkg=opts.usepkg, |
| 174 | jobs=opts.jobs, |
| 175 | regen_configs=opts.regen_configs, |
| 176 | quiet=opts.quiet, |
| 177 | update_toolchain=not opts.skip_toolchain_update, |
| 178 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 179 | init_board_pkgs=not opts.skip_board_pkg_init, |
| 180 | local_build=opts.reuse_local, |
| 181 | expanded_binhost_inheritance=opts.expanded_binhost_inheritance, |
Cindy Lin | adc610a | 2023-05-23 18:46:12 +0000 | [diff] [blame] | 182 | use_cq_prebuilts=opts.usepkg, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 183 | backtrack=opts.backtrack, |
| 184 | ) |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | opts.Freeze() |
| 187 | return opts |
Alex Klein | 3458108 | 2018-12-03 12:56:53 -0700 | [diff] [blame] | 188 | |
| 189 | |
| 190 | def main(argv): |
Jack Rosenthal | 77c07c3 | 2023-04-21 15:31:34 -0600 | [diff] [blame] | 191 | commandline.RunInsideChroot() |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 192 | opts = _ParseArgs(argv) |
| 193 | try: |
| 194 | sysroot.SetupBoard( |
| 195 | opts.build_target, opts.accept_licenses, opts.run_config |
| 196 | ) |
| 197 | except portage_util.MissingOverlayError as e: |
| 198 | # Add a bit more user friendly message as people can typo names easily. |
| 199 | cros_build_lib.Die( |
| 200 | "%s\n" |
| 201 | "Double check the --board setting and make sure you're syncing the " |
| 202 | "right manifest (internal-vs-external).", |
| 203 | e, |
| 204 | ) |
| 205 | except sysroot.Error as e: |
| 206 | cros_build_lib.Die(e) |