Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2012 The ChromiumOS Authors |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [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 | """Main builder code for Chromium OS. |
| 6 | |
| 7 | Used by Chromium OS buildbot configuration for all Chromium OS builds including |
| 8 | full and pre-flight-queue builds. |
| 9 | """ |
| 10 | |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 11 | import contextlib |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 12 | import distutils.version # pylint: disable=import-error,no-name-in-module |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 13 | import glob |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 14 | import json |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 15 | import logging |
Mike Frysinger | b0b0caa | 2015-11-07 01:05:18 -0500 | [diff] [blame] | 16 | import optparse # pylint: disable=deprecated-module |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 17 | import os |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 18 | import pickle |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 19 | import sys |
Mike Frysinger | ace4eae | 2023-05-26 21:09:43 -0400 | [diff] [blame] | 20 | import tempfile |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 21 | |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 22 | from chromite.cbuildbot import builders |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 23 | from chromite.cbuildbot import cbuildbot_alerts |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 24 | from chromite.cbuildbot import cbuildbot_run |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 25 | from chromite.cbuildbot import repository |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 26 | from chromite.cbuildbot import topology |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 27 | from chromite.cbuildbot.stages import completion_stages |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 28 | from chromite.cbuildbot.stages import test_stages |
Ningning Xia | f342b95 | 2017-02-15 14:13:33 -0800 | [diff] [blame] | 29 | from chromite.lib import builder_status_lib |
Brian Harring | c92a701 | 2012-02-29 10:11:34 -0800 | [diff] [blame] | 30 | from chromite.lib import cgroups |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 31 | from chromite.lib import cidb |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 32 | from chromite.lib import cleanup |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 33 | from chromite.lib import commandline |
Ningning Xia | 6a71805 | 2016-12-22 10:08:15 -0800 | [diff] [blame] | 34 | from chromite.lib import config_lib |
| 35 | from chromite.lib import constants |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 36 | from chromite.lib import cros_build_lib |
Ningning Xia | 6a71805 | 2016-12-22 10:08:15 -0800 | [diff] [blame] | 37 | from chromite.lib import failures_lib |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 38 | from chromite.lib import git |
Stefan Zager | d49d9ff | 2014-08-15 21:33:37 -0700 | [diff] [blame] | 39 | from chromite.lib import gob_util |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 40 | from chromite.lib import osutils |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 41 | from chromite.lib import parallel |
Don Garrett | b431836 | 2014-10-03 15:49:36 -0700 | [diff] [blame] | 42 | from chromite.lib import retry_stats |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 43 | from chromite.lib import sudo |
Michael Mortensen | 3e86c1e | 2019-11-21 15:51:54 -0700 | [diff] [blame] | 44 | from chromite.lib import tee |
David James | 3432acd | 2013-11-27 10:02:18 -0800 | [diff] [blame] | 45 | from chromite.lib import timeout_util |
Paul Hobbs | fcf1034 | 2015-12-29 15:52:31 -0800 | [diff] [blame] | 46 | from chromite.lib import ts_mon_config |
Dhanya Ganesh | 39a48a8 | 2018-12-06 16:01:11 -0700 | [diff] [blame] | 47 | from chromite.lib.buildstore import BuildStore |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 48 | |
Ryan Cui | add4912 | 2012-03-21 22:19:58 -0700 | [diff] [blame] | 49 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 50 | _DEFAULT_LOG_DIR = "cbuildbot_logs" |
| 51 | _BUILDBOT_LOG_FILE = "cbuildbot.log" |
| 52 | _DEFAULT_EXT_BUILDROOT = "trybot" |
| 53 | _DEFAULT_INT_BUILDROOT = "trybot-internal" |
| 54 | _BUILDBOT_REQUIRED_BINARIES = ("pbzip2",) |
| 55 | _API_VERSION_ATTR = "api_version" |
| 56 | BOARD_DIM_LABEL = "label-board" |
| 57 | MODEL_DIM_LABEL = "label-model" |
| 58 | POOL_DIM_LABEL = "label-pool" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 59 | |
| 60 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 61 | def _BackupPreviousLog(log_file, backup_limit=25): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 62 | """Rename previous log. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 63 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 64 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 65 | log_file: The absolute path to the previous log. |
| 66 | backup_limit: Maximum number of old logs to keep. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 67 | """ |
| 68 | if os.path.exists(log_file): |
| 69 | old_logs = sorted( |
| 70 | glob.glob(log_file + ".*"), key=distutils.version.LooseVersion |
| 71 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 72 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 73 | if len(old_logs) >= backup_limit: |
| 74 | os.remove(old_logs[0]) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 75 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 76 | last = 0 |
| 77 | if old_logs: |
| 78 | last = int(old_logs.pop().rpartition(".")[2]) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 79 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 80 | os.rename(log_file, log_file + "." + str(last + 1)) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 81 | |
Ryan Cui | 5616a51 | 2012-08-17 13:39:36 -0700 | [diff] [blame] | 82 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 83 | def _IsDistributedBuilder(options, chrome_rev, build_config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 84 | """Determines whether the builder should be a DistributedBuilder. |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 85 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 86 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 87 | options: options passed on the commandline. |
| 88 | chrome_rev: Chrome revision to build. |
| 89 | build_config: Builder configuration dictionary. |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 90 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 91 | Returns: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 92 | True if the builder should be a distributed_builder |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 93 | """ |
| 94 | if not options.buildbot: |
| 95 | return False |
| 96 | elif chrome_rev in ( |
| 97 | constants.CHROME_REV_TOT, |
| 98 | constants.CHROME_REV_LOCAL, |
| 99 | constants.CHROME_REV_SPEC, |
| 100 | ): |
| 101 | # We don't do distributed logic to TOT Chrome PFQ's, nor local |
| 102 | # chrome roots (e.g. chrome try bots) |
| 103 | # TODO(davidjames): Update any builders that rely on this logic to use |
| 104 | # manifest_version=False instead. |
| 105 | return False |
| 106 | elif build_config["manifest_version"]: |
| 107 | return True |
| 108 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 109 | return False |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 110 | |
| 111 | |
Don Garrett | a52a5b0 | 2015-06-02 14:52:57 -0700 | [diff] [blame] | 112 | def _RunBuildStagesWrapper(options, site_config, build_config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 113 | """Helper function that wraps RunBuildStages().""" |
| 114 | logging.info( |
| 115 | "cbuildbot was executed with args %s", cros_build_lib.CmdToStr(sys.argv) |
| 116 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 117 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 118 | chrome_rev = build_config["chrome_rev"] |
| 119 | if options.chrome_rev: |
| 120 | chrome_rev = options.chrome_rev |
| 121 | if chrome_rev == constants.CHROME_REV_TOT: |
| 122 | options.chrome_version = gob_util.GetTipOfTrunkRevision( |
| 123 | constants.CHROMIUM_GOB_URL |
| 124 | ) |
| 125 | options.chrome_rev = constants.CHROME_REV_SPEC |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 126 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 127 | # If it's likely we'll need to build Chrome, fetch the source. |
| 128 | if build_config["sync_chrome"] is None: |
| 129 | options.managed_chrome = chrome_rev != constants.CHROME_REV_LOCAL and ( |
| 130 | not build_config["usepkg_build_packages"] |
| 131 | or chrome_rev |
| 132 | or build_config["profile"] |
| 133 | ) |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 134 | else: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 135 | options.managed_chrome = build_config["sync_chrome"] |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 136 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | chrome_root_mgr = None |
| 138 | if options.managed_chrome: |
| 139 | # Create a temp directory for syncing Chrome source. |
| 140 | chrome_root_mgr = osutils.TempDir(prefix="chrome_root_") |
| 141 | options.chrome_root = chrome_root_mgr.tempdir |
| 142 | |
| 143 | # We are done munging options values, so freeze options object now to avoid |
| 144 | # further abuse of it. |
| 145 | # TODO(mtennant): one by one identify each options value override and see if |
| 146 | # it can be handled another way. Try to push this freeze closer and closer |
| 147 | # to the start of the script (e.g. in or after _PostParseCheck). |
| 148 | options.Freeze() |
| 149 | |
| 150 | metadata_dump_dict = { |
| 151 | # A detected default has been set before now if it wasn't explicit. |
| 152 | "branch": options.branch, |
| 153 | } |
| 154 | if options.metadata_dump: |
Mike Frysinger | 31fdddd | 2023-02-24 15:50:55 -0500 | [diff] [blame] | 155 | with open(options.metadata_dump, "rb") as metadata_file: |
| 156 | metadata_dump_dict = json.load(metadata_file) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 157 | |
| 158 | with parallel.Manager() as manager: |
| 159 | builder_run = cbuildbot_run.BuilderRun( |
| 160 | options, site_config, build_config, manager |
| 161 | ) |
| 162 | buildstore = BuildStore() |
| 163 | if metadata_dump_dict: |
| 164 | builder_run.attrs.metadata.UpdateWithDict(metadata_dump_dict) |
| 165 | |
| 166 | if builder_run.config.builder_class_name is None: |
| 167 | # TODO: This should get relocated to chromeos_config. |
| 168 | if _IsDistributedBuilder(options, chrome_rev, build_config): |
| 169 | builder_cls_name = "simple_builders.DistributedBuilder" |
| 170 | else: |
| 171 | builder_cls_name = "simple_builders.SimpleBuilder" |
| 172 | builder_cls = builders.GetBuilderClass(builder_cls_name) |
| 173 | builder = builder_cls(builder_run, buildstore) |
| 174 | else: |
| 175 | builder = builders.Builder(builder_run, buildstore) |
| 176 | |
| 177 | try: |
| 178 | if not builder.Run(): |
| 179 | sys.exit(1) |
| 180 | finally: |
| 181 | if chrome_root_mgr: |
| 182 | chrome_root_mgr.Cleanup() |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 183 | |
| 184 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 185 | def _CheckChromeVersionOption(_option, _opt_str, value, parser): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | """Upgrade other options based on chrome_version being passed.""" |
| 187 | value = value.strip() |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 188 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 189 | if parser.values.chrome_rev is None and value: |
| 190 | parser.values.chrome_rev = constants.CHROME_REV_SPEC |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 191 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 192 | parser.values.chrome_version = value |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 193 | |
| 194 | |
| 195 | def _CheckChromeRootOption(_option, _opt_str, value, parser): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 196 | """Validate and convert chrome_root to full-path form.""" |
| 197 | if parser.values.chrome_rev is None: |
| 198 | parser.values.chrome_rev = constants.CHROME_REV_LOCAL |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 199 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 200 | parser.values.chrome_root = value |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 201 | |
| 202 | |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 203 | def FindCacheDir(_parser, _options): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 204 | return None |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 205 | |
| 206 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 207 | class CustomGroup(optparse.OptionGroup): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 208 | """Custom option group which supports arguments passed-through to trybot.""" |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 209 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 210 | def add_remote_option(self, *args, **kwargs): |
| 211 | """For arguments that are passed-through to remote trybot.""" |
| 212 | return optparse.OptionGroup.add_option( |
| 213 | self, *args, remote_pass_through=True, **kwargs |
| 214 | ) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 215 | |
| 216 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 217 | class CustomOption(commandline.FilteringOption): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 218 | """Subclass FilteringOption class to implement pass-through and api.""" |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 219 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 220 | def __init__(self, *args, **kwargs): |
| 221 | # The remote_pass_through argument specifies whether we should directly |
| 222 | # pass the argument (with its value) onto the remote trybot. |
| 223 | self.pass_through = kwargs.pop("remote_pass_through", False) |
| 224 | self.api_version = int(kwargs.pop("api", "0")) |
| 225 | commandline.FilteringOption.__init__(self, *args, **kwargs) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 226 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 227 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 228 | class CustomParser(commandline.FilteringParser): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 229 | """Custom option parser which supports arguments passed-through to trybot""" |
Matt Tennant | e817904 | 2013-10-01 15:47:32 -0700 | [diff] [blame] | 230 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 231 | DEFAULT_OPTION_CLASS = CustomOption |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 232 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 233 | def add_remote_option(self, *args, **kwargs): |
| 234 | """For arguments that are passed-through to remote trybot.""" |
| 235 | return self.add_option(*args, remote_pass_through=True, **kwargs) |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 236 | |
| 237 | |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 238 | def CreateParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 239 | """Expose _CreateParser publicly.""" |
| 240 | # Name _CreateParser is needed for commandline library. |
| 241 | return _CreateParser() |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 242 | |
| 243 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 244 | def _CreateParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 245 | """Generate and return the parser with all the options.""" |
| 246 | # Parse options |
| 247 | usage = "usage: %prog [options] buildbot_config [buildbot_config ...]" |
| 248 | parser = CustomParser(usage=usage, caching=FindCacheDir) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 249 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 250 | # Main options |
| 251 | parser.add_remote_option( |
| 252 | "-b", |
| 253 | "--branch", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 254 | help=( |
| 255 | "The manifest branch to test. The branch to " |
| 256 | "check the buildroot out to." |
| 257 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 258 | ) |
| 259 | parser.add_option( |
| 260 | "-r", |
| 261 | "--buildroot", |
| 262 | type="path", |
| 263 | dest="buildroot", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 264 | help=( |
| 265 | "Root directory where source is checked out to, and " |
| 266 | "where the build occurs. For external build configs, " |
| 267 | "defaults to 'trybot' directory at top level of your " |
| 268 | "repo-managed checkout." |
| 269 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 270 | ) |
| 271 | parser.add_option( |
| 272 | "--workspace", |
| 273 | type="path", |
| 274 | api=constants.REEXEC_API_WORKSPACE, |
| 275 | help="Root directory for a secondary checkout .", |
| 276 | ) |
| 277 | parser.add_option( |
| 278 | "--bootstrap-dir", |
| 279 | type="path", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 280 | help=( |
| 281 | "Bootstrapping cbuildbot may involve checking out " |
| 282 | "multiple copies of chromite. All these checkouts " |
| 283 | "will be contained in the directory specified here. " |
Mike Frysinger | ace4eae | 2023-05-26 21:09:43 -0400 | [diff] [blame] | 284 | f"(Default: {tempfile.gettempdir()})" |
| 285 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 286 | ) |
| 287 | parser.add_remote_option( |
| 288 | "--android_rev", |
| 289 | type="choice", |
| 290 | choices=constants.VALID_ANDROID_REVISIONS, |
| 291 | help=( |
| 292 | "Revision of Android to use, of type [%s]" |
| 293 | % "|".join(constants.VALID_ANDROID_REVISIONS) |
| 294 | ), |
| 295 | ) |
| 296 | parser.add_remote_option( |
| 297 | "--chrome_rev", |
| 298 | type="choice", |
| 299 | choices=constants.VALID_CHROME_REVISIONS, |
| 300 | help=( |
| 301 | "Revision of Chrome to use, of type [%s]" |
| 302 | % "|".join(constants.VALID_CHROME_REVISIONS) |
| 303 | ), |
| 304 | ) |
| 305 | parser.add_remote_option( |
| 306 | "--profile", help="Name of profile to sub-specify board variant." |
| 307 | ) |
| 308 | # TODO(crbug.com/279618): Running GOMA is under development. Following |
| 309 | # flags are added for development purpose due to repository dependency, |
| 310 | # but not officially supported yet. |
| 311 | parser.add_option( |
| 312 | "--goma_dir", |
| 313 | type="path", |
| 314 | api=constants.REEXEC_API_GOMA, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 315 | help=( |
| 316 | "Specify a directory containing goma. When this is " |
| 317 | "set, GOMA is used to build Chrome." |
| 318 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 319 | ) |
| 320 | parser.add_option( |
| 321 | "--chromeos_goma_dir", |
| 322 | type="path", |
| 323 | api=constants.REEXEC_API_CHROMEOS_GOMA_DIR, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 324 | help="Specify a directory containing goma for build package.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 325 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 326 | group = CustomGroup(parser, "Deprecated Options") |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 327 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 328 | parser.add_option( |
| 329 | "--local", |
| 330 | action="store_true", |
| 331 | default=False, |
| 332 | help="Deprecated. See cros tryjob.", |
| 333 | ) |
| 334 | parser.add_option( |
| 335 | "--remote", |
| 336 | action="store_true", |
| 337 | default=False, |
| 338 | help="Deprecated. See cros tryjob.", |
| 339 | ) |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 340 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 341 | # |
| 342 | # Patch selection options. |
| 343 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 344 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 345 | group = CustomGroup(parser, "Patch Options") |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 346 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 347 | group.add_remote_option( |
| 348 | "-g", |
| 349 | "--gerrit-patches", |
| 350 | action="split_extend", |
| 351 | type="string", |
| 352 | default=[], |
| 353 | metavar="'Id1 *int_Id2...IdN'", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 354 | help=( |
| 355 | "Space-separated list of short-form Gerrit " |
| 356 | "Change-Id's or change numbers to patch. " |
| 357 | "Please prepend '*' to internal Change-Id's" |
| 358 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 359 | ) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 360 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 361 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 362 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 363 | # |
| 364 | # Remote trybot options. |
| 365 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 366 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 367 | group = CustomGroup(parser, "Options used to configure tryjob behavior.") |
| 368 | group.add_remote_option( |
| 369 | "--hwtest", |
| 370 | action="store_true", |
| 371 | default=False, |
| 372 | help="Run the HWTest stage (tests on real hardware)", |
| 373 | ) |
| 374 | group.add_option( |
| 375 | "--hwtest_dut_dimensions", |
| 376 | type="string", |
| 377 | action="split_extend", |
| 378 | default=None, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 379 | help=( |
| 380 | "Space-separated list of key:val Swarming bot " |
| 381 | "dimensions to run each builders SkylabHWTest " |
| 382 | "stages against (this overrides the configured " |
| 383 | "DUT dimensions for each test). Requires at least " |
| 384 | '"label-board", "label-model", and "label-pool".' |
| 385 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 386 | ) |
| 387 | group.add_remote_option( |
| 388 | "--channel", |
| 389 | action="split_extend", |
| 390 | dest="channels", |
| 391 | default=[], |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 392 | help=( |
| 393 | "Specify a channel for a payloads trybot. Can " |
| 394 | "be specified multiple times. No valid for " |
| 395 | "non-payloads configs." |
| 396 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 397 | ) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 398 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 399 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 400 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 401 | # |
| 402 | # Advanced options. |
| 403 | # |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 404 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 405 | group = CustomGroup( |
| 406 | parser, |
| 407 | "Advanced Options", |
| 408 | "Caution: use these options at your own risk.", |
| 409 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 410 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 411 | group.add_remote_option( |
| 412 | "--bootstrap-args", |
| 413 | action="append", |
| 414 | default=[], |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 415 | help=( |
| 416 | "Args passed directly to the bootstrap re-exec " |
| 417 | "to skip verification by the bootstrap code" |
| 418 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 419 | ) |
| 420 | group.add_remote_option( |
| 421 | "--buildbot", |
| 422 | action="store_true", |
| 423 | dest="buildbot", |
| 424 | default=False, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 425 | help=( |
| 426 | "This is running on a buildbot. " |
| 427 | "This can be used to make a build operate " |
| 428 | "like an official builder, e.g. generate " |
| 429 | "new version numbers and archive official " |
| 430 | "artifacts and such. This should only be " |
| 431 | "used if you are confident in what you are " |
| 432 | "doing, as it will make automated commits." |
| 433 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 434 | ) |
| 435 | parser.add_remote_option( |
| 436 | "--repo-cache", |
| 437 | type="path", |
| 438 | dest="_repo_cache", |
| 439 | help="Present for backwards compatibility, ignored.", |
| 440 | ) |
| 441 | group.add_remote_option( |
| 442 | "--no-buildbot-tags", |
| 443 | action="store_false", |
| 444 | dest="enable_buildbot_tags", |
| 445 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 446 | help=( |
| 447 | "Suppress buildbot specific tags from log " |
| 448 | "output. This is used to hide recursive " |
| 449 | "cbuilbot runs on the waterfall." |
| 450 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 451 | ) |
| 452 | group.add_remote_option( |
| 453 | "--buildnumber", type="int", default=0, help="build number" |
| 454 | ) |
| 455 | group.add_option( |
| 456 | "--chrome_root", |
| 457 | action="callback", |
| 458 | type="path", |
| 459 | callback=_CheckChromeRootOption, |
| 460 | help="Local checkout of Chrome to use.", |
| 461 | ) |
| 462 | group.add_remote_option( |
| 463 | "--chrome_version", |
| 464 | action="callback", |
| 465 | type="string", |
| 466 | dest="chrome_version", |
| 467 | callback=_CheckChromeVersionOption, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 468 | help=( |
| 469 | "Used with SPEC logic to force a particular " |
| 470 | "git revision of chrome rather than the " |
| 471 | "latest." |
| 472 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 473 | ) |
| 474 | group.add_remote_option( |
| 475 | "--clobber", |
| 476 | action="store_true", |
| 477 | default=False, |
| 478 | help="Clears an old checkout before syncing", |
| 479 | ) |
| 480 | group.add_remote_option( |
| 481 | "--latest-toolchain", |
| 482 | action="store_true", |
| 483 | default=False, |
| 484 | help="Use the latest toolchain.", |
| 485 | ) |
| 486 | parser.add_option( |
| 487 | "--log_dir", |
| 488 | dest="log_dir", |
| 489 | type="path", |
| 490 | help="Directory where logs are stored.", |
| 491 | ) |
| 492 | group.add_remote_option( |
| 493 | "--maxarchives", |
| 494 | type="int", |
| 495 | dest="max_archive_builds", |
| 496 | default=3, |
| 497 | help="Change the local saved build count limit.", |
| 498 | ) |
| 499 | parser.add_remote_option( |
| 500 | "--manifest-repo-url", help="Overrides the default manifest repo url." |
| 501 | ) |
| 502 | group.add_remote_option( |
| 503 | "--compilecheck", |
| 504 | action="store_true", |
| 505 | default=False, |
| 506 | help="Only verify compilation and unit tests.", |
| 507 | ) |
| 508 | group.add_remote_option( |
| 509 | "--noarchive", |
| 510 | action="store_false", |
| 511 | dest="archive", |
| 512 | default=True, |
| 513 | help="Don't run archive stage.", |
| 514 | ) |
| 515 | group.add_remote_option( |
| 516 | "--nobootstrap", |
| 517 | action="store_false", |
| 518 | dest="bootstrap", |
| 519 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 520 | help="Don't checkout and run from a standalone chromite repo.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 521 | ) |
| 522 | group.add_remote_option( |
| 523 | "--nobuild", |
| 524 | action="store_false", |
| 525 | dest="build", |
| 526 | default=True, |
| 527 | help="Don't actually build (for cbuildbot dev)", |
| 528 | ) |
| 529 | group.add_remote_option( |
| 530 | "--noclean", |
| 531 | action="store_false", |
| 532 | dest="clean", |
| 533 | default=True, |
| 534 | help="Don't clean the buildroot", |
| 535 | ) |
| 536 | group.add_remote_option( |
| 537 | "--nocgroups", |
| 538 | action="store_false", |
| 539 | dest="cgroups", |
| 540 | default=True, |
| 541 | help="Disable cbuildbots usage of cgroups.", |
| 542 | ) |
| 543 | group.add_remote_option( |
| 544 | "--nochromesdk", |
| 545 | action="store_false", |
| 546 | dest="chrome_sdk", |
| 547 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 548 | help=( |
| 549 | "Don't run the ChromeSDK stage which builds " |
| 550 | "Chrome outside of the chroot." |
| 551 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 552 | ) |
| 553 | group.add_remote_option( |
| 554 | "--noprebuilts", |
| 555 | action="store_false", |
| 556 | dest="prebuilts", |
| 557 | default=True, |
| 558 | help="Don't upload prebuilts.", |
| 559 | ) |
| 560 | group.add_remote_option( |
| 561 | "--nopatch", |
| 562 | action="store_false", |
| 563 | dest="postsync_patch", |
| 564 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 565 | help=( |
| 566 | "Don't run PatchChanges stage. This does not " |
| 567 | "disable patching in of chromite patches " |
| 568 | "during BootstrapStage." |
| 569 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 570 | ) |
| 571 | group.add_remote_option( |
| 572 | "--nopaygen", |
| 573 | action="store_false", |
| 574 | dest="paygen", |
| 575 | default=True, |
| 576 | help="Don't generate payloads.", |
| 577 | ) |
| 578 | group.add_remote_option( |
| 579 | "--noreexec", |
| 580 | action="store_false", |
| 581 | dest="postsync_reexec", |
| 582 | default=True, |
| 583 | help="Don't reexec into the buildroot after syncing.", |
| 584 | ) |
| 585 | group.add_remote_option( |
| 586 | "--nosdk", |
| 587 | action="store_true", |
| 588 | default=False, |
| 589 | help="Re-create the SDK from scratch.", |
| 590 | ) |
| 591 | group.add_remote_option( |
| 592 | "--nosync", |
| 593 | action="store_false", |
| 594 | dest="sync", |
| 595 | default=True, |
| 596 | help="Don't sync before building.", |
| 597 | ) |
| 598 | group.add_remote_option( |
| 599 | "--notests", |
| 600 | action="store_false", |
| 601 | dest="tests", |
| 602 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 603 | help=( |
| 604 | "Override values from buildconfig, run no " |
| 605 | "tests, and build no autotest and artifacts." |
| 606 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 607 | ) |
| 608 | group.add_remote_option( |
| 609 | "--novmtests", |
| 610 | action="store_false", |
| 611 | dest="vmtests", |
| 612 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 613 | help="Override values from buildconfig, run no vmtests.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 614 | ) |
| 615 | group.add_remote_option( |
| 616 | "--noimagetests", |
| 617 | action="store_false", |
| 618 | dest="image_test", |
| 619 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 620 | help="Override values from buildconfig and run no image tests.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 621 | ) |
| 622 | group.add_remote_option( |
| 623 | "--nouprev", |
| 624 | action="store_false", |
| 625 | dest="uprev", |
| 626 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 627 | help="Override values from buildconfig and never uprev.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 628 | ) |
| 629 | group.add_option( |
| 630 | "--reference-repo", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 631 | help=( |
| 632 | "Reuse git data stored in an existing repo " |
| 633 | "checkout. This can drastically reduce the network " |
| 634 | "time spent setting up the trybot checkout. By " |
| 635 | "default, if this option isn't given but cbuildbot " |
| 636 | "is invoked from a repo checkout, cbuildbot will " |
| 637 | "use the repo root." |
| 638 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 639 | ) |
| 640 | group.add_option( |
| 641 | "--resume", |
| 642 | action="store_true", |
| 643 | default=False, |
| 644 | help="Skip stages already successfully completed.", |
| 645 | ) |
| 646 | group.add_remote_option( |
| 647 | "--timeout", |
| 648 | type="int", |
| 649 | default=0, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 650 | help=( |
| 651 | "Specify the maximum amount of time this job " |
| 652 | "can run for, at which point the build will be " |
| 653 | "aborted. If set to zero, then there is no " |
| 654 | "timeout." |
| 655 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 656 | ) |
| 657 | group.add_remote_option( |
| 658 | "--version", |
| 659 | dest="force_version", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 660 | help=( |
| 661 | "Used with manifest logic. Forces use of this " |
| 662 | "version rather than create or get latest. " |
| 663 | "Examples: 4815.0.0-rc1, 4815.1.2" |
| 664 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 665 | ) |
| 666 | group.add_remote_option( |
| 667 | "--git-cache-dir", |
| 668 | type="path", |
| 669 | api=constants.REEXEC_API_GIT_CACHE_DIR, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 670 | help=( |
| 671 | "Specify the cache directory to store the " |
| 672 | "project caches populated by the git-cache " |
| 673 | "tool. Bootstrap the projects based on the git " |
| 674 | "cache files instead of fetching them directly " |
| 675 | "from the GoB servers." |
| 676 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 677 | ) |
| 678 | group.add_remote_option( |
| 679 | "--chrome-preload-dir", |
| 680 | type="path", |
| 681 | api=constants.REEXEC_API_CHROME_PRELOAD_DIR, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 682 | help=( |
| 683 | "Specify a preloaded chrome source cache " |
| 684 | "directory populated by the git-cache tool. " |
| 685 | "Bootstrap chrome based on the cached files " |
| 686 | "instead of fetching them directly from the GoB " |
| 687 | "servers. When both this argument and " |
| 688 | "--git-cache-dir are provided this value will " |
| 689 | "be preferred for the chrome source cache." |
| 690 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 691 | ) |
| 692 | group.add_remote_option( |
| 693 | "--source_cache", |
| 694 | action="store_true", |
| 695 | default=False, |
| 696 | help="Whether to utilize cache snapshot mounts.", |
| 697 | ) |
| 698 | group.add_remote_option( |
| 699 | "--debug-cidb", |
| 700 | action="store_true", |
| 701 | default=False, |
| 702 | help="Force Debug CIDB to be used.", |
| 703 | ) |
| 704 | # cbuildbot ChromeOS Findit options |
| 705 | group.add_remote_option( |
| 706 | "--cbb_build_packages", |
| 707 | action="split_extend", |
| 708 | dest="cbb_build_packages", |
| 709 | default=[], |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 710 | help=( |
| 711 | "Specify an explicit list of packages to build " |
| 712 | "for integration with Findit." |
| 713 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 714 | ) |
| 715 | group.add_remote_option( |
| 716 | "--cbb_snapshot_revision", |
| 717 | type="string", |
| 718 | dest="cbb_snapshot_revision", |
| 719 | default=None, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 720 | help="Snapshot manifest revision to sync to for building.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 721 | ) |
| 722 | group.add_remote_option( |
| 723 | "--no-publish-prebuilt-confs", |
| 724 | dest="publish", |
| 725 | action="store_false", |
| 726 | default=True, |
| 727 | help="Don't publish git commits to prebuilt.conf or sdk_version.conf", |
| 728 | ) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 729 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 730 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 731 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 732 | # |
| 733 | # Internal options. |
| 734 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 735 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 736 | group = CustomGroup( |
| 737 | parser, |
| 738 | "Internal Chromium OS Build Team Options", |
| 739 | "Caution: these are for meant for the Chromium OS build team only", |
| 740 | ) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 741 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 742 | group.add_remote_option( |
| 743 | "--archive-base", |
| 744 | type="gs_path", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 745 | help=( |
| 746 | "Base GS URL (gs://<bucket_name>/<path>) to " |
| 747 | "upload archive artifacts to" |
| 748 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 749 | ) |
| 750 | group.add_remote_option( |
| 751 | "--cq-gerrit-query", |
| 752 | dest="cq_gerrit_override", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 753 | help=( |
| 754 | "If given, this gerrit query will be used to find what patches to " |
| 755 | "test, rather than the normal 'CommitQueue>=1 AND Verified=1 AND " |
| 756 | "CodeReview=2' query it defaults to. Use with care- note " |
| 757 | "additionally this setting only has an effect if the buildbot " |
| 758 | "target is a cq target, and we're in buildbot mode." |
| 759 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 760 | ) |
| 761 | group.add_option( |
| 762 | "--pass-through", |
| 763 | action="append", |
| 764 | type="string", |
| 765 | dest="pass_through_args", |
| 766 | default=[], |
| 767 | ) |
| 768 | group.add_option( |
| 769 | "--reexec-api-version", |
| 770 | action="store_true", |
| 771 | dest="output_api_version", |
| 772 | default=False, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 773 | help=( |
| 774 | "Used for handling forwards/backwards compatibility " |
| 775 | "with --resume and --bootstrap" |
| 776 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 777 | ) |
| 778 | group.add_option( |
| 779 | "--remote-trybot", |
| 780 | action="store_true", |
| 781 | default=False, |
| 782 | help="Indicates this is running on a remote trybot machine", |
| 783 | ) |
| 784 | group.add_option( |
| 785 | "--buildbucket-id", |
| 786 | api=constants.REEXEC_API_GOMA, # Approximate. |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 787 | help=( |
| 788 | "The unique ID in buildbucket of current build " |
| 789 | "generated by buildbucket." |
| 790 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 791 | ) |
| 792 | group.add_remote_option( |
| 793 | "--remote-patches", |
| 794 | action="split_extend", |
| 795 | default=[], |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 796 | help=( |
| 797 | "Patches uploaded by the trybot client when run using the -p option" |
| 798 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 799 | ) |
| 800 | # Note the default here needs to be hardcoded to 3; that is the last version |
| 801 | # that lacked this functionality. |
| 802 | group.add_option( |
| 803 | "--remote-version", |
| 804 | type="int", |
| 805 | default=3, |
| 806 | help="Deprecated and ignored.", |
| 807 | ) |
| 808 | group.add_option("--sourceroot", type="path", default=constants.SOURCE_ROOT) |
| 809 | group.add_remote_option( |
| 810 | "--test-bootstrap", |
| 811 | action="store_true", |
| 812 | default=False, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 813 | help=( |
| 814 | "Causes cbuildbot to bootstrap itself twice, " |
| 815 | "in the sequence A->B->C: A(unpatched) patches " |
| 816 | "and bootstraps B; B patches and bootstraps C" |
| 817 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 818 | ) |
| 819 | group.add_remote_option( |
| 820 | "--validation_pool", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 821 | help=( |
| 822 | "Path to a pickled validation pool. Intended " |
| 823 | "for use only with the commit queue." |
| 824 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 825 | ) |
| 826 | group.add_remote_option( |
| 827 | "--metadata_dump", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 828 | help=( |
| 829 | "Path to a json dumped metadata file. This " |
| 830 | "will be used as the initial metadata." |
| 831 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 832 | ) |
| 833 | group.add_remote_option( |
| 834 | "--master-build-id", |
| 835 | type="int", |
| 836 | api=constants.REEXEC_API_MASTER_BUILD_ID, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 837 | help="cidb build id of the master build to this slave build.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 838 | ) |
| 839 | group.add_remote_option( |
| 840 | "--master-buildbucket-id", |
| 841 | api=constants.REEXEC_API_MASTER_BUILDBUCKET_ID, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 842 | help="buildbucket id of the master build to this slave build.", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 843 | ) |
| 844 | # TODO(nxia): crbug.com/778838 |
| 845 | # cbuildbot doesn't use pickle files anymore, remove this. |
| 846 | group.add_remote_option( |
| 847 | "--mock-slave-status", |
| 848 | metavar="MOCK_SLAVE_STATUS_PICKLE_FILE", |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 849 | help=( |
| 850 | "Override the result of the _FetchSlaveStatuses " |
| 851 | "method of MasterSlaveSyncCompletionStage, by " |
| 852 | "specifying a file with a pickle of the result " |
| 853 | "to be returned." |
| 854 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 855 | ) |
| 856 | group.add_option( |
| 857 | "--previous-build-state", |
| 858 | type="string", |
| 859 | default="", |
| 860 | api=constants.REEXEC_API_PREVIOUS_BUILD_STATE, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 861 | help=( |
| 862 | "A base64-encoded BuildSummary object describing the " |
| 863 | "previous build run on the same build machine." |
| 864 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 865 | ) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 866 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 867 | parser.add_argument_group(group) |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 868 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 869 | # |
| 870 | # Debug options |
| 871 | # |
| 872 | # Temporary hack; in place till --dry-run replaces --debug. |
| 873 | # pylint: disable=protected-access |
| 874 | group = parser.debug_group |
| 875 | debug = [x for x in group.option_list if x._long_opts == ["--debug"]][0] |
| 876 | debug.help += " Currently functions as --dry-run in addition." |
| 877 | debug.pass_through = True |
| 878 | group.add_option( |
| 879 | "--notee", |
| 880 | action="store_false", |
| 881 | dest="tee", |
| 882 | default=True, |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 883 | help=( |
| 884 | "Disable logging and internal tee process. Primarily " |
| 885 | "used for debugging cbuildbot itself." |
| 886 | ), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 887 | ) |
| 888 | return parser |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 889 | |
| 890 | |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 891 | def _FinishParsing(options): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 892 | """Perform some parsing tasks that need to take place after optparse. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 893 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 894 | This function needs to be easily testable! Keep it free of |
| 895 | environment-dependent code. Put more detailed usage validation in |
| 896 | _PostParseCheck(). |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 897 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 898 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 899 | options: The options object returned by optparse |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 900 | """ |
| 901 | # Populate options.pass_through_args. |
| 902 | accepted, _ = commandline.FilteringParser.FilterArgs( |
| 903 | options.parsed_args, lambda x: x.opt_inst.pass_through |
| 904 | ) |
| 905 | options.pass_through_args.extend(accepted) |
Brian Harring | 07039b5 | 2012-05-13 17:56:47 -0700 | [diff] [blame] | 906 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 907 | if options.local or options.remote: |
| 908 | cros_build_lib.Die("Deprecated usage. Please use cros tryjob instead.") |
Don Garrett | cc0ee52 | 2017-09-13 14:28:42 -0700 | [diff] [blame] | 909 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 910 | if not options.buildroot: |
| 911 | cros_build_lib.Die("A buildroot is required to build.") |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 912 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 913 | if options.chrome_root: |
| 914 | if options.chrome_rev != constants.CHROME_REV_LOCAL: |
| 915 | cros_build_lib.Die( |
| 916 | "Chrome rev must be %s if chrome_root is set." |
| 917 | % constants.CHROME_REV_LOCAL |
| 918 | ) |
| 919 | elif options.chrome_rev == constants.CHROME_REV_LOCAL: |
| 920 | cros_build_lib.Die( |
| 921 | "Chrome root must be set if chrome_rev is %s." |
| 922 | % constants.CHROME_REV_LOCAL |
| 923 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 924 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 925 | if options.chrome_version: |
| 926 | if options.chrome_rev != constants.CHROME_REV_SPEC: |
| 927 | cros_build_lib.Die( |
| 928 | "Chrome rev must be %s if chrome_version is set." |
| 929 | % constants.CHROME_REV_SPEC |
| 930 | ) |
| 931 | elif options.chrome_rev == constants.CHROME_REV_SPEC: |
| 932 | cros_build_lib.Die( |
| 933 | "Chrome rev must not be %s if chrome_version is not set." |
| 934 | % constants.CHROME_REV_SPEC |
| 935 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 936 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 937 | patches = bool(options.gerrit_patches) |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 938 | |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 939 | # When running in release mode, make sure we are running with checked-in |
| 940 | # code. We want checked-in cbuildbot/scripts to prevent errors, and we want |
| 941 | # to build a release image with checked-in code for CrOS packages. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 942 | if options.buildbot and patches and not options.debug: |
| 943 | cros_build_lib.Die( |
| 944 | "Cannot provide patches when running with --buildbot!" |
| 945 | ) |
David James | 5734ea3 | 2012-08-15 20:23:49 -0700 | [diff] [blame] | 946 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 947 | if options.buildbot and options.remote_trybot: |
| 948 | cros_build_lib.Die( |
| 949 | "--buildbot and --remote-trybot cannot be used together." |
| 950 | ) |
Ryan Cui | ba41ad3 | 2012-03-08 17:15:29 -0800 | [diff] [blame] | 951 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 952 | # Record whether --debug was set explicitly vs. it was inferred. |
| 953 | options.debug_forced = options.debug |
| 954 | # We force --debug to be set for builds that are not 'official'. |
| 955 | options.debug = options.debug or not options.buildbot |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 956 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 957 | options.hwtest_dut_override = ParseHWTestDUTDims( |
| 958 | options.hwtest_dut_dimensions |
| 959 | ) |
| 960 | |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 961 | |
| 962 | def ParseHWTestDUTDims(dims): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 963 | """Parse HWTest DUT dimensions into a valid HWTestDUTOverride object. |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 964 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 965 | Raises an error if any of board, model, or pool is missing. |
| 966 | """ |
| 967 | if not dims: |
| 968 | return None |
| 969 | board = model = pool = None |
| 970 | extra_dims = [] |
| 971 | for dim in dims: |
| 972 | if dim.startswith(BOARD_DIM_LABEL): |
| 973 | # Remove one extra character to account for the ":" or "=" symbol |
| 974 | # separating the label from the dimension itself. |
| 975 | board = dim[len(BOARD_DIM_LABEL) + 1 :] |
| 976 | elif dim.startswith(MODEL_DIM_LABEL): |
| 977 | model = dim[len(MODEL_DIM_LABEL) + 1 :] |
| 978 | elif dim.startswith(POOL_DIM_LABEL): |
| 979 | pool = dim[len(POOL_DIM_LABEL) + 1 :] |
| 980 | else: |
| 981 | extra_dims.append(dim) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 982 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 983 | if not (board and model and pool): |
| 984 | cros_build_lib.Die( |
| 985 | "HWTest DUT dimensions must include board, model, and " |
| 986 | "pool (given %s)." % dims |
| 987 | ) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 988 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 989 | return test_stages.HWTestDUTOverride(board, model, pool, extra_dims) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 990 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 991 | |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 992 | # pylint: disable=unused-argument |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 993 | def _PostParseCheck(parser, options, site_config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 994 | """Perform some usage validation after we've parsed the arguments |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 995 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 996 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 997 | parser: Option parser that was used to parse arguments. |
| 998 | options: The options returned by optparse. |
| 999 | site_config: config_lib.SiteConfig containing all config info. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1000 | """ |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 1001 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1002 | if not options.branch: |
| 1003 | options.branch = git.GetChromiteTrackingBranch() |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 1004 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1005 | # Because the default cache dir depends on other options, FindCacheDir |
| 1006 | # always returns None, and we setup the default here. |
| 1007 | if options.cache_dir is None: |
| 1008 | # Note, options.sourceroot is set regardless of the path |
| 1009 | # actually existing. |
| 1010 | options.cache_dir = os.path.join(options.buildroot, ".cache") |
| 1011 | options.cache_dir = os.path.abspath(options.cache_dir) |
| 1012 | parser.ConfigureCacheDir(options.cache_dir) |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 1013 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1014 | osutils.SafeMakedirsNonRoot(options.cache_dir) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 1015 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1016 | # Ensure that all args are legitimate config targets. |
| 1017 | if options.build_config_name not in site_config: |
| 1018 | cros_build_lib.Die( |
| 1019 | 'Unknown build config: "%s"' % options.build_config_name |
| 1020 | ) |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 1021 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1022 | build_config = site_config[options.build_config_name] |
| 1023 | is_payloads_build = build_config.build_type == constants.PAYLOADS_TYPE |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 1024 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1025 | if options.channels and not is_payloads_build: |
| 1026 | cros_build_lib.Die( |
| 1027 | "--channel must only be used with a payload config," |
| 1028 | " not target (%s)." % options.build_config_name |
| 1029 | ) |
Don Garrett | 5af1d26 | 2014-05-16 15:49:37 -0700 | [diff] [blame] | 1030 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1031 | if not options.channels and is_payloads_build: |
| 1032 | cros_build_lib.Die( |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 1033 | "payload configs (%s) require --channel to do anything useful." |
| 1034 | % options.build_config_name |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1035 | ) |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 1036 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1037 | # If the build config explicitly forces the debug flag, set the debug flag |
| 1038 | # as if it was set from the command line. |
| 1039 | if build_config.debug: |
| 1040 | options.debug = True |
Don Garrett | 370839f | 2017-10-19 18:32:34 -0700 | [diff] [blame] | 1041 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1042 | if not (config_lib.isTryjobConfig(build_config) or options.buildbot): |
| 1043 | cros_build_lib.Die( |
| 1044 | "Refusing to run non-tryjob config as a tryjob.\n" |
| 1045 | 'Please "repo sync && cros tryjob --list %s" for alternatives.\n' |
| 1046 | "See go/cros-explicit-tryjob-build-configs-psa.", |
| 1047 | build_config.name, |
| 1048 | ) |
Don Garrett | 02d2f58 | 2017-11-08 14:01:24 -0800 | [diff] [blame] | 1049 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1050 | # The --version option is not compatible with an external target unless the |
| 1051 | # --buildbot option is specified. More correctly, only "paladin versions" |
| 1052 | # will work with external targets, and those are only used with --buildbot. |
| 1053 | # If --buildbot is specified, then user should know what they are doing and |
| 1054 | # only specify a version that will work. See crbug.com/311648. |
| 1055 | if options.force_version and not ( |
| 1056 | options.buildbot or build_config.internal |
| 1057 | ): |
| 1058 | cros_build_lib.Die( |
| 1059 | "Cannot specify --version without --buildbot for an" |
| 1060 | " external target (%s)." % options.build_config_name |
| 1061 | ) |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 1062 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1063 | |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 1064 | def ParseCommandLine(parser, argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1065 | """Completely parse the commandline arguments""" |
| 1066 | (options, args) = parser.parse_args(argv) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 1067 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1068 | # Handle the request for the reexec command line API version number. |
| 1069 | if options.output_api_version: |
| 1070 | print(constants.REEXEC_API_VERSION) |
| 1071 | sys.exit(0) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 1072 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1073 | # Record the configs targeted. Strip out null arguments. |
| 1074 | build_config_names = [x for x in args if x] |
| 1075 | if len(build_config_names) != 1: |
| 1076 | cros_build_lib.Die( |
| 1077 | "Expected exactly one build config. Got: %r", build_config_names |
| 1078 | ) |
| 1079 | options.build_config_name = build_config_names[-1] |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 1080 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1081 | _FinishParsing(options) |
| 1082 | return options |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1083 | |
| 1084 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1085 | _ENVIRONMENT_PROD = "prod" |
| 1086 | _ENVIRONMENT_DEBUG = "debug" |
| 1087 | _ENVIRONMENT_STANDALONE = "standalone" |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1088 | |
| 1089 | |
| 1090 | def _GetRunEnvironment(options, build_config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1091 | """Determine whether this is a prod/debug/standalone run.""" |
| 1092 | if options.debug_cidb: |
| 1093 | return _ENVIRONMENT_DEBUG |
Don Garrett | a90f014 | 2018-02-28 14:25:19 -0800 | [diff] [blame] | 1094 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1095 | # One of these arguments should always be set if running on a real builder. |
| 1096 | # If we aren't on a real builder, we are standalone. |
| 1097 | if not options.buildbot and not options.remote_trybot: |
| 1098 | return _ENVIRONMENT_STANDALONE |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1099 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1100 | if build_config["debug_cidb"]: |
| 1101 | return _ENVIRONMENT_DEBUG |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1102 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1103 | return _ENVIRONMENT_PROD |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1104 | |
| 1105 | |
Gabe Black | de694a3 | 2015-02-19 15:11:11 -0800 | [diff] [blame] | 1106 | def _SetupConnections(options, build_config): |
George Engelbrecht | 7e07c70 | 2022-09-19 17:03:55 -0600 | [diff] [blame] | 1107 | """Set up CIDB connections using the appropriate Setup call. |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1108 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1109 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 1110 | options: Command line options structure. |
| 1111 | build_config: Config object for this build. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1112 | """ |
George Engelbrecht | 7e07c70 | 2022-09-19 17:03:55 -0600 | [diff] [blame] | 1113 | # Outline: |
| 1114 | # 1) Based on options and build_config, decide whether we are a production |
| 1115 | # run, debug run, or standalone run. |
| 1116 | # 2) Set up cidb instance accordingly. |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 1117 | # 3) Update topology info from cidb, so that any other service set up can |
| 1118 | # use topology. |
George Engelbrecht | 7e07c70 | 2022-09-19 17:03:55 -0600 | [diff] [blame] | 1119 | # 4) Set up any other services. |
| 1120 | run_type = _GetRunEnvironment(options, build_config) |
| 1121 | |
| 1122 | if run_type == _ENVIRONMENT_PROD: |
| 1123 | cidb.CIDBConnectionFactory.SetupProdCidb() |
| 1124 | context = ts_mon_config.SetupTsMonGlobalState( |
| 1125 | "cbuildbot", indirect=True |
| 1126 | ) |
| 1127 | elif run_type == _ENVIRONMENT_DEBUG: |
| 1128 | cidb.CIDBConnectionFactory.SetupDebugCidb() |
| 1129 | context = ts_mon_config.TrivialContextManager() |
| 1130 | else: |
| 1131 | cidb.CIDBConnectionFactory.SetupNoCidb() |
| 1132 | context = ts_mon_config.TrivialContextManager() |
Aviv Keshet | 62d1a0e | 2014-08-22 21:16:13 -0700 | [diff] [blame] | 1133 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1134 | topology.FetchTopology() |
| 1135 | return context |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1136 | |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1137 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame^] | 1138 | class _MockMethodWithReturnValue: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1139 | """A method mocker which just returns the specific value.""" |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1140 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1141 | def __init__(self, return_value): |
| 1142 | self.return_value = return_value |
| 1143 | |
| 1144 | def __call__(self, *args, **kwargs): |
| 1145 | return self.return_value |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1146 | |
| 1147 | |
Alex Klein | 074f94f | 2023-06-22 10:32:06 -0600 | [diff] [blame^] | 1148 | class _ObjectMethodPatcher: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1149 | """A simplified mock.object.patch. |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1150 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1151 | It is a context manager that patches an object's method with specified |
| 1152 | return value. |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1153 | """ |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1154 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1155 | def __init__(self, target, attr, return_value=None): |
| 1156 | """Constructor. |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1157 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1158 | Args: |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 1159 | target: object to patch. |
| 1160 | attr: method name of the object to patch. |
| 1161 | return_value: the return value when calling target.attr |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1162 | """ |
| 1163 | self.target = target |
| 1164 | self.attr = attr |
| 1165 | self.return_value = return_value |
| 1166 | self.original_attr = None |
| 1167 | self.new_attr = _MockMethodWithReturnValue(self.return_value) |
| 1168 | |
| 1169 | def __enter__(self): |
| 1170 | self.original_attr = self.target.__dict__[self.attr] |
| 1171 | setattr(self.target, self.attr, self.new_attr) |
| 1172 | |
| 1173 | def __exit__(self, *args): |
| 1174 | if self.target and self.original_attr: |
| 1175 | setattr(self.target, self.attr, self.original_attr) |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 1176 | |
| 1177 | |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 1178 | # TODO(build): This function is too damn long. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1179 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1180 | # We get false positives with the options object. |
| 1181 | # pylint: disable=attribute-defined-outside-init |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 1182 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1183 | # Turn on strict sudo checks. |
| 1184 | cros_build_lib.STRICT_SUDO = True |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 1185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1186 | # Set umask to 022 so files created by buildbot are readable. |
| 1187 | os.umask(0o22) |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1188 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1189 | parser = _CreateParser() |
| 1190 | options = ParseCommandLine(parser, argv) |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 1191 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1192 | # Fetch our site_config now, because we need it to do anything else. |
| 1193 | site_config = config_lib.GetConfig() |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 1194 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1195 | _PostParseCheck(parser, options, site_config) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1196 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1197 | cros_build_lib.AssertOutsideChroot() |
Zdenek Behan | 98ec2fb | 2012-08-31 17:12:18 +0200 | [diff] [blame] | 1198 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1199 | if options.enable_buildbot_tags: |
| 1200 | cbuildbot_alerts.EnableBuildbotMarkers() |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 1201 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1202 | if ( |
| 1203 | options.buildbot |
| 1204 | and not options.debug |
| 1205 | and not cros_build_lib.HostIsCIBuilder() |
| 1206 | ): |
| 1207 | # --buildbot can only be used on a real builder, unless it's debug. |
| 1208 | cros_build_lib.Die("This host is not a supported build machine.") |
Ningning Xia | c691e43 | 2016-08-11 14:52:59 -0700 | [diff] [blame] | 1209 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1210 | # Only one config arg is allowed in this mode, which was confirmed earlier. |
| 1211 | build_config = site_config[options.build_config_name] |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1212 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1213 | # TODO: Re-enable this block when reference_repo support handles this |
| 1214 | # properly. (see chromium:330775) |
| 1215 | # if options.reference_repo is None: |
| 1216 | # repo_path = os.path.join(options.sourceroot, '.repo') |
| 1217 | # # If we're being run from a repo checkout, reuse the repo's git pool to |
| 1218 | # # cut down on sync time. |
| 1219 | # if os.path.exists(repo_path): |
| 1220 | # options.reference_repo = options.sourceroot |
Don Garrett | bbd7b55 | 2014-05-16 13:15:21 -0700 | [diff] [blame] | 1221 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1222 | if options.reference_repo: |
| 1223 | if not os.path.exists(options.reference_repo): |
| 1224 | parser.error( |
| 1225 | "Reference path %s does not exist" % (options.reference_repo,) |
| 1226 | ) |
| 1227 | elif not os.path.exists(os.path.join(options.reference_repo, ".repo")): |
| 1228 | parser.error( |
| 1229 | "Reference path %s does not look to be the base of a " |
| 1230 | "repo checkout; no .repo exists in the root." |
| 1231 | % (options.reference_repo,) |
| 1232 | ) |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 1233 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1234 | if (options.buildbot or options.remote_trybot) and not options.resume: |
| 1235 | missing = osutils.FindMissingBinaries(_BUILDBOT_REQUIRED_BINARIES) |
| 1236 | if missing: |
| 1237 | parser.error( |
| 1238 | "Option --buildbot/--remote-trybot requires the following " |
| 1239 | "binaries which couldn't be found in $PATH: %s" |
Trent Apted | 66736d8 | 2023-05-25 10:38:28 +1000 | [diff] [blame] | 1240 | % ", ".join(missing) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1241 | ) |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 1242 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1243 | if options.reference_repo: |
| 1244 | options.reference_repo = os.path.abspath(options.reference_repo) |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 1245 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1246 | # Sanity check of buildroot- specifically that it's not pointing into the |
| 1247 | # midst of an existing repo since git-repo doesn't support nesting. |
| 1248 | if not repository.IsARepoRoot(options.buildroot) and git.FindRepoDir( |
| 1249 | options.buildroot |
| 1250 | ): |
| 1251 | cros_build_lib.Die( |
| 1252 | "Configured buildroot %s is a subdir of an existing repo checkout." |
| 1253 | % options.buildroot |
| 1254 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1255 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1256 | if not options.log_dir: |
| 1257 | options.log_dir = os.path.join(options.buildroot, _DEFAULT_LOG_DIR) |
Chris Sosa | b5ea3b4 | 2012-10-25 15:25:20 -0700 | [diff] [blame] | 1258 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1259 | log_file = None |
| 1260 | if options.tee: |
| 1261 | log_file = os.path.join(options.log_dir, _BUILDBOT_LOG_FILE) |
| 1262 | osutils.SafeMakedirs(options.log_dir) |
| 1263 | _BackupPreviousLog(log_file) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1264 | |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1265 | with contextlib.ExitStack() as stack: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1266 | # Preserve chromite; we might be running from there! |
| 1267 | options.preserve_paths = set(["chromite"]) |
| 1268 | if log_file is not None: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 1269 | # We don't want the critical section to try to clean up the tee |
| 1270 | # process, so we run Tee (forked off) outside of it. This prevents a |
| 1271 | # deadlock because the Tee process only exits when its pipe is |
| 1272 | # closed, and the critical section accidentally holds on to that |
| 1273 | # file handle. |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1274 | stack.enter_context(tee.Tee(log_file)) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1275 | options.preserve_paths.add(_DEFAULT_LOG_DIR) |
David James | cebc727 | 2013-07-17 16:45:05 -0700 | [diff] [blame] | 1276 | |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1277 | critical_section = stack.enter_context(cleanup.EnforcedCleanupSection()) |
| 1278 | stack.enter_context(sudo.SudoKeepAlive()) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1279 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1280 | if not options.resume: |
| 1281 | # If we're in resume mode, use our parents tempdir rather than |
| 1282 | # nesting another layer. |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1283 | stack.enter_context(osutils.TempDir(prefix="cbb", set_global=True)) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1284 | logging.debug("Cbuildbot tempdir is %r.", os.environ.get("TMP")) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1285 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1286 | if options.cgroups: |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1287 | stack.enter_context(cgroups.SimpleContainChildren("cbuildbot")) |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 1288 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1289 | # Mark everything between EnforcedCleanupSection and here as having to |
| 1290 | # be rolled back via the contextmanager cleanup handlers. This |
| 1291 | # ensures that sudo bits cannot outlive cbuildbot, that anything |
| 1292 | # cgroups would kill gets killed, etc. |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1293 | stack.enter_context(critical_section.ForkWatchdog()) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1294 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1295 | if options.mock_slave_status is not None: |
Mike Frysinger | 31fdddd | 2023-02-24 15:50:55 -0500 | [diff] [blame] | 1296 | with open(options.mock_slave_status, "rb") as f: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1297 | mock_statuses = pickle.load(f) |
| 1298 | for key, value in mock_statuses.items(): |
| 1299 | mock_statuses[key] = builder_status_lib.BuilderStatus( |
| 1300 | **value |
| 1301 | ) |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1302 | stack.enter_context( |
| 1303 | _ObjectMethodPatcher( |
| 1304 | completion_stages.MasterSlaveSyncCompletionStage, |
| 1305 | "_FetchSlaveStatuses", |
| 1306 | return_value=mock_statuses, |
| 1307 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1308 | ) |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 1309 | |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1310 | stack.enter_context(_SetupConnections(options, build_config)) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1311 | retry_stats.SetupStats() |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1312 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1313 | timeout_display_message = ( |
| 1314 | "This build has reached the timeout deadline set by the master. " |
| 1315 | "Either this stage or a previous one took too long (see stage " |
| 1316 | "timing historical summary in ReportStage) or the build failed " |
| 1317 | "to start on time." |
| 1318 | ) |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 1319 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1320 | if options.timeout > 0: |
Mike Frysinger | 321fecd | 2023-06-16 10:40:51 -0400 | [diff] [blame] | 1321 | stack.enter_context( |
| 1322 | timeout_util.FatalTimeout( |
| 1323 | options.timeout, |
| 1324 | timeout_display_message, |
| 1325 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1326 | ) |
| 1327 | try: |
| 1328 | _RunBuildStagesWrapper(options, site_config, build_config) |
| 1329 | except failures_lib.ExitEarlyException as ex: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 1330 | # This build finished successfully. Do not re-raise |
| 1331 | # ExitEarlyException. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1332 | logging.info("One stage exited early: %s", ex) |