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