Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2022 The ChromiumOS Authors |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [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 | """build_packages updates the set of binary packages needed by Chrome OS. |
| 6 | |
| 7 | The build_packages process cross compiles all packages that have been |
| 8 | updated into the given sysroot and builds binary packages as a side-effect. |
| 9 | The output packages will be used by the build_image script to create a |
| 10 | bootable Chrome OS image. |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 11 | |
| 12 | If packages are specified in cli, only build those specific packages and any |
| 13 | dependencies they might need. |
| 14 | |
| 15 | For the fastest builds, use --nowithautotest --noworkon. |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [diff] [blame] | 16 | """ |
| 17 | |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 18 | import argparse |
Alex Klein | fba23ba | 2022-02-03 11:58:48 -0700 | [diff] [blame] | 19 | import logging |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [diff] [blame] | 20 | import os |
Mike Frysinger | 807d828 | 2022-04-28 22:45:17 -0400 | [diff] [blame] | 21 | from typing import List, Optional, Tuple |
Alex Klein | fba23ba | 2022-02-03 11:58:48 -0700 | [diff] [blame] | 22 | import urllib.error |
| 23 | import urllib.request |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [diff] [blame] | 24 | |
Cindy Lin | 7487daa | 2022-02-23 04:14:10 +0000 | [diff] [blame] | 25 | from chromite.lib import build_target_lib |
Sergey Frolov | f988de7 | 2023-03-06 20:05:21 -0700 | [diff] [blame] | 26 | from chromite.lib import chromite_config |
Alex Klein | a39dc98 | 2022-02-03 12:13:14 -0700 | [diff] [blame] | 27 | from chromite.lib import commandline |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [diff] [blame] | 28 | from chromite.lib import cros_build_lib |
Cindy Lin | 7487daa | 2022-02-23 04:14:10 +0000 | [diff] [blame] | 29 | from chromite.lib import sysroot_lib |
Ram Chandrasekar | bdec0f0 | 2022-02-24 01:20:17 +0000 | [diff] [blame] | 30 | from chromite.service import sysroot |
Cindy Lin | b7f89a4 | 2022-05-23 16:50:00 +0000 | [diff] [blame] | 31 | from chromite.utils import timer |
Cindy Lin | c06b4ea | 2022-01-27 18:13:04 +0000 | [diff] [blame] | 32 | |
| 33 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 34 | def build_shell_bool_style_args( |
| 35 | parser: commandline.ArgumentParser, |
| 36 | name: str, |
| 37 | default_val: bool, |
| 38 | help_str: str, |
| 39 | deprecation_note: str, |
| 40 | alternate_name: Optional[str] = None, |
| 41 | ) -> None: |
| 42 | """Build the shell boolean input argument equivalent. |
Alex Klein | a39dc98 | 2022-02-03 12:13:14 -0700 | [diff] [blame] | 43 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 44 | There are two cases which we will need to handle, |
| 45 | case 1: A shell boolean arg, which doesn't need to be re-worded in python. |
| 46 | case 2: A shell boolean arg, which needs to be re-worded in python. |
| 47 | Example below. |
| 48 | For Case 1, for a given input arg name 'argA', we create three python |
| 49 | arguments. |
| 50 | --argA, --noargA, --no-argA. The arguments --argA and --no-argA will be |
| 51 | retained after deprecating --noargA. |
| 52 | For Case 2, for a given input arg name 'arg_A' we need to use alternate |
| 53 | argument name 'arg-A'. we create four python arguments in this case. |
| 54 | --arg_A, --noarg_A, --arg-A, --no-arg-A. The first two arguments will be |
| 55 | deprecated later. |
| 56 | TODO(b/218522717): Remove the creation of --noargA in case 1 and --arg_A and |
| 57 | --noarg_A in case 2. |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 58 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 59 | Args: |
| 60 | parser: The parser to update. |
| 61 | name: The input argument name. This will be used as 'dest' variable name. |
| 62 | default_val: The default value to assign. |
| 63 | help_str: The help string for the input argument. |
| 64 | deprecation_note: A deprecation note to use. |
| 65 | alternate_name: Alternate argument to be used after deprecation. |
| 66 | """ |
| 67 | arg = f"--{name}" |
| 68 | shell_narg = f"--no{name}" |
| 69 | py_narg = f"--no-{name}" |
| 70 | alt_arg = f"--{alternate_name}" if alternate_name else None |
| 71 | alt_py_narg = f"--no-{alternate_name}" if alternate_name else None |
| 72 | default_val_str = f"{help_str} (Default: %(default)s)." |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 73 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 74 | if alternate_name: |
| 75 | parser.add_argument( |
| 76 | alt_arg, |
| 77 | action="store_true", |
| 78 | default=default_val, |
| 79 | dest=name, |
| 80 | help=default_val_str, |
| 81 | ) |
| 82 | parser.add_argument( |
| 83 | alt_py_narg, |
| 84 | action="store_false", |
| 85 | dest=name, |
| 86 | help="Don't " + help_str.lower(), |
| 87 | ) |
| 88 | |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 89 | parser.add_argument( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 90 | arg, |
| 91 | action="store_true", |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 92 | default=default_val, |
| 93 | dest=name, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 94 | deprecated=deprecation_note % alt_arg if alternate_name else None, |
| 95 | help=default_val_str if not alternate_name else argparse.SUPPRESS, |
| 96 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 97 | parser.add_argument( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 98 | shell_narg, |
| 99 | action="store_false", |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 100 | dest=name, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 101 | deprecated=deprecation_note % alt_py_narg |
| 102 | if alternate_name |
| 103 | else py_narg, |
| 104 | help=argparse.SUPPRESS, |
| 105 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 106 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 107 | if not alternate_name: |
| 108 | parser.add_argument( |
| 109 | py_narg, |
| 110 | action="store_false", |
| 111 | dest=name, |
| 112 | help="Don't " + help_str.lower(), |
| 113 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 114 | |
| 115 | |
| 116 | def get_parser() -> commandline.ArgumentParser: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 117 | """Creates the cmdline argparser, populates the options and description. |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 118 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 119 | Returns: |
| 120 | Argument parser. |
| 121 | """ |
| 122 | deprecation_note = "Argument will be removed July, 2022. Use %s instead." |
| 123 | parser = commandline.ArgumentParser(description=__doc__) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 124 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 125 | parser.add_argument( |
| 126 | "-b", |
| 127 | "--board", |
| 128 | "--build-target", |
| 129 | dest="board", |
| 130 | default=cros_build_lib.GetDefaultBoard(), |
| 131 | help="The board to build packages for.", |
| 132 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 133 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 134 | build_shell_bool_style_args( |
| 135 | parser, |
| 136 | "usepkg", |
| 137 | True, |
| 138 | "Use binary packages to bootstrap when possible.", |
| 139 | deprecation_note, |
| 140 | ) |
| 141 | build_shell_bool_style_args( |
| 142 | parser, |
| 143 | "usepkgonly", |
| 144 | False, |
| 145 | "Use binary packages only to bootstrap; abort if any are missing.", |
| 146 | deprecation_note, |
| 147 | ) |
| 148 | build_shell_bool_style_args( |
| 149 | parser, "workon", True, "Force-build workon packages.", deprecation_note |
| 150 | ) |
| 151 | build_shell_bool_style_args( |
| 152 | parser, |
| 153 | "withrevdeps", |
| 154 | True, |
| 155 | "Calculate reverse dependencies on changed ebuilds.", |
| 156 | deprecation_note, |
| 157 | ) |
| 158 | build_shell_bool_style_args( |
| 159 | parser, |
| 160 | "cleanbuild", |
| 161 | False, |
| 162 | "Perform a clean build; delete sysroot if it exists before building.", |
| 163 | deprecation_note, |
| 164 | ) |
| 165 | build_shell_bool_style_args( |
| 166 | parser, |
| 167 | "pretend", |
| 168 | False, |
| 169 | "Pretend building packages, just display which packages would have " |
| 170 | "been installed.", |
| 171 | deprecation_note, |
| 172 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 173 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 174 | # The --sysroot flag specifies the environment variables ROOT and PKGDIR. |
| 175 | # This allows fetching and emerging of all packages to specified sysroot. |
| 176 | # Note that --sysroot will setup the board normally in /build/$BOARD, if |
| 177 | # it's not setup yet. It also expects the toolchain to already be installed |
| 178 | # in the sysroot. |
| 179 | # --usepkgonly and --norebuild are required, because building is not |
| 180 | # supported when board_root is set. |
| 181 | parser.add_argument( |
| 182 | "--sysroot", type="path", help="Emerge packages to sysroot." |
| 183 | ) |
| 184 | parser.add_argument( |
| 185 | "--board_root", |
| 186 | type="path", |
| 187 | dest="sysroot", |
| 188 | deprecated=deprecation_note % "--sysroot", |
| 189 | help=argparse.SUPPRESS, |
| 190 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 191 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 192 | # CPU Governor related options. |
| 193 | group = parser.add_argument_group("CPU Governor Options") |
| 194 | build_shell_bool_style_args( |
| 195 | group, |
| 196 | "autosetgov", |
| 197 | False, |
| 198 | "Automatically set cpu governor to 'performance'.", |
| 199 | deprecation_note, |
| 200 | ) |
| 201 | build_shell_bool_style_args( |
| 202 | group, |
| 203 | "autosetgov_sticky", |
| 204 | False, |
| 205 | "Remember --autosetgov setting for future runs.", |
| 206 | deprecation_note, |
| 207 | alternate_name="autosetgov-sticky", |
| 208 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 209 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 210 | # Chrome building related options. |
| 211 | group = parser.add_argument_group("Chrome Options") |
| 212 | build_shell_bool_style_args( |
| 213 | group, |
| 214 | "use_any_chrome", |
| 215 | True, |
| 216 | "Use any Chrome prebuilt available, even if the prebuilt doesn't " |
| 217 | "match exactly.", |
| 218 | deprecation_note, |
| 219 | alternate_name="use-any-chrome", |
| 220 | ) |
| 221 | build_shell_bool_style_args( |
| 222 | group, |
| 223 | "internal", |
| 224 | False, |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame^] | 225 | "Build the internal version of chrome (set the chrome_internal USE " |
| 226 | "flag).", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 227 | deprecation_note, |
| 228 | ) |
| 229 | build_shell_bool_style_args( |
| 230 | group, |
| 231 | "chrome", |
| 232 | False, |
| 233 | "Ensure chrome instead of chromium. Alias for " |
| 234 | "--internal --no-use-any-chrome.", |
| 235 | deprecation_note, |
| 236 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 237 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 238 | # Setup board related options. |
| 239 | group = parser.add_argument_group("Setup Board Config Options") |
| 240 | build_shell_bool_style_args( |
| 241 | group, |
| 242 | "skip_chroot_upgrade", |
| 243 | False, |
| 244 | "Skip the automatic chroot upgrade; use with care.", |
| 245 | deprecation_note, |
| 246 | alternate_name="skip-chroot-upgrade", |
| 247 | ) |
| 248 | build_shell_bool_style_args( |
| 249 | group, |
| 250 | "skip_toolchain_update", |
| 251 | False, |
| 252 | "Skip automatic toolchain update", |
| 253 | deprecation_note, |
| 254 | alternate_name="skip-toolchain-update", |
| 255 | ) |
| 256 | build_shell_bool_style_args( |
| 257 | group, |
| 258 | "skip_setup_board", |
| 259 | False, |
| 260 | "Skip running setup_board. Implies " |
| 261 | "--skip-chroot-upgrade --skip-toolchain-update.", |
| 262 | deprecation_note, |
| 263 | alternate_name="skip-setup-board", |
| 264 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 265 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 266 | # Image Type selection related options. |
| 267 | group = parser.add_argument_group("Image Type Options") |
| 268 | build_shell_bool_style_args( |
| 269 | group, |
| 270 | "withdev", |
| 271 | True, |
| 272 | "Build useful developer friendly utilities.", |
| 273 | deprecation_note, |
| 274 | ) |
| 275 | build_shell_bool_style_args( |
| 276 | group, |
| 277 | "withdebug", |
| 278 | True, |
| 279 | "Build debug versions of Chromium-OS-specific packages.", |
| 280 | deprecation_note, |
| 281 | ) |
| 282 | build_shell_bool_style_args( |
| 283 | group, "withfactory", True, "Build factory installer.", deprecation_note |
| 284 | ) |
| 285 | build_shell_bool_style_args( |
| 286 | group, |
| 287 | "withtest", |
| 288 | True, |
| 289 | "Build packages required for testing.", |
| 290 | deprecation_note, |
| 291 | ) |
| 292 | build_shell_bool_style_args( |
| 293 | group, |
| 294 | "withautotest", |
| 295 | True, |
| 296 | "Build autotest client code.", |
| 297 | deprecation_note, |
| 298 | ) |
| 299 | build_shell_bool_style_args( |
| 300 | group, |
| 301 | "withdebugsymbols", |
| 302 | False, |
| 303 | "Install the debug symbols for all packages.", |
| 304 | deprecation_note, |
| 305 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 306 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 307 | # Advanced Options. |
| 308 | group = parser.add_argument_group("Advanced Options") |
| 309 | group.add_argument( |
| 310 | "--accept-licenses", help="Licenses to append to the accept list." |
| 311 | ) |
| 312 | group.add_argument( |
| 313 | "--accept_licenses", |
| 314 | deprecated=deprecation_note % "--accept-licenses", |
| 315 | help=argparse.SUPPRESS, |
| 316 | ) |
| 317 | build_shell_bool_style_args( |
| 318 | group, |
| 319 | "eclean", |
| 320 | True, |
| 321 | "Run eclean to delete old binpkgs.", |
| 322 | deprecation_note, |
| 323 | ) |
| 324 | group.add_argument( |
| 325 | "--jobs", |
| 326 | type=int, |
| 327 | default=os.cpu_count(), |
| 328 | help="Number of packages to build in parallel. " |
| 329 | "(Default: %(default)s)", |
| 330 | ) |
| 331 | build_shell_bool_style_args( |
| 332 | group, |
| 333 | "rebuild", |
| 334 | True, |
| 335 | "Automatically rebuild dependencies.", |
| 336 | deprecation_note, |
| 337 | ) |
| 338 | # TODO(b/218522717): Remove the --nonorebuild argument support. |
| 339 | group.add_argument( |
| 340 | "--nonorebuild", |
| 341 | action="store_true", |
| 342 | dest="rebuild", |
| 343 | deprecated=deprecation_note % "--rebuild", |
| 344 | help=argparse.SUPPRESS, |
| 345 | ) |
| 346 | build_shell_bool_style_args( |
| 347 | group, |
| 348 | "expandedbinhosts", |
| 349 | True, |
| 350 | "Allow expanded binhost inheritance.", |
| 351 | deprecation_note, |
| 352 | ) |
| 353 | group.add_argument( |
| 354 | "--backtrack", |
| 355 | type=int, |
| 356 | default=sysroot.BACKTRACK_DEFAULT, |
| 357 | help="See emerge --backtrack.", |
| 358 | ) |
Alex Klein | 062d728 | 2022-07-28 09:03:26 -0600 | [diff] [blame] | 359 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 360 | # The --reuse-pkgs-from-local-boards flag tells Portage to share binary |
| 361 | # packages between boards that are built locally, so that the total time |
| 362 | # required to build several boards is reduced. This flag is only useful |
| 363 | # when you are not able to use remote binary packages, since remote binary |
| 364 | # packages are usually more up to date than anything you have locally. |
| 365 | build_shell_bool_style_args( |
| 366 | group, |
| 367 | "reuse_pkgs_from_local_boards", |
| 368 | False, |
| 369 | "Bootstrap from local packages instead of remote packages.", |
| 370 | deprecation_note, |
| 371 | alternate_name="reuse-pkgs-from-local-boards", |
| 372 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 373 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 374 | # --run-goma option is designed to be used on bots. |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame^] | 375 | # If you're trying to build packages with goma in your local dev env, this |
| 376 | # is *not* the option you're looking for. Please see comments below. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 377 | # This option; 1) starts goma, 2) builds packages (expecting that goma is |
| 378 | # used), then 3) stops goma explicitly. |
| 379 | # 4) is a request from the goma team, so that stats/logs can be taken. |
Fumitoshi Ukai | 00becd4 | 2023-01-13 12:51:26 +0900 | [diff] [blame] | 380 | # Note: GOMA_DIR is expected to be passed via env var. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 381 | # |
| 382 | # In local dev env cases, compiler_proxy is expected to keep running. |
| 383 | # In such a case; |
| 384 | # $ python ${GOMA_DIR}/goma_ctl.py ensure_start |
| 385 | # $ build_packages (... and options without --run-goma ...) |
| 386 | # is an expected commandline sequence. If you set --run-goma flag while |
| 387 | # compiler_proxy is already running, the existing compiler_proxy will be |
| 388 | # stopped. |
| 389 | build_shell_bool_style_args( |
| 390 | group, |
| 391 | "run_goma", |
| 392 | False, |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame^] | 393 | "When set, (re)starts goma, builds packages, and then stops goma.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 394 | deprecation_note, |
| 395 | alternate_name="run-goma", |
| 396 | ) |
| 397 | # This option is for building chrome remotely. |
| 398 | # 1) starts reproxy 2) builds chrome with reproxy and 3) stops reproxy so |
| 399 | # logs/stats can be collected. |
| 400 | # Note: RECLIENT_DIR and REPROXY_CFG env var will be deprecated July, 2022. |
| 401 | # Use --reclient-dir and --reproxy-cfg input options instead. |
| 402 | build_shell_bool_style_args( |
| 403 | group, |
| 404 | "run_remoteexec", |
| 405 | False, |
| 406 | "If set to true, starts RBE reproxy, builds packages, and then stops " |
| 407 | "reproxy.", |
| 408 | deprecation_note, |
| 409 | ) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 410 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 411 | parser.add_argument("packages", nargs="*", help="Packages to build.") |
| 412 | return parser |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 413 | |
| 414 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 415 | def parse_args( |
| 416 | argv: List[str], |
| 417 | ) -> Tuple[commandline.ArgumentParser, commandline.ArgumentNamespace]: |
| 418 | """Parse and validate CLI arguments. |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 419 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 420 | Args: |
| 421 | argv: Arguments passed via CLI. |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 422 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 423 | Returns: |
| 424 | Tuple having the below two, |
| 425 | Argument Parser |
| 426 | Validated argument namespace. |
| 427 | """ |
| 428 | parser = get_parser() |
| 429 | opts = parser.parse_args(argv) |
Ram Chandrasekar | bdec0f0 | 2022-02-24 01:20:17 +0000 | [diff] [blame] | 430 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 431 | if opts.chrome: |
| 432 | opts.internal_chrome = True |
| 433 | opts.use_any_chrome = False |
Ram Chandrasekar | bdec0f0 | 2022-02-24 01:20:17 +0000 | [diff] [blame] | 434 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 435 | opts.setup_board_run_config = sysroot.SetupBoardRunConfig( |
| 436 | force=opts.cleanbuild, |
| 437 | usepkg=opts.usepkg, |
| 438 | jobs=opts.jobs, |
| 439 | quiet=True, |
| 440 | update_toolchain=not opts.skip_toolchain_update, |
| 441 | upgrade_chroot=not opts.skip_chroot_upgrade, |
| 442 | local_build=opts.reuse_pkgs_from_local_boards, |
| 443 | expanded_binhost_inheritance=opts.expandedbinhosts, |
| 444 | backtrack=opts.backtrack, |
| 445 | ) |
| 446 | opts.build_run_config = sysroot.BuildPackagesRunConfig( |
| 447 | usepkg=opts.usepkg, |
| 448 | install_debug_symbols=opts.withdebugsymbols, |
| 449 | packages=opts.packages, |
| 450 | use_goma=opts.run_goma, |
| 451 | use_remoteexec=opts.run_remoteexec, |
| 452 | incremental_build=opts.withrevdeps, |
| 453 | dryrun=opts.pretend, |
| 454 | usepkgonly=opts.usepkgonly, |
| 455 | workon=opts.workon, |
| 456 | install_auto_test=opts.withautotest, |
| 457 | autosetgov=opts.autosetgov, |
| 458 | autosetgov_sticky=opts.autosetgov_sticky, |
| 459 | use_any_chrome=opts.use_any_chrome, |
| 460 | internal_chrome=opts.internal, |
| 461 | clean_build=opts.cleanbuild, |
| 462 | eclean=opts.eclean, |
| 463 | rebuild_dep=opts.rebuild, |
| 464 | jobs=opts.jobs, |
| 465 | local_pkg=opts.reuse_pkgs_from_local_boards, |
| 466 | dev_image=opts.withdev, |
| 467 | factory_image=opts.withfactory, |
| 468 | test_image=opts.withtest, |
| 469 | debug_version=opts.withdebug, |
| 470 | backtrack=opts.backtrack, |
| 471 | ) |
| 472 | opts.Freeze() |
| 473 | return parser, opts |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 474 | |
| 475 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 476 | @timer.timed("Elapsed time (build_packages)") |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 477 | def main(argv: Optional[List[str]] = None) -> Optional[int]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 478 | commandline.RunInsideChroot() |
| 479 | parser, opts = parse_args(argv) |
Ram Chandrasekar | baa8963 | 2022-02-11 23:22:09 +0000 | [diff] [blame] | 480 | |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame^] | 481 | # If the opts.board is not set, then it means user hasn't specified a |
| 482 | # default board in 'src/scripts/.default_board' and didn't specify it as |
| 483 | # input argument. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 484 | if not opts.board: |
| 485 | parser.error("--board is required") |
Ram Chandrasekar | bdec0f0 | 2022-02-24 01:20:17 +0000 | [diff] [blame] | 486 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 487 | build_target = build_target_lib.BuildTarget( |
| 488 | opts.board, build_root=opts.sysroot |
| 489 | ) |
| 490 | board_root = sysroot_lib.Sysroot(build_target.root) |
Cindy Lin | 7487daa | 2022-02-23 04:14:10 +0000 | [diff] [blame] | 491 | |
Alex Klein | fba23ba | 2022-02-03 11:58:48 -0700 | [diff] [blame] | 492 | try: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 493 | # TODO(xcl): Update run_configs to have a common base set of configs for |
| 494 | # setup_board and build_packages. |
| 495 | if not opts.skip_setup_board: |
| 496 | sysroot.SetupBoard( |
| 497 | build_target, |
| 498 | accept_licenses=opts.accept_licenses, |
| 499 | run_configs=opts.setup_board_run_config, |
| 500 | ) |
Sergey Frolov | f988de7 | 2023-03-06 20:05:21 -0700 | [diff] [blame] | 501 | |
| 502 | if os.path.isfile(chromite_config.AUTO_COP_CONFIG): |
| 503 | cop_command = [ |
| 504 | "cros", |
| 505 | "clean-outdated-pkgs", |
| 506 | f"--board={opts.board}", |
| 507 | ] |
| 508 | # Set check=False to allow cop to fail. |
| 509 | cros_build_lib.sudo_run( |
| 510 | cop_command, |
| 511 | preserve_env=True, |
| 512 | check=False, |
| 513 | ) |
| 514 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 515 | sysroot.BuildPackages(build_target, board_root, opts.build_run_config) |
| 516 | except sysroot_lib.PackageInstallError as e: |
| 517 | try: |
| 518 | with urllib.request.urlopen( |
| 519 | "https://chromiumos-status.appspot.com/current?format=raw" |
Sergey Frolov | 7cf6c0b | 2022-06-06 16:47:44 -0600 | [diff] [blame] | 520 | ) as request: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 521 | logging.notice("Tree Status: %s", request.read().decode()) |
| 522 | except urllib.error.HTTPError: |
| 523 | pass |
| 524 | cros_build_lib.Die(e) |