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