Mike Frysinger | e58c0e2 | 2017-10-04 15:43:30 -0400 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Mike Frysinger | d6925b5 | 2012-07-16 16:11:00 -0400 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Main builder code for Chromium OS. |
| 7 | |
| 8 | Used by Chromium OS buildbot configuration for all Chromium OS builds including |
| 9 | full and pre-flight-queue builds. |
| 10 | """ |
| 11 | |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 12 | from __future__ import print_function |
| 13 | |
Aviv Keshet | 593014d | 2017-07-18 17:28:25 -0700 | [diff] [blame] | 14 | import distutils.version # pylint: disable=import-error,no-name-in-module |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 15 | import glob |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 16 | import json |
Mike Frysinger | b0b0caa | 2015-11-07 01:05:18 -0500 | [diff] [blame] | 17 | import optparse # pylint: disable=deprecated-module |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 18 | import os |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 19 | import pickle |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 20 | import sys |
| 21 | |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 22 | from chromite.cbuildbot import builders |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 23 | from chromite.cbuildbot import cbuildbot_run |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 24 | from chromite.cbuildbot import repository |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 25 | from chromite.cbuildbot import topology |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 26 | from chromite.cbuildbot.stages import completion_stages |
Ningning Xia | f342b95 | 2017-02-15 14:13:33 -0800 | [diff] [blame] | 27 | from chromite.lib import builder_status_lib |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 28 | from chromite.lib import cidb |
Brian Harring | c92a701 | 2012-02-29 10:11:34 -0800 | [diff] [blame] | 29 | from chromite.lib import cgroups |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 30 | from chromite.lib import cleanup |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 31 | from chromite.lib import commandline |
Ningning Xia | 6a71805 | 2016-12-22 10:08:15 -0800 | [diff] [blame] | 32 | from chromite.lib import config_lib |
| 33 | from chromite.lib import constants |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 34 | from chromite.lib import cros_build_lib |
Ralph Nathan | 91874ca | 2015-03-19 13:29:41 -0700 | [diff] [blame] | 35 | from chromite.lib import cros_logging as logging |
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 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [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' |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 53 | _BUILDBOT_REQUIRED_BINARIES = ('pbzip2',) |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 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): |
| 58 | """Rename previous log. |
| 59 | |
| 60 | Args: |
| 61 | log_file: The absolute path to the previous log. |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 62 | backup_limit: Maximum number of old logs to keep. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 63 | """ |
| 64 | if os.path.exists(log_file): |
| 65 | old_logs = sorted(glob.glob(log_file + '.*'), |
| 66 | key=distutils.version.LooseVersion) |
| 67 | |
| 68 | if len(old_logs) >= backup_limit: |
| 69 | os.remove(old_logs[0]) |
| 70 | |
| 71 | last = 0 |
| 72 | if old_logs: |
| 73 | last = int(old_logs.pop().rpartition('.')[2]) |
| 74 | |
| 75 | os.rename(log_file, log_file + '.' + str(last + 1)) |
| 76 | |
Ryan Cui | 5616a51 | 2012-08-17 13:39:36 -0700 | [diff] [blame] | 77 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 78 | def _IsDistributedBuilder(options, chrome_rev, build_config): |
| 79 | """Determines whether the builder should be a DistributedBuilder. |
| 80 | |
| 81 | Args: |
| 82 | options: options passed on the commandline. |
| 83 | chrome_rev: Chrome revision to build. |
| 84 | build_config: Builder configuration dictionary. |
| 85 | |
| 86 | Returns: |
| 87 | True if the builder should be a distributed_builder |
| 88 | """ |
Don Garrett | 0bc8567 | 2015-07-23 19:46:00 +0000 | [diff] [blame] | 89 | if build_config['pre_cq']: |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 90 | return True |
| 91 | elif not options.buildbot: |
| 92 | return False |
| 93 | elif chrome_rev in (constants.CHROME_REV_TOT, |
| 94 | constants.CHROME_REV_LOCAL, |
| 95 | constants.CHROME_REV_SPEC): |
| 96 | # We don't do distributed logic to TOT Chrome PFQ's, nor local |
| 97 | # chrome roots (e.g. chrome try bots) |
| 98 | # TODO(davidjames): Update any builders that rely on this logic to use |
| 99 | # manifest_version=False instead. |
| 100 | return False |
| 101 | elif build_config['manifest_version']: |
| 102 | return True |
| 103 | |
| 104 | return False |
| 105 | |
| 106 | |
Don Garrett | a52a5b0 | 2015-06-02 14:52:57 -0700 | [diff] [blame] | 107 | def _RunBuildStagesWrapper(options, site_config, build_config): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 108 | """Helper function that wraps RunBuildStages().""" |
Lann Martin | ffb9516 | 2018-08-28 12:02:54 -0600 | [diff] [blame] | 109 | logging.info('cbuildbot was executed with args %s', |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 110 | cros_build_lib.CmdToStr(sys.argv)) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 111 | |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 112 | chrome_rev = build_config['chrome_rev'] |
| 113 | if options.chrome_rev: |
| 114 | chrome_rev = options.chrome_rev |
| 115 | if chrome_rev == constants.CHROME_REV_TOT: |
Stefan Zager | d49d9ff | 2014-08-15 21:33:37 -0700 | [diff] [blame] | 116 | options.chrome_version = gob_util.GetTipOfTrunkRevision( |
| 117 | constants.CHROMIUM_GOB_URL) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 118 | options.chrome_rev = constants.CHROME_REV_SPEC |
| 119 | |
David James | 4a404a5 | 2013-02-19 13:07:59 -0800 | [diff] [blame] | 120 | # If it's likely we'll need to build Chrome, fetch the source. |
Mike Frysinger | f4d9ab8 | 2013-03-05 19:38:05 -0500 | [diff] [blame] | 121 | if build_config['sync_chrome'] is None: |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 122 | options.managed_chrome = ( |
| 123 | chrome_rev != constants.CHROME_REV_LOCAL and |
Mike Frysinger | f4d9ab8 | 2013-03-05 19:38:05 -0500 | [diff] [blame] | 124 | (not build_config['usepkg_build_packages'] or chrome_rev or |
Mike Frysinger | 8b1bd82 | 2017-08-11 16:11:42 -0400 | [diff] [blame] | 125 | build_config['profile'])) |
Mike Frysinger | f4d9ab8 | 2013-03-05 19:38:05 -0500 | [diff] [blame] | 126 | else: |
| 127 | options.managed_chrome = build_config['sync_chrome'] |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 128 | |
Don Garrett | 94c603f | 2019-02-01 16:26:43 -0800 | [diff] [blame] | 129 | chrome_root_mgr = None |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 130 | if options.managed_chrome: |
Don Garrett | 94c603f | 2019-02-01 16:26:43 -0800 | [diff] [blame] | 131 | # Create a temp directory for syncing Chrome source. |
| 132 | chrome_root_mgr = osutils.TempDir(prefix='chrome_root_') |
| 133 | options.chrome_root = chrome_root_mgr.tempdir |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 134 | |
Matt Tennant | 95a42ad | 2013-12-27 15:38:36 -0800 | [diff] [blame] | 135 | # We are done munging options values, so freeze options object now to avoid |
| 136 | # further abuse of it. |
| 137 | # TODO(mtennant): one by one identify each options value override and see if |
| 138 | # it can be handled another way. Try to push this freeze closer and closer |
| 139 | # to the start of the script (e.g. in or after _PostParseCheck). |
| 140 | options.Freeze() |
| 141 | |
Don Garrett | 5ba2c45 | 2018-01-30 16:34:41 -0800 | [diff] [blame] | 142 | metadata_dump_dict = { |
| 143 | # A detected default has been set before now if it wasn't explicit. |
| 144 | 'branch': options.branch, |
| 145 | } |
| 146 | if options.metadata_dump: |
| 147 | with open(options.metadata_dump, 'r') as metadata_file: |
| 148 | metadata_dump_dict = json.loads(metadata_file.read()) |
| 149 | |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 150 | with parallel.Manager() as manager: |
Don Garrett | a52a5b0 | 2015-06-02 14:52:57 -0700 | [diff] [blame] | 151 | builder_run = cbuildbot_run.BuilderRun( |
| 152 | options, site_config, build_config, manager) |
Dhanya Ganesh | 39a48a8 | 2018-12-06 16:01:11 -0700 | [diff] [blame] | 153 | buildstore = BuildStore() |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 154 | if metadata_dump_dict: |
| 155 | builder_run.attrs.metadata.UpdateWithDict(metadata_dump_dict) |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 156 | |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 157 | if builder_run.config.builder_class_name is None: |
Don Garrett | 56e6ed3 | 2015-06-23 16:52:20 -0700 | [diff] [blame] | 158 | # TODO: This should get relocated to chromeos_config. |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 159 | if _IsDistributedBuilder(options, chrome_rev, build_config): |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 160 | builder_cls_name = 'simple_builders.DistributedBuilder' |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 161 | else: |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 162 | builder_cls_name = 'simple_builders.SimpleBuilder' |
| 163 | builder_cls = builders.GetBuilderClass(builder_cls_name) |
Dhanya Ganesh | 39a48a8 | 2018-12-06 16:01:11 -0700 | [diff] [blame] | 164 | builder = builder_cls(builder_run, buildstore) |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 165 | else: |
Dhanya Ganesh | 39a48a8 | 2018-12-06 16:01:11 -0700 | [diff] [blame] | 166 | builder = builders.Builder(builder_run, buildstore) |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 167 | |
Don Garrett | 94c603f | 2019-02-01 16:26:43 -0800 | [diff] [blame] | 168 | try: |
| 169 | if not builder.Run(): |
| 170 | sys.exit(1) |
| 171 | finally: |
| 172 | if chrome_root_mgr: |
| 173 | chrome_root_mgr.Cleanup() |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 174 | |
| 175 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 176 | def _CheckChromeVersionOption(_option, _opt_str, value, parser): |
| 177 | """Upgrade other options based on chrome_version being passed.""" |
| 178 | value = value.strip() |
| 179 | |
| 180 | if parser.values.chrome_rev is None and value: |
| 181 | parser.values.chrome_rev = constants.CHROME_REV_SPEC |
| 182 | |
| 183 | parser.values.chrome_version = value |
| 184 | |
| 185 | |
| 186 | def _CheckChromeRootOption(_option, _opt_str, value, parser): |
| 187 | """Validate and convert chrome_root to full-path form.""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 188 | if parser.values.chrome_rev is None: |
| 189 | parser.values.chrome_rev = constants.CHROME_REV_LOCAL |
| 190 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 191 | parser.values.chrome_root = value |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 192 | |
| 193 | |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 194 | def FindCacheDir(_parser, _options): |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 195 | return None |
| 196 | |
| 197 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 198 | class CustomGroup(optparse.OptionGroup): |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 199 | """Custom option group which supports arguments passed-through to trybot.""" |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 200 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 201 | def add_remote_option(self, *args, **kwargs): |
| 202 | """For arguments that are passed-through to remote trybot.""" |
| 203 | return optparse.OptionGroup.add_option(self, *args, |
| 204 | remote_pass_through=True, |
| 205 | **kwargs) |
| 206 | |
| 207 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 208 | class CustomOption(commandline.FilteringOption): |
| 209 | """Subclass FilteringOption class to implement pass-through and api.""" |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 210 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 211 | def __init__(self, *args, **kwargs): |
| 212 | # The remote_pass_through argument specifies whether we should directly |
| 213 | # pass the argument (with its value) onto the remote trybot. |
| 214 | self.pass_through = kwargs.pop('remote_pass_through', False) |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 215 | self.api_version = int(kwargs.pop('api', '0')) |
| 216 | commandline.FilteringOption.__init__(self, *args, **kwargs) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 217 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 218 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 219 | class CustomParser(commandline.FilteringParser): |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 220 | """Custom option parser which supports arguments passed-through to trybot""" |
Matt Tennant | e817904 | 2013-10-01 15:47:32 -0700 | [diff] [blame] | 221 | |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 222 | DEFAULT_OPTION_CLASS = CustomOption |
| 223 | |
| 224 | def add_remote_option(self, *args, **kwargs): |
| 225 | """For arguments that are passed-through to remote trybot.""" |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 226 | return self.add_option(*args, remote_pass_through=True, **kwargs) |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 227 | |
| 228 | |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 229 | def CreateParser(): |
| 230 | """Expose _CreateParser publicly.""" |
| 231 | # Name _CreateParser is needed for commandline library. |
| 232 | return _CreateParser() |
| 233 | |
| 234 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 235 | def _CreateParser(): |
Ryan Cui | 16d9e1f | 2012-05-11 10:50:18 -0700 | [diff] [blame] | 236 | """Generate and return the parser with all the options.""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 237 | # Parse options |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 238 | usage = 'usage: %prog [options] buildbot_config [buildbot_config ...]' |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 239 | parser = CustomParser(usage=usage, caching=FindCacheDir) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 240 | |
| 241 | # Main options |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 242 | parser.add_remote_option('-b', '--branch', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 243 | help='The manifest branch to test. The branch to ' |
| 244 | 'check the buildroot out to.') |
| 245 | parser.add_option('-r', '--buildroot', type='path', dest='buildroot', |
| 246 | help='Root directory where source is checked out to, and ' |
| 247 | 'where the build occurs. For external build configs, ' |
| 248 | "defaults to 'trybot' directory at top level of your " |
| 249 | 'repo-managed checkout.') |
Don Garrett | 10210fa | 2018-06-29 18:25:41 -0700 | [diff] [blame] | 250 | parser.add_option('--workspace', type='path', |
| 251 | api=constants.REEXEC_API_WORKSPACE, |
| 252 | help='Root directory for a secondary checkout .') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 253 | parser.add_option('--bootstrap-dir', type='path', |
Prathmesh Prabhu | 867c117 | 2015-06-02 17:57:59 -0700 | [diff] [blame] | 254 | help='Bootstrapping cbuildbot may involve checking out ' |
| 255 | 'multiple copies of chromite. All these checkouts ' |
| 256 | 'will be contained in the directory specified here. ' |
| 257 | 'Default:%s' % osutils.GetGlobalTempDir()) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 258 | parser.add_remote_option('--android_rev', type='choice', |
David Riley | 486b261 | 2016-02-22 19:59:26 -0800 | [diff] [blame] | 259 | choices=constants.VALID_ANDROID_REVISIONS, |
| 260 | help=('Revision of Android to use, of type [%s]' |
| 261 | % '|'.join(constants.VALID_ANDROID_REVISIONS))) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 262 | parser.add_remote_option('--chrome_rev', type='choice', |
David Riley | 486b261 | 2016-02-22 19:59:26 -0800 | [diff] [blame] | 263 | choices=constants.VALID_CHROME_REVISIONS, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 264 | help=('Revision of Chrome to use, of type [%s]' |
| 265 | % '|'.join(constants.VALID_CHROME_REVISIONS))) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 266 | parser.add_remote_option('--profile', |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 267 | help='Name of profile to sub-specify board variant.') |
Hidehiko Abe | 95d7cf6 | 2017-03-07 23:34:30 +0900 | [diff] [blame] | 268 | # TODO(crbug.com/279618): Running GOMA is under development. Following |
| 269 | # flags are added for development purpose due to repository dependency, |
| 270 | # but not officially supported yet. |
| 271 | parser.add_option('--goma_dir', type='path', |
| 272 | api=constants.REEXEC_API_GOMA, |
| 273 | help='Specify a directory containing goma. When this is ' |
| 274 | 'set, GOMA is used to build Chrome.') |
Yoshisato Yanagisawa | 13d55b3 | 2019-08-15 09:44:44 +0900 | [diff] [blame] | 275 | parser.add_option('--chromeos_goma_dir', type='path', |
| 276 | api=constants.REEXEC_API_CHROMEOS_GOMA_DIR, |
| 277 | help='Specify a directory containing goma for ' |
| 278 | 'build package.') |
Hidehiko Abe | 95d7cf6 | 2017-03-07 23:34:30 +0900 | [diff] [blame] | 279 | parser.add_option('--goma_client_json', type='path', |
| 280 | api=constants.REEXEC_API_GOMA, |
| 281 | help='Specify a service-account-goma-client.json path. ' |
| 282 | 'The file is needed on bots to run GOMA.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 283 | |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 284 | group = CustomGroup( |
| 285 | parser, |
| 286 | 'Deprecated Options') |
| 287 | |
| 288 | parser.add_option('--local', action='store_true', default=False, |
Don Garrett | cc0ee52 | 2017-09-13 14:28:42 -0700 | [diff] [blame] | 289 | help='Deprecated. See cros tryjob.') |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 290 | parser.add_option('--remote', action='store_true', default=False, |
Don Garrett | cc0ee52 | 2017-09-13 14:28:42 -0700 | [diff] [blame] | 291 | help='Deprecated. See cros tryjob.') |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 292 | |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 293 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 294 | # Patch selection options. |
| 295 | # |
| 296 | |
| 297 | group = CustomGroup( |
| 298 | parser, |
| 299 | 'Patch Options') |
| 300 | |
Mike Frysinger | dad205d | 2017-08-11 16:00:14 -0400 | [diff] [blame] | 301 | group.add_remote_option('-g', '--gerrit-patches', action='split_extend', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 302 | type='string', default=[], |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 303 | metavar="'Id1 *int_Id2...IdN'", |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 304 | help='Space-separated list of short-form Gerrit ' |
| 305 | "Change-Id's or change numbers to patch. " |
| 306 | "Please prepend '*' to internal Change-Id's") |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 307 | |
Mike Frysinger | 6889324 | 2017-08-11 14:16:39 -0400 | [diff] [blame] | 308 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 309 | |
| 310 | # |
| 311 | # Remote trybot options. |
| 312 | # |
| 313 | |
| 314 | group = CustomGroup( |
| 315 | parser, |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 316 | 'Options used to configure tryjob behavior.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 317 | group.add_remote_option('--hwtest', action='store_true', default=False, |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 318 | help='Run the HWTest stage (tests on real hardware)') |
Mike Frysinger | dad205d | 2017-08-11 16:00:14 -0400 | [diff] [blame] | 319 | group.add_remote_option('--channel', action='split_extend', dest='channels', |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 320 | default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 321 | help='Specify a channel for a payloads trybot. Can ' |
| 322 | 'be specified multiple times. No valid for ' |
| 323 | 'non-payloads configs.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 324 | |
Mike Frysinger | 6889324 | 2017-08-11 14:16:39 -0400 | [diff] [blame] | 325 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 326 | |
| 327 | # |
| 328 | # Advanced options. |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 329 | # |
| 330 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 331 | group = CustomGroup( |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 332 | parser, |
| 333 | 'Advanced Options', |
| 334 | 'Caution: use these options at your own risk.') |
| 335 | |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 336 | group.add_remote_option('--bootstrap-args', action='append', default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 337 | help='Args passed directly to the bootstrap re-exec ' |
| 338 | 'to skip verification by the bootstrap code') |
| 339 | group.add_remote_option('--buildbot', action='store_true', dest='buildbot', |
Bernie Thompson | 63f3006 | 2016-12-21 15:24:25 -0800 | [diff] [blame] | 340 | default=False, |
| 341 | help='This is running on a buildbot. ' |
| 342 | 'This can be used to make a build operate ' |
| 343 | 'like an official builder, e.g. generate ' |
| 344 | 'new version numbers and archive official ' |
| 345 | 'artifacts and such. This should only be ' |
| 346 | 'used if you are confident in what you are ' |
| 347 | 'doing, as it will make automated commits.') |
Don Garrett | 07d4626 | 2017-04-13 12:06:44 -0700 | [diff] [blame] | 348 | parser.add_remote_option('--repo-cache', type='path', dest='_repo_cache', |
| 349 | help='Present for backwards compatibility, ignored.') |
Prathmesh Prabhu | 51d774f | 2015-07-17 15:11:49 -0700 | [diff] [blame] | 350 | group.add_remote_option('--no-buildbot-tags', action='store_false', |
| 351 | dest='enable_buildbot_tags', default=True, |
| 352 | help='Suppress buildbot specific tags from log ' |
| 353 | 'output. This is used to hide recursive ' |
| 354 | 'cbuilbot runs on the waterfall.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 355 | group.add_remote_option('--buildnumber', type='int', default=0, |
| 356 | help='build number') |
| 357 | group.add_option('--chrome_root', action='callback', type='path', |
| 358 | callback=_CheckChromeRootOption, |
| 359 | help='Local checkout of Chrome to use.') |
| 360 | group.add_remote_option('--chrome_version', action='callback', type='string', |
| 361 | dest='chrome_version', |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 362 | callback=_CheckChromeVersionOption, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 363 | help='Used with SPEC logic to force a particular ' |
| 364 | 'git revision of chrome rather than the ' |
| 365 | 'latest.') |
| 366 | group.add_remote_option('--clobber', action='store_true', default=False, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 367 | help='Clears an old checkout before syncing') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 368 | group.add_remote_option('--latest-toolchain', action='store_true', |
| 369 | default=False, |
| 370 | help='Use the latest toolchain.') |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 371 | parser.add_option('--log_dir', dest='log_dir', type='path', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 372 | help='Directory where logs are stored.') |
| 373 | group.add_remote_option('--maxarchives', type='int', |
| 374 | dest='max_archive_builds', default=3, |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 375 | help='Change the local saved build count limit.') |
Ryan Cui | bbd3d4b | 2012-08-17 12:20:37 -0700 | [diff] [blame] | 376 | parser.add_remote_option('--manifest-repo-url', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 377 | help='Overrides the default manifest repo url.') |
David James | 565bc9a | 2013-04-08 14:54:45 -0700 | [diff] [blame] | 378 | group.add_remote_option('--compilecheck', action='store_true', default=False, |
| 379 | help='Only verify compilation and unit tests.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 380 | group.add_remote_option('--noarchive', action='store_false', dest='archive', |
| 381 | default=True, help="Don't run archive stage.") |
Ryan Cui | f7f2469 | 2012-05-18 16:35:33 -0700 | [diff] [blame] | 382 | group.add_remote_option('--nobootstrap', action='store_false', |
| 383 | dest='bootstrap', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 384 | help="Don't checkout and run from a standalone " |
| 385 | 'chromite repo.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 386 | group.add_remote_option('--nobuild', action='store_false', dest='build', |
| 387 | default=True, |
| 388 | help="Don't actually build (for cbuildbot dev)") |
| 389 | group.add_remote_option('--noclean', action='store_false', dest='clean', |
| 390 | default=True, help="Don't clean the buildroot") |
Ryan Cui | f7f2469 | 2012-05-18 16:35:33 -0700 | [diff] [blame] | 391 | group.add_remote_option('--nocgroups', action='store_false', dest='cgroups', |
| 392 | default=True, |
| 393 | help='Disable cbuildbots usage of cgroups.') |
Ryan Cui | 3ea98e0 | 2013-08-07 16:01:48 -0700 | [diff] [blame] | 394 | group.add_remote_option('--nochromesdk', action='store_false', |
| 395 | dest='chrome_sdk', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 396 | help="Don't run the ChromeSDK stage which builds " |
| 397 | 'Chrome outside of the chroot.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 398 | group.add_remote_option('--noprebuilts', action='store_false', |
| 399 | dest='prebuilts', default=True, |
| 400 | help="Don't upload prebuilts.") |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 401 | group.add_remote_option('--nopatch', action='store_false', |
| 402 | dest='postsync_patch', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 403 | help="Don't run PatchChanges stage. This does not " |
| 404 | 'disable patching in of chromite patches ' |
| 405 | 'during BootstrapStage.') |
Don Garrett | 82c0ae8 | 2014-02-03 18:25:11 -0800 | [diff] [blame] | 406 | group.add_remote_option('--nopaygen', action='store_false', |
| 407 | dest='paygen', default=True, |
| 408 | help="Don't generate payloads.") |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 409 | group.add_remote_option('--noreexec', action='store_false', |
| 410 | dest='postsync_reexec', default=True, |
| 411 | help="Don't reexec into the buildroot after syncing.") |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 412 | group.add_remote_option('--nosdk', action='store_true', default=False, |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 413 | help='Re-create the SDK from scratch.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 414 | group.add_remote_option('--nosync', action='store_false', dest='sync', |
| 415 | default=True, help="Don't sync before building.") |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 416 | group.add_remote_option('--notests', action='store_false', dest='tests', |
| 417 | default=True, |
xixuan | 7774ba8 | 2017-06-22 16:04:00 -0700 | [diff] [blame] | 418 | help='Override values from buildconfig, run no ' |
| 419 | 'tests, and build no autotest and artifacts.') |
| 420 | group.add_remote_option('--novmtests', action='store_false', dest='vmtests', |
| 421 | default=True, |
| 422 | help='Override values from buildconfig, run no ' |
| 423 | 'vmtests.') |
Nam T. Nguyen | c93f134 | 2014-07-11 14:40:54 -0700 | [diff] [blame] | 424 | group.add_remote_option('--noimagetests', action='store_false', |
| 425 | dest='image_test', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 426 | help='Override values from buildconfig and run no ' |
| 427 | 'image tests.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 428 | group.add_remote_option('--nouprev', action='store_false', dest='uprev', |
| 429 | default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 430 | help='Override values from buildconfig and never ' |
| 431 | 'uprev.') |
| 432 | group.add_option('--reference-repo', |
| 433 | help='Reuse git data stored in an existing repo ' |
| 434 | 'checkout. This can drastically reduce the network ' |
| 435 | 'time spent setting up the trybot checkout. By ' |
| 436 | "default, if this option isn't given but cbuildbot " |
| 437 | 'is invoked from a repo checkout, cbuildbot will ' |
| 438 | 'use the repo root.') |
Ryan Cui | cedd8a5 | 2012-03-22 02:28:35 -0700 | [diff] [blame] | 439 | group.add_option('--resume', action='store_true', default=False, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 440 | help='Skip stages already successfully completed.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 441 | group.add_remote_option('--timeout', type='int', default=0, |
| 442 | help='Specify the maximum amount of time this job ' |
| 443 | 'can run for, at which point the build will be ' |
| 444 | 'aborted. If set to zero, then there is no ' |
| 445 | 'timeout.') |
| 446 | group.add_remote_option('--version', dest='force_version', |
| 447 | help='Used with manifest logic. Forces use of this ' |
| 448 | 'version rather than create or get latest. ' |
| 449 | 'Examples: 4815.0.0-rc1, 4815.1.2') |
| 450 | group.add_remote_option('--git-cache-dir', type='path', |
Don Garrett | bb79be9 | 2016-09-27 11:14:07 -0700 | [diff] [blame] | 451 | api=constants.REEXEC_API_GIT_CACHE_DIR, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 452 | help='Specify the cache directory to store the ' |
| 453 | 'project caches populated by the git-cache ' |
| 454 | 'tool. Bootstrap the projects based on the git ' |
| 455 | 'cache files instead of fetching them directly ' |
| 456 | 'from the GoB servers.') |
David Burger | 33c7d3c | 2020-02-19 09:57:54 -0700 | [diff] [blame] | 457 | group.add_remote_option('--chrome-preload-dir', type='path', |
| 458 | api=constants.REEXEC_API_CHROME_PRELOAD_DIR, |
| 459 | help='Specify a preloaded chrome source cache ' |
| 460 | 'directory populated by the git-cache tool. ' |
| 461 | 'Bootstrap chrome based on the cached files ' |
| 462 | 'instead of fetching them directly from the GoB ' |
| 463 | 'servers. When both this argument and ' |
| 464 | '--git-cache-dir are provided this value will ' |
| 465 | 'be preferred for the chrome source cache.') |
Don Garrett | a90f014 | 2018-02-28 14:25:19 -0800 | [diff] [blame] | 466 | group.add_remote_option('--debug-cidb', action='store_true', default=False, |
| 467 | help='Force Debug CIDB to be used.') |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 468 | # cbuildbot ChromeOS Findit options |
| 469 | group.add_remote_option('--cbb_build_packages', action='split_extend', |
| 470 | dest='cbb_build_packages', |
| 471 | default=[], |
| 472 | help='Specify an explicit list of packages to build ' |
| 473 | 'for integration with Findit.') |
Gregory Meinke | ad6d567 | 2019-02-19 08:41:12 -0700 | [diff] [blame] | 474 | group.add_remote_option('--cbb_snapshot_revision', type='string', |
| 475 | dest='cbb_snapshot_revision', default=None, |
| 476 | help='Snapshot manifest revision to sync to ' |
| 477 | 'for building.') |
Chris McDonald | 2921fd4 | 2020-02-25 14:30:06 -0700 | [diff] [blame^] | 478 | group.add_remote_option( |
| 479 | '--no-publish-prebuilt-confs', |
| 480 | dest='publish', |
| 481 | action='store_false', |
| 482 | default=True, |
| 483 | help="Don't publish git commits to prebuilt.conf or sdk_version.conf") |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 484 | |
Mike Frysinger | 6889324 | 2017-08-11 14:16:39 -0400 | [diff] [blame] | 485 | parser.add_argument_group(group) |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 486 | |
| 487 | # |
| 488 | # Internal options. |
| 489 | # |
| 490 | |
| 491 | group = CustomGroup( |
| 492 | parser, |
Mike Frysinger | 34db869 | 2013-11-11 14:54:08 -0500 | [diff] [blame] | 493 | 'Internal Chromium OS Build Team Options', |
| 494 | 'Caution: these are for meant for the Chromium OS build team only') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 495 | |
| 496 | group.add_remote_option('--archive-base', type='gs_path', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 497 | help='Base GS URL (gs://<bucket_name>/<path>) to ' |
| 498 | 'upload archive artifacts to') |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 499 | group.add_remote_option( |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 500 | '--cq-gerrit-query', dest='cq_gerrit_override', |
| 501 | help='If given, this gerrit query will be used to find what patches to ' |
| 502 | "test, rather than the normal 'CommitQueue>=1 AND Verified=1 AND " |
| 503 | "CodeReview=2' query it defaults to. Use with care- note " |
| 504 | 'additionally this setting only has an effect if the buildbot ' |
| 505 | "target is a cq target, and we're in buildbot mode.") |
| 506 | group.add_option('--pass-through', action='append', type='string', |
| 507 | dest='pass_through_args', default=[]) |
| 508 | group.add_option('--reexec-api-version', action='store_true', |
| 509 | dest='output_api_version', default=False, |
| 510 | help='Used for handling forwards/backwards compatibility ' |
| 511 | 'with --resume and --bootstrap') |
| 512 | group.add_option('--remote-trybot', action='store_true', default=False, |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 513 | help='Indicates this is running on a remote trybot machine') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 514 | group.add_option('--buildbucket-id', |
Don Garrett | b01a8e6 | 2017-12-11 17:47:18 -0800 | [diff] [blame] | 515 | api=constants.REEXEC_API_GOMA, # Approximate. |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 516 | help='The unique ID in buildbucket of current build ' |
| 517 | 'generated by buildbucket.') |
Mike Frysinger | dad205d | 2017-08-11 16:00:14 -0400 | [diff] [blame] | 518 | group.add_remote_option('--remote-patches', action='split_extend', default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 519 | help='Patches uploaded by the trybot client when ' |
| 520 | 'run using the -p option') |
Brian Harring | f611e6e | 2012-07-17 18:47:44 -0700 | [diff] [blame] | 521 | # Note the default here needs to be hardcoded to 3; that is the last version |
| 522 | # that lacked this functionality. |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 523 | group.add_option('--remote-version', type='int', default=3, |
Don Garrett | bb965dc | 2017-09-14 17:24:18 -0700 | [diff] [blame] | 524 | help='Deprecated and ignored.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 525 | group.add_option('--sourceroot', type='path', default=constants.SOURCE_ROOT) |
| 526 | group.add_remote_option('--test-bootstrap', action='store_true', |
| 527 | default=False, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 528 | help='Causes cbuildbot to bootstrap itself twice, ' |
| 529 | 'in the sequence A->B->C: A(unpatched) patches ' |
| 530 | 'and bootstraps B; B patches and bootstraps C') |
| 531 | group.add_remote_option('--validation_pool', |
| 532 | help='Path to a pickled validation pool. Intended ' |
| 533 | 'for use only with the commit queue.') |
| 534 | group.add_remote_option('--metadata_dump', |
| 535 | help='Path to a json dumped metadata file. This ' |
| 536 | 'will be used as the initial metadata.') |
| 537 | group.add_remote_option('--master-build-id', type='int', |
Aviv Keshet | acf4cfb | 2014-07-30 12:31:22 -0700 | [diff] [blame] | 538 | api=constants.REEXEC_API_MASTER_BUILD_ID, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 539 | help='cidb build id of the master build to this ' |
| 540 | 'slave build.') |
Dhanya Ganesh | 6e0e028 | 2019-03-06 16:06:16 -0700 | [diff] [blame] | 541 | group.add_remote_option('--master-buildbucket-id', |
| 542 | api=constants.REEXEC_API_MASTER_BUILDBUCKET_ID, |
| 543 | help='buildbucket id of the master build to this ' |
| 544 | 'slave build.') |
Ningning Xia | 6c38165 | 2017-10-24 16:03:29 -0700 | [diff] [blame] | 545 | # TODO(nxia): crbug.com/778838 |
| 546 | # cbuildbot doesn't use pickle files anymore, remove this. |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 547 | group.add_remote_option('--mock-slave-status', |
| 548 | metavar='MOCK_SLAVE_STATUS_PICKLE_FILE', |
| 549 | help='Override the result of the _FetchSlaveStatuses ' |
| 550 | 'method of MasterSlaveSyncCompletionStage, by ' |
| 551 | 'specifying a file with a pickle of the result ' |
| 552 | 'to be returned.') |
Benjamin Gordon | 0443cb8 | 2018-04-17 12:38:49 -0600 | [diff] [blame] | 553 | group.add_option('--previous-build-state', type='string', default='', |
| 554 | api=constants.REEXEC_API_PREVIOUS_BUILD_STATE, |
| 555 | help='A base64-encoded BuildSummary object describing the ' |
| 556 | 'previous build run on the same build machine.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 557 | |
Mike Frysinger | 6889324 | 2017-08-11 14:16:39 -0400 | [diff] [blame] | 558 | parser.add_argument_group(group) |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 559 | |
| 560 | # |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 561 | # Debug options |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 562 | # |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 563 | # Temporary hack; in place till --dry-run replaces --debug. |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 564 | # pylint: disable=protected-access |
Brian Harring | 009db50 | 2012-10-10 02:21:37 -0700 | [diff] [blame] | 565 | group = parser.debug_group |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 566 | debug = [x for x in group.option_list if x._long_opts == ['--debug']][0] |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 567 | debug.help += ' Currently functions as --dry-run in addition.' |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 568 | debug.pass_through = True |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 569 | group.add_option('--notee', action='store_false', dest='tee', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 570 | help='Disable logging and internal tee process. Primarily ' |
| 571 | 'used for debugging cbuildbot itself.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 572 | return parser |
| 573 | |
| 574 | |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 575 | def _FinishParsing(options): |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 576 | """Perform some parsing tasks that need to take place after optparse. |
| 577 | |
| 578 | This function needs to be easily testable! Keep it free of |
| 579 | environment-dependent code. Put more detailed usage validation in |
| 580 | _PostParseCheck(). |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 581 | |
| 582 | Args: |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 583 | options: The options object returned by optparse |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 584 | """ |
Ryan Cui | 41023d9 | 2012-11-13 19:59:50 -0800 | [diff] [blame] | 585 | # Populate options.pass_through_args. |
| 586 | accepted, _ = commandline.FilteringParser.FilterArgs( |
| 587 | options.parsed_args, lambda x: x.opt_inst.pass_through) |
| 588 | options.pass_through_args.extend(accepted) |
Brian Harring | 07039b5 | 2012-05-13 17:56:47 -0700 | [diff] [blame] | 589 | |
Don Garrett | cc0ee52 | 2017-09-13 14:28:42 -0700 | [diff] [blame] | 590 | if options.local or options.remote: |
| 591 | cros_build_lib.Die('Deprecated usage. Please use cros tryjob instead.') |
| 592 | |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 593 | if not options.buildroot: |
| 594 | cros_build_lib.Die('A buildroot is required to build.') |
| 595 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 596 | if options.chrome_root: |
| 597 | if options.chrome_rev != constants.CHROME_REV_LOCAL: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 598 | cros_build_lib.Die('Chrome rev must be %s if chrome_root is set.' % |
| 599 | constants.CHROME_REV_LOCAL) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 600 | elif options.chrome_rev == constants.CHROME_REV_LOCAL: |
| 601 | cros_build_lib.Die('Chrome root must be set if chrome_rev is %s.' % |
| 602 | constants.CHROME_REV_LOCAL) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 603 | |
| 604 | if options.chrome_version: |
| 605 | if options.chrome_rev != constants.CHROME_REV_SPEC: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 606 | cros_build_lib.Die('Chrome rev must be %s if chrome_version is set.' % |
| 607 | constants.CHROME_REV_SPEC) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 608 | elif options.chrome_rev == constants.CHROME_REV_SPEC: |
| 609 | cros_build_lib.Die( |
| 610 | 'Chrome rev must not be %s if chrome_version is not set.' |
| 611 | % constants.CHROME_REV_SPEC) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 612 | |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 613 | patches = bool(options.gerrit_patches) |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 614 | |
David James | 5734ea3 | 2012-08-15 20:23:49 -0700 | [diff] [blame] | 615 | # When running in release mode, make sure we are running with checked-in code. |
| 616 | # We want checked-in cbuildbot/scripts to prevent errors, and we want to build |
| 617 | # a release image with checked-in code for CrOS packages. |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 618 | if options.buildbot and patches and not options.debug: |
David James | 5734ea3 | 2012-08-15 20:23:49 -0700 | [diff] [blame] | 619 | cros_build_lib.Die( |
| 620 | 'Cannot provide patches when running with --buildbot!') |
| 621 | |
Ryan Cui | ba41ad3 | 2012-03-08 17:15:29 -0800 | [diff] [blame] | 622 | if options.buildbot and options.remote_trybot: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 623 | cros_build_lib.Die( |
| 624 | '--buildbot and --remote-trybot cannot be used together.') |
Ryan Cui | ba41ad3 | 2012-03-08 17:15:29 -0800 | [diff] [blame] | 625 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 626 | # Record whether --debug was set explicitly vs. it was inferred. |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 627 | options.debug_forced = options.debug |
| 628 | # We force --debug to be set for builds that are not 'official'. |
| 629 | options.debug = options.debug or not options.buildbot |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 630 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 631 | |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 632 | # pylint: disable=unused-argument |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 633 | def _PostParseCheck(parser, options, site_config): |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 634 | """Perform some usage validation after we've parsed the arguments |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 635 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 636 | Args: |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 637 | parser: Option parser that was used to parse arguments. |
| 638 | options: The options returned by optparse. |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 639 | site_config: config_lib.SiteConfig containing all config info. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 640 | """ |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 641 | |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 642 | if not options.branch: |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 643 | options.branch = git.GetChromiteTrackingBranch() |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 644 | |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 645 | # Because the default cache dir depends on other options, FindCacheDir |
| 646 | # always returns None, and we setup the default here. |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 647 | if options.cache_dir is None: |
| 648 | # Note, options.sourceroot is set regardless of the path |
| 649 | # actually existing. |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 650 | options.cache_dir = os.path.join(options.buildroot, '.cache') |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 651 | options.cache_dir = os.path.abspath(options.cache_dir) |
Brian Harring | 8c1d7b1 | 2012-10-04 17:36:32 -0700 | [diff] [blame] | 652 | parser.ConfigureCacheDir(options.cache_dir) |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 653 | |
Yu-Ju Hong | 2c06676 | 2013-10-28 14:05:08 -0700 | [diff] [blame] | 654 | osutils.SafeMakedirsNonRoot(options.cache_dir) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 655 | |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 656 | # Ensure that all args are legitimate config targets. |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 657 | if options.build_config_name not in site_config: |
Stephen Boyd | eb0cd63 | 2019-04-25 11:51:08 -0700 | [diff] [blame] | 658 | cros_build_lib.Die('Unknown build config: "%s"' % options.build_config_name) |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 659 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 660 | build_config = site_config[options.build_config_name] |
| 661 | is_payloads_build = build_config.build_type == constants.PAYLOADS_TYPE |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 662 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 663 | if options.channels and not is_payloads_build: |
| 664 | cros_build_lib.Die('--channel must only be used with a payload config,' |
| 665 | ' not target (%s).' % options.build_config_name) |
Don Garrett | 5af1d26 | 2014-05-16 15:49:37 -0700 | [diff] [blame] | 666 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 667 | if not options.channels and is_payloads_build: |
| 668 | cros_build_lib.Die('payload configs (%s) require --channel to do anything' |
| 669 | ' useful.' % options.build_config_name) |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 670 | |
Don Garrett | 370839f | 2017-10-19 18:32:34 -0700 | [diff] [blame] | 671 | # If the build config explicitly forces the debug flag, set the debug flag |
| 672 | # as if it was set from the command line. |
| 673 | if build_config.debug: |
| 674 | options.debug = True |
| 675 | |
Don Garrett | 8bd5256 | 2017-11-20 14:16:37 -0800 | [diff] [blame] | 676 | if not (config_lib.isTryjobConfig(build_config) or options.buildbot): |
Don Garrett | 02d2f58 | 2017-11-08 14:01:24 -0800 | [diff] [blame] | 677 | cros_build_lib.Die( |
| 678 | 'Refusing to run non-tryjob config as a tryjob.\n' |
Don Garrett | 8bd5256 | 2017-11-20 14:16:37 -0800 | [diff] [blame] | 679 | 'Please "repo sync && cros tryjob --list %s" for alternatives.\n' |
Don Garrett | f666179 | 2017-11-15 13:13:23 -0800 | [diff] [blame] | 680 | 'See go/cros-explicit-tryjob-build-configs-psa.', |
Don Garrett | 02d2f58 | 2017-11-08 14:01:24 -0800 | [diff] [blame] | 681 | build_config.name) |
| 682 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 683 | # The --version option is not compatible with an external target unless the |
| 684 | # --buildbot option is specified. More correctly, only "paladin versions" |
| 685 | # will work with external targets, and those are only used with --buildbot. |
| 686 | # If --buildbot is specified, then user should know what they are doing and |
| 687 | # only specify a version that will work. See crbug.com/311648. |
| 688 | if (options.force_version and |
| 689 | not (options.buildbot or build_config.internal)): |
| 690 | cros_build_lib.Die('Cannot specify --version without --buildbot for an' |
| 691 | ' external target (%s).' % options.build_config_name) |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 692 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 693 | |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 694 | def ParseCommandLine(parser, argv): |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 695 | """Completely parse the commandline arguments""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 696 | (options, args) = parser.parse_args(argv) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 697 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 698 | # Handle the request for the reexec command line API version number. |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 699 | if options.output_api_version: |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 700 | print(constants.REEXEC_API_VERSION) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 701 | sys.exit(0) |
| 702 | |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 703 | # Record the configs targeted. Strip out null arguments. |
| 704 | build_config_names = [x for x in args if x] |
| 705 | if len(build_config_names) != 1: |
| 706 | cros_build_lib.Die('Expected exactly one build config. Got: %r', |
| 707 | build_config_names) |
| 708 | options.build_config_name = build_config_names[-1] |
| 709 | |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 710 | _FinishParsing(options) |
| 711 | return options |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 712 | |
| 713 | |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 714 | _ENVIRONMENT_PROD = 'prod' |
| 715 | _ENVIRONMENT_DEBUG = 'debug' |
| 716 | _ENVIRONMENT_STANDALONE = 'standalone' |
| 717 | |
| 718 | |
| 719 | def _GetRunEnvironment(options, build_config): |
| 720 | """Determine whether this is a prod/debug/standalone run.""" |
Don Garrett | a90f014 | 2018-02-28 14:25:19 -0800 | [diff] [blame] | 721 | if options.debug_cidb: |
| 722 | return _ENVIRONMENT_DEBUG |
| 723 | |
Don Garrett | 63765c4 | 2017-11-03 16:54:20 -0700 | [diff] [blame] | 724 | # One of these arguments should always be set if running on a real builder. |
| 725 | # If we aren't on a real builder, we are standalone. |
| 726 | if not options.buildbot and not options.remote_trybot: |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 727 | return _ENVIRONMENT_STANDALONE |
| 728 | |
Don Garrett | 63765c4 | 2017-11-03 16:54:20 -0700 | [diff] [blame] | 729 | if build_config['debug_cidb']: |
| 730 | return _ENVIRONMENT_DEBUG |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 731 | |
Don Garrett | 63765c4 | 2017-11-03 16:54:20 -0700 | [diff] [blame] | 732 | return _ENVIRONMENT_PROD |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 733 | |
| 734 | |
Gabe Black | de694a3 | 2015-02-19 15:11:11 -0800 | [diff] [blame] | 735 | def _SetupConnections(options, build_config): |
Aviv Keshet | 5549124 | 2017-07-13 17:04:07 -0700 | [diff] [blame] | 736 | """Set up CIDB connections using the appropriate Setup call. |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 737 | |
| 738 | Args: |
| 739 | options: Command line options structure. |
Aviv Keshet | 6413302 | 2014-08-25 15:50:52 -0700 | [diff] [blame] | 740 | build_config: Config object for this build. |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 741 | """ |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 742 | # Outline: |
| 743 | # 1) Based on options and build_config, decide whether we are a production |
| 744 | # run, debug run, or standalone run. |
| 745 | # 2) Set up cidb instance accordingly. |
| 746 | # 3) Update topology info from cidb, so that any other service set up can use |
| 747 | # topology. |
| 748 | # 4) Set up any other services. |
| 749 | run_type = _GetRunEnvironment(options, build_config) |
| 750 | |
| 751 | if run_type == _ENVIRONMENT_PROD: |
| 752 | cidb.CIDBConnectionFactory.SetupProdCidb() |
Mike Frysinger | cc292b4 | 2019-12-11 13:12:35 -0500 | [diff] [blame] | 753 | context = ts_mon_config.SetupTsMonGlobalState('cbuildbot', indirect=True) |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 754 | elif run_type == _ENVIRONMENT_DEBUG: |
| 755 | cidb.CIDBConnectionFactory.SetupDebugCidb() |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 756 | context = ts_mon_config.TrivialContextManager() |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 757 | else: |
Aviv Keshet | 62d1a0e | 2014-08-22 21:16:13 -0700 | [diff] [blame] | 758 | cidb.CIDBConnectionFactory.SetupNoCidb() |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 759 | context = ts_mon_config.TrivialContextManager() |
Aviv Keshet | 62d1a0e | 2014-08-22 21:16:13 -0700 | [diff] [blame] | 760 | |
Dhanya Ganesh | ef0cd5b | 2019-02-06 16:29:36 -0700 | [diff] [blame] | 761 | topology.FetchTopology() |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 762 | return context |
| 763 | |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 764 | |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 765 | class _MockMethodWithReturnValue(object): |
| 766 | """A method mocker which just returns the specific value.""" |
| 767 | def __init__(self, return_value): |
| 768 | self.return_value = return_value |
| 769 | |
| 770 | def __call__(self, *args, **kwargs): |
| 771 | return self.return_value |
| 772 | |
| 773 | |
| 774 | class _ObjectMethodPatcher(object): |
| 775 | """A simplified mock.object.patch. |
| 776 | |
| 777 | It is a context manager that patches an object's method with specified |
| 778 | return value. |
| 779 | """ |
| 780 | def __init__(self, target, attr, return_value=None): |
| 781 | """Constructor. |
| 782 | |
| 783 | Args: |
| 784 | target: object to patch. |
| 785 | attr: method name of the object to patch. |
| 786 | return_value: the return value when calling target.attr |
| 787 | """ |
| 788 | self.target = target |
| 789 | self.attr = attr |
| 790 | self.return_value = return_value |
| 791 | self.original_attr = None |
| 792 | self.new_attr = _MockMethodWithReturnValue(self.return_value) |
| 793 | |
| 794 | def __enter__(self): |
| 795 | self.original_attr = self.target.__dict__[self.attr] |
| 796 | setattr(self.target, self.attr, self.new_attr) |
| 797 | |
| 798 | def __exit__(self, *args): |
| 799 | if self.target and self.original_attr: |
| 800 | setattr(self.target, self.attr, self.original_attr) |
| 801 | |
| 802 | |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 803 | # TODO(build): This function is too damn long. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 804 | def main(argv): |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 805 | # We get false positives with the options object. |
| 806 | # pylint: disable=attribute-defined-outside-init |
| 807 | |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 808 | # Turn on strict sudo checks. |
| 809 | cros_build_lib.STRICT_SUDO = True |
| 810 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 811 | # Set umask to 022 so files created by buildbot are readable. |
Mike Frysinger | 60ec101 | 2013-10-21 00:11:10 -0400 | [diff] [blame] | 812 | os.umask(0o22) |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 813 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 814 | parser = _CreateParser() |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 815 | options = ParseCommandLine(parser, argv) |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 816 | |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 817 | # Fetch our site_config now, because we need it to do anything else. |
Don Garrett | de81cc7 | 2015-07-07 13:23:28 -0700 | [diff] [blame] | 818 | site_config = config_lib.GetConfig() |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 819 | |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 820 | _PostParseCheck(parser, options, site_config) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 821 | |
Mike Frysinger | 8fd67dc | 2012-12-03 23:51:18 -0500 | [diff] [blame] | 822 | cros_build_lib.AssertOutsideChroot() |
Zdenek Behan | 98ec2fb | 2012-08-31 17:12:18 +0200 | [diff] [blame] | 823 | |
Prathmesh Prabhu | 51d774f | 2015-07-17 15:11:49 -0700 | [diff] [blame] | 824 | if options.enable_buildbot_tags: |
| 825 | logging.EnableBuildbotMarkers() |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 826 | |
Don Garrett | 0c6e027 | 2017-12-13 17:05:21 -0800 | [diff] [blame] | 827 | if (options.buildbot and |
| 828 | not options.debug and |
Don Garrett | 0c6e027 | 2017-12-13 17:05:21 -0800 | [diff] [blame] | 829 | not cros_build_lib.HostIsCIBuilder()): |
Evan Hernandez | 73263be | 2019-03-14 15:17:59 -0600 | [diff] [blame] | 830 | # --buildbot can only be used on a real builder, unless it's debug. |
Don Garrett | 0c6e027 | 2017-12-13 17:05:21 -0800 | [diff] [blame] | 831 | cros_build_lib.Die('This host is not a supported build machine.') |
Ningning Xia | c691e43 | 2016-08-11 14:52:59 -0700 | [diff] [blame] | 832 | |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 833 | # Only one config arg is allowed in this mode, which was confirmed earlier. |
Don Garrett | f076115 | 2017-10-19 19:38:27 -0700 | [diff] [blame] | 834 | build_config = site_config[options.build_config_name] |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 835 | |
Don Garrett | bbd7b55 | 2014-05-16 13:15:21 -0700 | [diff] [blame] | 836 | # TODO: Re-enable this block when reference_repo support handles this |
| 837 | # properly. (see chromium:330775) |
| 838 | # if options.reference_repo is None: |
| 839 | # repo_path = os.path.join(options.sourceroot, '.repo') |
| 840 | # # If we're being run from a repo checkout, reuse the repo's git pool to |
| 841 | # # cut down on sync time. |
| 842 | # if os.path.exists(repo_path): |
| 843 | # options.reference_repo = options.sourceroot |
| 844 | |
| 845 | if options.reference_repo: |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 846 | if not os.path.exists(options.reference_repo): |
| 847 | parser.error('Reference path %s does not exist' |
| 848 | % (options.reference_repo,)) |
| 849 | elif not os.path.exists(os.path.join(options.reference_repo, '.repo')): |
| 850 | parser.error('Reference path %s does not look to be the base of a ' |
| 851 | 'repo checkout; no .repo exists in the root.' |
| 852 | % (options.reference_repo,)) |
| 853 | |
Brian Harring | f11bf68 | 2012-05-14 15:53:43 -0700 | [diff] [blame] | 854 | if (options.buildbot or options.remote_trybot) and not options.resume: |
Brian Harring | 470f611 | 2012-03-02 11:47:10 -0800 | [diff] [blame] | 855 | if not options.cgroups: |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 856 | parser.error('Options --buildbot/--remote-trybot and --nocgroups cannot ' |
| 857 | 'be used together. Cgroup support is required for ' |
| 858 | 'buildbot/remote-trybot mode.') |
Mike Frysinger | a78a56e | 2012-11-20 06:02:30 -0500 | [diff] [blame] | 859 | if not cgroups.Cgroup.IsSupported(): |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 860 | parser.error('Option --buildbot/--remote-trybot was given, but this ' |
| 861 | 'system does not support cgroups. Failing.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 862 | |
David James | aad5cc7 | 2012-10-26 15:03:13 -0700 | [diff] [blame] | 863 | missing = osutils.FindMissingBinaries(_BUILDBOT_REQUIRED_BINARIES) |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 864 | if missing: |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 865 | parser.error('Option --buildbot/--remote-trybot requires the following ' |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 866 | "binaries which couldn't be found in $PATH: %s" |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 867 | % (', '.join(missing))) |
| 868 | |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 869 | if options.reference_repo: |
| 870 | options.reference_repo = os.path.abspath(options.reference_repo) |
| 871 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 872 | # Sanity check of buildroot- specifically that it's not pointing into the |
| 873 | # midst of an existing repo since git-repo doesn't support nesting. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 874 | if (not repository.IsARepoRoot(options.buildroot) and |
David James | 13a69c9 | 2013-05-09 10:37:42 -0700 | [diff] [blame] | 875 | git.FindRepoDir(options.buildroot)): |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 876 | cros_build_lib.Die( |
| 877 | 'Configured buildroot %s is a subdir of an existing repo checkout.' |
| 878 | % options.buildroot) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 879 | |
Chris Sosa | b5ea3b4 | 2012-10-25 15:25:20 -0700 | [diff] [blame] | 880 | if not options.log_dir: |
| 881 | options.log_dir = os.path.join(options.buildroot, _DEFAULT_LOG_DIR) |
| 882 | |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 883 | log_file = None |
| 884 | if options.tee: |
Chris Sosa | b5ea3b4 | 2012-10-25 15:25:20 -0700 | [diff] [blame] | 885 | log_file = os.path.join(options.log_dir, _BUILDBOT_LOG_FILE) |
| 886 | osutils.SafeMakedirs(options.log_dir) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 887 | _BackupPreviousLog(log_file) |
| 888 | |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 889 | with cros_build_lib.ContextManagerStack() as stack: |
Lann Martin | 8cc2eab | 2018-09-05 17:17:57 -0600 | [diff] [blame] | 890 | # Preserve chromite; we might be running from there! |
| 891 | options.preserve_paths = set(['chromite']) |
David James | cebc727 | 2013-07-17 16:45:05 -0700 | [diff] [blame] | 892 | if log_file is not None: |
| 893 | # We don't want the critical section to try to clean up the tee process, |
| 894 | # so we run Tee (forked off) outside of it. This prevents a deadlock |
| 895 | # because the Tee process only exits when its pipe is closed, and the |
| 896 | # critical section accidentally holds on to that file handle. |
| 897 | stack.Add(tee.Tee, log_file) |
| 898 | options.preserve_paths.add(_DEFAULT_LOG_DIR) |
| 899 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 900 | critical_section = stack.Add(cleanup.EnforcedCleanupSection) |
| 901 | stack.Add(sudo.SudoKeepAlive) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 902 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 903 | if not options.resume: |
Brian Harring | 2bf55e1 | 2012-05-13 21:31:55 -0700 | [diff] [blame] | 904 | # If we're in resume mode, use our parents tempdir rather than |
| 905 | # nesting another layer. |
David James | 4bc1370 | 2013-03-26 08:08:04 -0700 | [diff] [blame] | 906 | stack.Add(osutils.TempDir, prefix='cbuildbot-tmp', set_global=True) |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 907 | logging.debug('Cbuildbot tempdir is %r.', os.environ.get('TMP')) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 908 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 909 | if options.cgroups: |
| 910 | stack.Add(cgroups.SimpleContainChildren, 'cbuildbot') |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 911 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 912 | # Mark everything between EnforcedCleanupSection and here as having to |
| 913 | # be rolled back via the contextmanager cleanup handlers. This |
| 914 | # ensures that sudo bits cannot outlive cbuildbot, that anything |
| 915 | # cgroups would kill gets killed, etc. |
David James | fb3aac9 | 2013-10-16 13:26:52 -0700 | [diff] [blame] | 916 | stack.Add(critical_section.ForkWatchdog) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 917 | |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 918 | if options.mock_slave_status is not None: |
| 919 | with open(options.mock_slave_status, 'r') as f: |
Aviv Keshet | 4e75002 | 2014-03-07 16:50:34 -0800 | [diff] [blame] | 920 | mock_statuses = pickle.load(f) |
Mike Frysinger | 0bdbc10 | 2019-06-13 15:27:29 -0400 | [diff] [blame] | 921 | for key, value in mock_statuses.items(): |
Ningning Xia | f342b95 | 2017-02-15 14:13:33 -0800 | [diff] [blame] | 922 | mock_statuses[key] = builder_status_lib.BuilderStatus(**value) |
Dean Liao | e5b0aca | 2018-01-24 15:27:26 +0800 | [diff] [blame] | 923 | stack.Add(_ObjectMethodPatcher, |
Yu-Ju Hong | d0fda38 | 2014-05-09 15:28:24 -0700 | [diff] [blame] | 924 | completion_stages.MasterSlaveSyncCompletionStage, |
| 925 | '_FetchSlaveStatuses', |
| 926 | return_value=mock_statuses) |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 927 | |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 928 | stack.Add(_SetupConnections, options, build_config) |
Don Garrett | b431836 | 2014-10-03 15:49:36 -0700 | [diff] [blame] | 929 | retry_stats.SetupStats() |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 930 | |
Dhanya Ganesh | 4339cbc | 2019-03-08 12:02:14 -0700 | [diff] [blame] | 931 | timeout_display_message = ( |
| 932 | 'This build has reached the timeout deadline set by the master. ' |
| 933 | 'Either this stage or a previous one took too long (see stage ' |
| 934 | 'timing historical summary in ReportStage) or the build failed ' |
| 935 | 'to start on time.') |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 936 | |
| 937 | if options.timeout > 0: |
Aviv Keshet | 446f07f | 2016-03-08 11:32:31 -0800 | [diff] [blame] | 938 | stack.Add(timeout_util.FatalTimeout, options.timeout, |
| 939 | timeout_display_message) |
Ningning Xia | ad48354 | 2016-05-24 12:27:21 -0700 | [diff] [blame] | 940 | try: |
| 941 | _RunBuildStagesWrapper(options, site_config, build_config) |
| 942 | except failures_lib.ExitEarlyException as ex: |
| 943 | # This build finished successfully. Do not re-raise ExitEarlyException. |
| 944 | logging.info('One stage exited early: %s', ex) |