Mike Frysinger | d6925b5 | 2012-07-16 16:11:00 -0400 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
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 | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 11 | from __future__ import print_function |
| 12 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 13 | import distutils.version |
| 14 | import glob |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 15 | import json |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 16 | import mock |
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 remote_try |
| 25 | from chromite.cbuildbot import repository |
| 26 | from chromite.cbuildbot import tee |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 27 | from chromite.cbuildbot import topology |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 28 | from chromite.cbuildbot import trybot_patch_pool |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 29 | from chromite.cbuildbot.stages import completion_stages |
Ningning Xia | f342b95 | 2017-02-15 14:13:33 -0800 | [diff] [blame] | 30 | from chromite.lib import builder_status_lib |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 31 | from chromite.lib import cidb |
Brian Harring | c92a701 | 2012-02-29 10:11:34 -0800 | [diff] [blame] | 32 | from chromite.lib import cgroups |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 33 | from chromite.lib import cleanup |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 34 | from chromite.lib import commandline |
Ningning Xia | 6a71805 | 2016-12-22 10:08:15 -0800 | [diff] [blame] | 35 | from chromite.lib import config_lib |
| 36 | from chromite.lib import constants |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 37 | from chromite.lib import cros_build_lib |
Ralph Nathan | 91874ca | 2015-03-19 13:29:41 -0700 | [diff] [blame] | 38 | from chromite.lib import cros_logging as logging |
Ningning Xia | 6a71805 | 2016-12-22 10:08:15 -0800 | [diff] [blame] | 39 | from chromite.lib import failures_lib |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 40 | from chromite.lib import git |
Stefan Zager | d49d9ff | 2014-08-15 21:33:37 -0700 | [diff] [blame] | 41 | from chromite.lib import gob_util |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 42 | from chromite.lib import osutils |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 43 | from chromite.lib import parallel |
Don Garrett | b431836 | 2014-10-03 15:49:36 -0700 | [diff] [blame] | 44 | from chromite.lib import retry_stats |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 45 | from chromite.lib import sudo |
David James | 3432acd | 2013-11-27 10:02:18 -0800 | [diff] [blame] | 46 | from chromite.lib import timeout_util |
Drew Davenport | d7c22c1 | 2017-06-07 16:16:54 -0600 | [diff] [blame] | 47 | from chromite.lib import tree_status |
Paul Hobbs | fcf1034 | 2015-12-29 15:52:31 -0800 | [diff] [blame] | 48 | from chromite.lib import ts_mon_config |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 49 | |
Ryan Cui | add4912 | 2012-03-21 22:19:58 -0700 | [diff] [blame] | 50 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 51 | _DEFAULT_LOG_DIR = 'cbuildbot_logs' |
| 52 | _BUILDBOT_LOG_FILE = 'cbuildbot.log' |
| 53 | _DEFAULT_EXT_BUILDROOT = 'trybot' |
| 54 | _DEFAULT_INT_BUILDROOT = 'trybot-internal' |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 55 | _BUILDBOT_REQUIRED_BINARIES = ('pbzip2',) |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 56 | _API_VERSION_ATTR = 'api_version' |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 57 | |
| 58 | |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 59 | def _PrintValidConfigs(site_config, display_all=False): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 60 | """Print a list of valid buildbot configs. |
| 61 | |
Mike Frysinger | 02e1e07 | 2013-11-10 22:11:34 -0500 | [diff] [blame] | 62 | Args: |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 63 | site_config: config_lib.SiteConfig containing all config info. |
Ryan Cui | 4f6cf7e | 2012-04-18 16:12:27 -0700 | [diff] [blame] | 64 | display_all: Print all configs. Otherwise, prints only configs with |
| 65 | trybot_list=True. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 66 | """ |
Ryan Cui | 4f6cf7e | 2012-04-18 16:12:27 -0700 | [diff] [blame] | 67 | def _GetSortKey(config_name): |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 68 | config_dict = site_config[config_name] |
Ryan Cui | 4f6cf7e | 2012-04-18 16:12:27 -0700 | [diff] [blame] | 69 | return (not config_dict['trybot_list'], config_dict['description'], |
| 70 | config_name) |
| 71 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 72 | COLUMN_WIDTH = 45 |
Mike Frysinger | 13b0888 | 2015-05-28 04:36:10 -0400 | [diff] [blame] | 73 | if not display_all: |
| 74 | print('Note: This is the common list; for all configs, use --all.') |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 75 | print('config'.ljust(COLUMN_WIDTH), 'description') |
| 76 | print('------'.ljust(COLUMN_WIDTH), '-----------') |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 77 | config_names = site_config.keys() |
Ryan Cui | 4f6cf7e | 2012-04-18 16:12:27 -0700 | [diff] [blame] | 78 | config_names.sort(key=_GetSortKey) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 79 | for name in config_names: |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 80 | if display_all or site_config[name]['trybot_list']: |
| 81 | desc = site_config[name].get('description') |
Ryan Cui | 4f6cf7e | 2012-04-18 16:12:27 -0700 | [diff] [blame] | 82 | desc = desc if desc else '' |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 83 | print(name.ljust(COLUMN_WIDTH), desc) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 84 | |
| 85 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 86 | def _ConfirmBuildRoot(buildroot): |
| 87 | """Confirm with user the inferred buildroot, and mark it as confirmed.""" |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 88 | logging.warning('Using default directory %s as buildroot', buildroot) |
Brian Harring | 521e724 | 2012-11-01 16:57:42 -0700 | [diff] [blame] | 89 | if not cros_build_lib.BooleanPrompt(default=False): |
| 90 | print('Please specify a different buildroot via the --buildroot option.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 91 | sys.exit(0) |
| 92 | |
| 93 | if not os.path.exists(buildroot): |
| 94 | os.mkdir(buildroot) |
| 95 | |
| 96 | repository.CreateTrybotMarker(buildroot) |
| 97 | |
| 98 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 99 | def _ConfirmRemoteBuildbotRun(): |
| 100 | """Confirm user wants to run with --buildbot --remote.""" |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 101 | logging.warning( |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 102 | 'You are about to launch a PRODUCTION job! This is *NOT* a ' |
| 103 | 'trybot run! Are you sure?') |
Brian Harring | 521e724 | 2012-11-01 16:57:42 -0700 | [diff] [blame] | 104 | if not cros_build_lib.BooleanPrompt(default=False): |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 105 | print('Please specify --pass-through="--debug".') |
| 106 | sys.exit(0) |
| 107 | |
| 108 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 109 | def _DetermineDefaultBuildRoot(sourceroot, internal_build): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 110 | """Default buildroot to be under the directory that contains current checkout. |
| 111 | |
Mike Frysinger | 02e1e07 | 2013-11-10 22:11:34 -0500 | [diff] [blame] | 112 | Args: |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 113 | internal_build: Whether the build is an internal build |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 114 | sourceroot: Use specified sourceroot. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 115 | """ |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 116 | if not repository.IsARepoRoot(sourceroot): |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 117 | cros_build_lib.Die( |
| 118 | 'Could not find root of local checkout at %s. Please specify ' |
| 119 | 'using the --sourceroot option.' % sourceroot) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 120 | |
| 121 | # Place trybot buildroot under the directory containing current checkout. |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 122 | top_level = os.path.dirname(os.path.realpath(sourceroot)) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 123 | if internal_build: |
| 124 | buildroot = os.path.join(top_level, _DEFAULT_INT_BUILDROOT) |
| 125 | else: |
| 126 | buildroot = os.path.join(top_level, _DEFAULT_EXT_BUILDROOT) |
| 127 | |
| 128 | return buildroot |
| 129 | |
| 130 | |
| 131 | def _BackupPreviousLog(log_file, backup_limit=25): |
| 132 | """Rename previous log. |
| 133 | |
| 134 | Args: |
| 135 | log_file: The absolute path to the previous log. |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 136 | backup_limit: Maximum number of old logs to keep. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 137 | """ |
| 138 | if os.path.exists(log_file): |
| 139 | old_logs = sorted(glob.glob(log_file + '.*'), |
| 140 | key=distutils.version.LooseVersion) |
| 141 | |
| 142 | if len(old_logs) >= backup_limit: |
| 143 | os.remove(old_logs[0]) |
| 144 | |
| 145 | last = 0 |
| 146 | if old_logs: |
| 147 | last = int(old_logs.pop().rpartition('.')[2]) |
| 148 | |
| 149 | os.rename(log_file, log_file + '.' + str(last + 1)) |
| 150 | |
Ryan Cui | 5616a51 | 2012-08-17 13:39:36 -0700 | [diff] [blame] | 151 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 152 | def _IsDistributedBuilder(options, chrome_rev, build_config): |
| 153 | """Determines whether the builder should be a DistributedBuilder. |
| 154 | |
| 155 | Args: |
| 156 | options: options passed on the commandline. |
| 157 | chrome_rev: Chrome revision to build. |
| 158 | build_config: Builder configuration dictionary. |
| 159 | |
| 160 | Returns: |
| 161 | True if the builder should be a distributed_builder |
| 162 | """ |
Don Garrett | 0bc8567 | 2015-07-23 19:46:00 +0000 | [diff] [blame] | 163 | if build_config['pre_cq']: |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 164 | return True |
| 165 | elif not options.buildbot: |
| 166 | return False |
| 167 | elif chrome_rev in (constants.CHROME_REV_TOT, |
| 168 | constants.CHROME_REV_LOCAL, |
| 169 | constants.CHROME_REV_SPEC): |
| 170 | # We don't do distributed logic to TOT Chrome PFQ's, nor local |
| 171 | # chrome roots (e.g. chrome try bots) |
| 172 | # TODO(davidjames): Update any builders that rely on this logic to use |
| 173 | # manifest_version=False instead. |
| 174 | return False |
| 175 | elif build_config['manifest_version']: |
| 176 | return True |
| 177 | |
| 178 | return False |
| 179 | |
| 180 | |
Don Garrett | a52a5b0 | 2015-06-02 14:52:57 -0700 | [diff] [blame] | 181 | def _RunBuildStagesWrapper(options, site_config, build_config): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 182 | """Helper function that wraps RunBuildStages().""" |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 183 | logging.info('cbuildbot was executed with args %s' % |
| 184 | cros_build_lib.CmdToStr(sys.argv)) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 185 | |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 186 | chrome_rev = build_config['chrome_rev'] |
| 187 | if options.chrome_rev: |
| 188 | chrome_rev = options.chrome_rev |
| 189 | if chrome_rev == constants.CHROME_REV_TOT: |
Stefan Zager | d49d9ff | 2014-08-15 21:33:37 -0700 | [diff] [blame] | 190 | options.chrome_version = gob_util.GetTipOfTrunkRevision( |
| 191 | constants.CHROMIUM_GOB_URL) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 192 | options.chrome_rev = constants.CHROME_REV_SPEC |
| 193 | |
David James | 4a404a5 | 2013-02-19 13:07:59 -0800 | [diff] [blame] | 194 | # 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] | 195 | if build_config['sync_chrome'] is None: |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 196 | options.managed_chrome = ( |
| 197 | chrome_rev != constants.CHROME_REV_LOCAL and |
Mike Frysinger | f4d9ab8 | 2013-03-05 19:38:05 -0500 | [diff] [blame] | 198 | (not build_config['usepkg_build_packages'] or chrome_rev or |
David James | 3cce464 | 2013-05-10 17:50:23 -0700 | [diff] [blame] | 199 | build_config['profile'] or options.rietveld_patches)) |
Mike Frysinger | f4d9ab8 | 2013-03-05 19:38:05 -0500 | [diff] [blame] | 200 | else: |
| 201 | options.managed_chrome = build_config['sync_chrome'] |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 202 | |
| 203 | if options.managed_chrome: |
| 204 | # Tell Chrome to fetch the source locally. |
Matt Tennant | 628ffdd | 2013-11-27 14:44:39 -0800 | [diff] [blame] | 205 | internal = constants.USE_CHROME_INTERNAL in build_config['useflags'] |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 206 | chrome_src = 'chrome-src-internal' if internal else 'chrome-src' |
YH Lin | b1ea83c | 2016-10-13 15:47:09 -0700 | [diff] [blame] | 207 | target_name = 'target' |
| 208 | if options.branch: |
| 209 | # Tie the cache per branch |
| 210 | target_name = 'target-%s' % options.branch |
| 211 | options.chrome_root = os.path.join(options.cache_dir, 'distfiles', |
| 212 | target_name, chrome_src) |
| 213 | # Create directory if in need |
| 214 | osutils.SafeMakedirsNonRoot(options.chrome_root) |
David James | 9e27e66 | 2013-02-14 13:42:43 -0800 | [diff] [blame] | 215 | elif options.rietveld_patches: |
David James | 4a404a5 | 2013-02-19 13:07:59 -0800 | [diff] [blame] | 216 | cros_build_lib.Die('This builder does not support Rietveld patches.') |
David James | 2333c18 | 2013-02-13 16:16:15 -0800 | [diff] [blame] | 217 | |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 218 | metadata_dump_dict = {} |
| 219 | if options.metadata_dump: |
| 220 | with open(options.metadata_dump, 'r') as metadata_file: |
| 221 | metadata_dump_dict = json.loads(metadata_file.read()) |
| 222 | |
Matt Tennant | 95a42ad | 2013-12-27 15:38:36 -0800 | [diff] [blame] | 223 | # We are done munging options values, so freeze options object now to avoid |
| 224 | # further abuse of it. |
| 225 | # TODO(mtennant): one by one identify each options value override and see if |
| 226 | # it can be handled another way. Try to push this freeze closer and closer |
| 227 | # to the start of the script (e.g. in or after _PostParseCheck). |
| 228 | options.Freeze() |
| 229 | |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 230 | with parallel.Manager() as manager: |
Don Garrett | a52a5b0 | 2015-06-02 14:52:57 -0700 | [diff] [blame] | 231 | builder_run = cbuildbot_run.BuilderRun( |
| 232 | options, site_config, build_config, manager) |
Aviv Keshet | 669eb5e | 2014-06-23 08:53:01 -0700 | [diff] [blame] | 233 | if metadata_dump_dict: |
| 234 | builder_run.attrs.metadata.UpdateWithDict(metadata_dump_dict) |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 235 | |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 236 | if builder_run.config.builder_class_name is None: |
Don Garrett | 56e6ed3 | 2015-06-23 16:52:20 -0700 | [diff] [blame] | 237 | # TODO: This should get relocated to chromeos_config. |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 238 | if _IsDistributedBuilder(options, chrome_rev, build_config): |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 239 | builder_cls_name = 'simple_builders.DistributedBuilder' |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 240 | else: |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 241 | builder_cls_name = 'simple_builders.SimpleBuilder' |
| 242 | builder_cls = builders.GetBuilderClass(builder_cls_name) |
| 243 | builder = builder_cls(builder_run) |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 244 | else: |
Mike Frysinger | 05c5faf | 2015-02-04 21:46:46 -0500 | [diff] [blame] | 245 | builder = builders.Builder(builder_run) |
Mike Frysinger | e4d68c2 | 2015-02-04 21:26:24 -0500 | [diff] [blame] | 246 | |
Matt Tennant | 0940c38 | 2014-01-21 20:43:55 -0800 | [diff] [blame] | 247 | if not builder.Run(): |
| 248 | sys.exit(1) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 249 | |
| 250 | |
| 251 | # Parser related functions |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 252 | def _CheckLocalPatches(sourceroot, local_patches): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 253 | """Do an early quick check of the passed-in patches. |
| 254 | |
| 255 | If the branch of a project is not specified we append the current branch the |
| 256 | project is on. |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 257 | |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 258 | TODO(davidjames): The project:branch format isn't unique, so this means that |
| 259 | we can't differentiate what directory the user intended to apply patches to. |
| 260 | We should references by directory instead. |
| 261 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 262 | Args: |
| 263 | sourceroot: The checkout where patches are coming from. |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 264 | local_patches: List of patches to check in project:branch format. |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 265 | |
| 266 | Returns: |
| 267 | A list of patches that have been verified, in project:branch format. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 268 | """ |
Ryan Cui | cedd8a5 | 2012-03-22 02:28:35 -0700 | [diff] [blame] | 269 | verified_patches = [] |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 270 | manifest = git.ManifestCheckout.Cached(sourceroot) |
Ryan Cui | cedd8a5 | 2012-03-22 02:28:35 -0700 | [diff] [blame] | 271 | for patch in local_patches: |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 272 | project, _, branch = patch.partition(':') |
| 273 | |
David James | e6301e0 | 2016-11-03 17:14:03 -0700 | [diff] [blame] | 274 | checkouts = manifest.FindCheckouts(project) |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 275 | if not checkouts: |
| 276 | cros_build_lib.Die('Project %s does not exist.' % (project,)) |
| 277 | if len(checkouts) > 1: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 278 | cros_build_lib.Die( |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 279 | 'We do not yet support local patching for projects that are checked ' |
| 280 | 'out to multiple directories. Try uploading your patch to gerrit ' |
| 281 | 'and referencing it via the -g option instead.' |
| 282 | ) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 283 | |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 284 | ok = False |
| 285 | for checkout in checkouts: |
| 286 | project_dir = checkout.GetPath(absolute=True) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 287 | |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 288 | # If no branch was specified, we use the project's current branch. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 289 | if not branch: |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 290 | local_branch = git.GetCurrentBranch(project_dir) |
| 291 | else: |
| 292 | local_branch = branch |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 293 | |
David James | f1a0761 | 2014-04-28 17:48:52 -0700 | [diff] [blame] | 294 | if local_branch and git.DoesCommitExistInRepo(project_dir, local_branch): |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 295 | verified_patches.append('%s:%s' % (project, local_branch)) |
| 296 | ok = True |
| 297 | |
| 298 | if not ok: |
| 299 | if branch: |
| 300 | cros_build_lib.Die('Project %s does not have branch %s' |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 301 | % (project, branch)) |
David James | e3b0606 | 2013-11-09 18:52:02 -0800 | [diff] [blame] | 302 | else: |
| 303 | cros_build_lib.Die('Project %s is not on a branch!' % (project,)) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 304 | |
Ryan Cui | cedd8a5 | 2012-03-22 02:28:35 -0700 | [diff] [blame] | 305 | return verified_patches |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 306 | |
| 307 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 308 | def _CheckChromeVersionOption(_option, _opt_str, value, parser): |
| 309 | """Upgrade other options based on chrome_version being passed.""" |
| 310 | value = value.strip() |
| 311 | |
| 312 | if parser.values.chrome_rev is None and value: |
| 313 | parser.values.chrome_rev = constants.CHROME_REV_SPEC |
| 314 | |
| 315 | parser.values.chrome_version = value |
| 316 | |
| 317 | |
| 318 | def _CheckChromeRootOption(_option, _opt_str, value, parser): |
| 319 | """Validate and convert chrome_root to full-path form.""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 320 | if parser.values.chrome_rev is None: |
| 321 | parser.values.chrome_rev = constants.CHROME_REV_LOCAL |
| 322 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 323 | parser.values.chrome_root = value |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 324 | |
| 325 | |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 326 | def FindCacheDir(_parser, _options): |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 327 | return None |
| 328 | |
| 329 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 330 | class CustomGroup(optparse.OptionGroup): |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 331 | """Custom option group which supports arguments passed-through to trybot.""" |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 332 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 333 | def add_remote_option(self, *args, **kwargs): |
| 334 | """For arguments that are passed-through to remote trybot.""" |
| 335 | return optparse.OptionGroup.add_option(self, *args, |
| 336 | remote_pass_through=True, |
| 337 | **kwargs) |
| 338 | |
| 339 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 340 | class CustomOption(commandline.FilteringOption): |
| 341 | """Subclass FilteringOption class to implement pass-through and api.""" |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 342 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 343 | ACTIONS = commandline.FilteringOption.ACTIONS + ('extend',) |
| 344 | STORE_ACTIONS = commandline.FilteringOption.STORE_ACTIONS + ('extend',) |
| 345 | TYPED_ACTIONS = commandline.FilteringOption.TYPED_ACTIONS + ('extend',) |
| 346 | ALWAYS_TYPED_ACTIONS = (commandline.FilteringOption.ALWAYS_TYPED_ACTIONS + |
| 347 | ('extend',)) |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 348 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 349 | def __init__(self, *args, **kwargs): |
| 350 | # The remote_pass_through argument specifies whether we should directly |
| 351 | # pass the argument (with its value) onto the remote trybot. |
| 352 | self.pass_through = kwargs.pop('remote_pass_through', False) |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 353 | self.api_version = int(kwargs.pop('api', '0')) |
| 354 | commandline.FilteringOption.__init__(self, *args, **kwargs) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 355 | |
| 356 | def take_action(self, action, dest, opt, value, values, parser): |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 357 | if action == 'extend': |
Mike Frysinger | d6925b5 | 2012-07-16 16:11:00 -0400 | [diff] [blame] | 358 | # If there is extra spaces between each argument, we get '' which later |
| 359 | # code barfs on, so skip those. e.g. We see this with the forms: |
| 360 | # cbuildbot -p 'proj:branch ' ... |
| 361 | # cbuildbot -p ' proj:branch' ... |
| 362 | # cbuildbot -p 'proj:branch proj2:branch' ... |
| 363 | lvalue = value.split() |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 364 | values.ensure_value(dest, []).extend(lvalue) |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 365 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 366 | commandline.FilteringOption.take_action( |
| 367 | self, action, dest, opt, value, values, parser) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 368 | |
| 369 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 370 | class CustomParser(commandline.FilteringParser): |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 371 | """Custom option parser which supports arguments passed-trhough to trybot""" |
Matt Tennant | e817904 | 2013-10-01 15:47:32 -0700 | [diff] [blame] | 372 | |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 373 | DEFAULT_OPTION_CLASS = CustomOption |
| 374 | |
| 375 | def add_remote_option(self, *args, **kwargs): |
| 376 | """For arguments that are passed-through to remote trybot.""" |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 377 | return self.add_option(*args, remote_pass_through=True, **kwargs) |
Brian Harring | b6cf914 | 2012-09-01 20:43:17 -0700 | [diff] [blame] | 378 | |
| 379 | |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 380 | def CreateParser(): |
| 381 | """Expose _CreateParser publicly.""" |
| 382 | # Name _CreateParser is needed for commandline library. |
| 383 | return _CreateParser() |
| 384 | |
| 385 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 386 | def _CreateParser(): |
Ryan Cui | 16d9e1f | 2012-05-11 10:50:18 -0700 | [diff] [blame] | 387 | """Generate and return the parser with all the options.""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 388 | # Parse options |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 389 | usage = 'usage: %prog [options] buildbot_config [buildbot_config ...]' |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 390 | parser = CustomParser(usage=usage, caching=FindCacheDir) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 391 | |
| 392 | # Main options |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 393 | parser.add_option('-l', '--list', action='store_true', dest='list', |
| 394 | default=False, |
| 395 | help='List the suggested trybot configs to use (see --all)') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 396 | parser.add_option('-a', '--all', action='store_true', dest='print_all', |
| 397 | default=False, |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 398 | help='List all of the buildbot configs available w/--list') |
| 399 | |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 400 | parser.add_option('--local', action='store_true', default=False, |
| 401 | help='Specifies that this tryjob should be run locally. ' |
| 402 | 'Implies --debug.') |
| 403 | parser.add_option('--remote', action='store_true', default=False, |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 404 | help='Specifies that this tryjob should be run remotely.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 405 | |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 406 | parser.add_remote_option('-b', '--branch', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 407 | help='The manifest branch to test. The branch to ' |
| 408 | 'check the buildroot out to.') |
| 409 | parser.add_option('-r', '--buildroot', type='path', dest='buildroot', |
| 410 | help='Root directory where source is checked out to, and ' |
| 411 | 'where the build occurs. For external build configs, ' |
| 412 | "defaults to 'trybot' directory at top level of your " |
| 413 | 'repo-managed checkout.') |
| 414 | parser.add_option('--bootstrap-dir', type='path', |
Prathmesh Prabhu | 867c117 | 2015-06-02 17:57:59 -0700 | [diff] [blame] | 415 | help='Bootstrapping cbuildbot may involve checking out ' |
| 416 | 'multiple copies of chromite. All these checkouts ' |
| 417 | 'will be contained in the directory specified here. ' |
| 418 | 'Default:%s' % osutils.GetGlobalTempDir()) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 419 | parser.add_remote_option('--android_rev', type='choice', |
David Riley | 486b261 | 2016-02-22 19:59:26 -0800 | [diff] [blame] | 420 | choices=constants.VALID_ANDROID_REVISIONS, |
| 421 | help=('Revision of Android to use, of type [%s]' |
| 422 | % '|'.join(constants.VALID_ANDROID_REVISIONS))) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 423 | parser.add_remote_option('--chrome_rev', type='choice', |
David Riley | 486b261 | 2016-02-22 19:59:26 -0800 | [diff] [blame] | 424 | choices=constants.VALID_CHROME_REVISIONS, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 425 | help=('Revision of Chrome to use, of type [%s]' |
| 426 | % '|'.join(constants.VALID_CHROME_REVISIONS))) |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 427 | parser.add_remote_option('--profile', |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 428 | help='Name of profile to sub-specify board variant.') |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 429 | parser.add_option('-c', '--config_repo', |
Don Garrett | 58e85e0 | 2017-06-21 15:24:29 -0700 | [diff] [blame] | 430 | help='Deprecated option. Do not use!') |
Hidehiko Abe | 95d7cf6 | 2017-03-07 23:34:30 +0900 | [diff] [blame] | 431 | # TODO(crbug.com/279618): Running GOMA is under development. Following |
| 432 | # flags are added for development purpose due to repository dependency, |
| 433 | # but not officially supported yet. |
| 434 | parser.add_option('--goma_dir', type='path', |
| 435 | api=constants.REEXEC_API_GOMA, |
| 436 | help='Specify a directory containing goma. When this is ' |
| 437 | 'set, GOMA is used to build Chrome.') |
| 438 | parser.add_option('--goma_client_json', type='path', |
| 439 | api=constants.REEXEC_API_GOMA, |
| 440 | help='Specify a service-account-goma-client.json path. ' |
| 441 | 'The file is needed on bots to run GOMA.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 442 | |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 443 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 444 | # Patch selection options. |
| 445 | # |
| 446 | |
| 447 | group = CustomGroup( |
| 448 | parser, |
| 449 | 'Patch Options') |
| 450 | |
| 451 | group.add_remote_option('-g', '--gerrit-patches', action='extend', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 452 | type='string', default=[], |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 453 | metavar="'Id1 *int_Id2...IdN'", |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 454 | help='Space-separated list of short-form Gerrit ' |
| 455 | "Change-Id's or change numbers to patch. " |
| 456 | "Please prepend '*' to internal Change-Id's") |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 457 | group.add_remote_option('-G', '--rietveld-patches', action='extend', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 458 | type='string', default=[], |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 459 | metavar="'id1[:subdir1]...idN[:subdirN]'", |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 460 | help='Space-separated list of short-form Rietveld ' |
| 461 | 'issue numbers to patch. If no subdir is ' |
| 462 | 'specified, the src directory is used.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 463 | group.add_option('-p', '--local-patches', action='extend', default=[], |
| 464 | metavar="'<project1>[:<branch1>]...<projectN>[:<branchN>]'", |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 465 | help='Space-separated list of project branches with ' |
| 466 | 'patches to apply. Projects are specified by name. ' |
| 467 | 'If no branch is specified the current branch of the ' |
| 468 | 'project will be used.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 469 | |
| 470 | parser.add_option_group(group) |
| 471 | |
| 472 | # |
| 473 | # Remote trybot options. |
| 474 | # |
| 475 | |
| 476 | group = CustomGroup( |
| 477 | parser, |
| 478 | 'Remote Trybot Options (--remote)') |
| 479 | |
Don Garrett | 6b0cf68 | 2017-03-29 18:21:04 -0700 | [diff] [blame] | 480 | # TODO(dgarrett): Remove after a reasonable delay. |
| 481 | group.add_option('--use-buildbucket', action='store_true', |
| 482 | dest='deprecated_use_buildbucket', |
| 483 | help='Deprecated option. Ignored.') |
| 484 | |
| 485 | group.add_option('--do-not-use-buildbucket', action='store_false', |
| 486 | dest='use_buildbucket', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 487 | help='Use buildbucket instead of git to request' |
| 488 | 'the tryjob(s).') |
Paul Hobbs | 5cd050d | 2015-06-30 16:52:28 -0700 | [diff] [blame] | 489 | |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 490 | group.add_remote_option('--hwtest', action='store_true', default=False, |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 491 | help='Run the HWTest stage (tests on real hardware)') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 492 | group.add_option('--remote-description', |
| 493 | help='Attach an optional description to a --remote run ' |
| 494 | 'to make it easier to identify the results when it ' |
| 495 | 'finishes') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 496 | group.add_option('--slaves', action='extend', default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 497 | help='Specify specific remote tryslaves to run on (e.g. ' |
| 498 | 'build149-m2); if the bot is busy, it will be queued') |
| 499 | group.add_remote_option('--channel', action='extend', dest='channels', |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 500 | default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 501 | help='Specify a channel for a payloads trybot. Can ' |
| 502 | 'be specified multiple times. No valid for ' |
| 503 | 'non-payloads configs.') |
| 504 | group.add_option('--test-tryjob', action='store_true', default=False, |
| 505 | help='Submit a tryjob to the test repository. Will not ' |
| 506 | 'show up on the production trybot waterfall.') |
Dominik Behr | adc592c | 2017-01-31 16:06:26 -0800 | [diff] [blame] | 507 | group.add_option('--committer-email', type='string', |
| 508 | help='Override default git committer email.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 509 | |
| 510 | parser.add_option_group(group) |
| 511 | |
| 512 | # |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 513 | # Branch creation options. |
| 514 | # |
| 515 | |
| 516 | group = CustomGroup( |
| 517 | parser, |
| 518 | 'Branch Creation Options (used with branch-util)') |
| 519 | |
| 520 | group.add_remote_option('--branch-name', |
| 521 | help='The branch to create or delete.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 522 | group.add_remote_option('--delete-branch', action='store_true', default=False, |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 523 | help='Delete the branch specified in --branch-name.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 524 | group.add_remote_option('--rename-to', |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 525 | help='Rename a branch to the specified name.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 526 | group.add_remote_option('--force-create', action='store_true', default=False, |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 527 | help='Overwrites an existing branch.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 528 | group.add_remote_option('--skip-remote-push', action='store_true', |
| 529 | default=False, |
Prathmesh Prabhu | e5f4d47 | 2015-05-07 16:52:10 -0700 | [diff] [blame] | 530 | help='Do not actually push to remote git repos. ' |
| 531 | 'Used for end-to-end testing branching.') |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 532 | |
| 533 | parser.add_option_group(group) |
| 534 | |
| 535 | # |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 536 | # Advanced options. |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 537 | # |
| 538 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 539 | group = CustomGroup( |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 540 | parser, |
| 541 | 'Advanced Options', |
| 542 | 'Caution: use these options at your own risk.') |
| 543 | |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 544 | group.add_remote_option('--bootstrap-args', action='append', default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 545 | help='Args passed directly to the bootstrap re-exec ' |
| 546 | 'to skip verification by the bootstrap code') |
| 547 | group.add_remote_option('--buildbot', action='store_true', dest='buildbot', |
Bernie Thompson | 63f3006 | 2016-12-21 15:24:25 -0800 | [diff] [blame] | 548 | default=False, |
| 549 | help='This is running on a buildbot. ' |
| 550 | 'This can be used to make a build operate ' |
| 551 | 'like an official builder, e.g. generate ' |
| 552 | 'new version numbers and archive official ' |
| 553 | 'artifacts and such. This should only be ' |
| 554 | 'used if you are confident in what you are ' |
| 555 | 'doing, as it will make automated commits.') |
Don Garrett | 07d4626 | 2017-04-13 12:06:44 -0700 | [diff] [blame] | 556 | parser.add_remote_option('--repo-cache', type='path', dest='_repo_cache', |
| 557 | help='Present for backwards compatibility, ignored.') |
Prathmesh Prabhu | 51d774f | 2015-07-17 15:11:49 -0700 | [diff] [blame] | 558 | group.add_remote_option('--no-buildbot-tags', action='store_false', |
| 559 | dest='enable_buildbot_tags', default=True, |
| 560 | help='Suppress buildbot specific tags from log ' |
| 561 | 'output. This is used to hide recursive ' |
| 562 | 'cbuilbot runs on the waterfall.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 563 | group.add_remote_option('--buildnumber', type='int', default=0, |
| 564 | help='build number') |
| 565 | group.add_option('--chrome_root', action='callback', type='path', |
| 566 | callback=_CheckChromeRootOption, |
| 567 | help='Local checkout of Chrome to use.') |
| 568 | group.add_remote_option('--chrome_version', action='callback', type='string', |
| 569 | dest='chrome_version', |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 570 | callback=_CheckChromeVersionOption, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 571 | help='Used with SPEC logic to force a particular ' |
| 572 | 'git revision of chrome rather than the ' |
| 573 | 'latest.') |
| 574 | group.add_remote_option('--clobber', action='store_true', default=False, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 575 | help='Clears an old checkout before syncing') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 576 | group.add_remote_option('--latest-toolchain', action='store_true', |
| 577 | default=False, |
| 578 | help='Use the latest toolchain.') |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 579 | parser.add_option('--log_dir', dest='log_dir', type='path', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 580 | help='Directory where logs are stored.') |
| 581 | group.add_remote_option('--maxarchives', type='int', |
| 582 | dest='max_archive_builds', default=3, |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 583 | help='Change the local saved build count limit.') |
Ryan Cui | bbd3d4b | 2012-08-17 12:20:37 -0700 | [diff] [blame] | 584 | parser.add_remote_option('--manifest-repo-url', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 585 | help='Overrides the default manifest repo url.') |
David James | 565bc9a | 2013-04-08 14:54:45 -0700 | [diff] [blame] | 586 | group.add_remote_option('--compilecheck', action='store_true', default=False, |
| 587 | help='Only verify compilation and unit tests.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 588 | group.add_remote_option('--noarchive', action='store_false', dest='archive', |
| 589 | default=True, help="Don't run archive stage.") |
Ryan Cui | f7f2469 | 2012-05-18 16:35:33 -0700 | [diff] [blame] | 590 | group.add_remote_option('--nobootstrap', action='store_false', |
| 591 | dest='bootstrap', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 592 | help="Don't checkout and run from a standalone " |
| 593 | 'chromite repo.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 594 | group.add_remote_option('--nobuild', action='store_false', dest='build', |
| 595 | default=True, |
| 596 | help="Don't actually build (for cbuildbot dev)") |
| 597 | group.add_remote_option('--noclean', action='store_false', dest='clean', |
| 598 | default=True, help="Don't clean the buildroot") |
Ryan Cui | f7f2469 | 2012-05-18 16:35:33 -0700 | [diff] [blame] | 599 | group.add_remote_option('--nocgroups', action='store_false', dest='cgroups', |
| 600 | default=True, |
| 601 | help='Disable cbuildbots usage of cgroups.') |
Ryan Cui | 3ea98e0 | 2013-08-07 16:01:48 -0700 | [diff] [blame] | 602 | group.add_remote_option('--nochromesdk', action='store_false', |
| 603 | dest='chrome_sdk', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 604 | help="Don't run the ChromeSDK stage which builds " |
| 605 | 'Chrome outside of the chroot.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 606 | group.add_remote_option('--noprebuilts', action='store_false', |
| 607 | dest='prebuilts', default=True, |
| 608 | help="Don't upload prebuilts.") |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 609 | group.add_remote_option('--nopatch', action='store_false', |
| 610 | dest='postsync_patch', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 611 | help="Don't run PatchChanges stage. This does not " |
| 612 | 'disable patching in of chromite patches ' |
| 613 | 'during BootstrapStage.') |
Don Garrett | 82c0ae8 | 2014-02-03 18:25:11 -0800 | [diff] [blame] | 614 | group.add_remote_option('--nopaygen', action='store_false', |
| 615 | dest='paygen', default=True, |
| 616 | help="Don't generate payloads.") |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 617 | group.add_remote_option('--noreexec', action='store_false', |
| 618 | dest='postsync_reexec', default=True, |
| 619 | help="Don't reexec into the buildroot after syncing.") |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 620 | group.add_remote_option('--nosdk', action='store_true', default=False, |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 621 | help='Re-create the SDK from scratch.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 622 | group.add_remote_option('--nosync', action='store_false', dest='sync', |
| 623 | default=True, help="Don't sync before building.") |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 624 | group.add_remote_option('--notests', action='store_false', dest='tests', |
| 625 | default=True, |
xixuan | 7774ba8 | 2017-06-22 16:04:00 -0700 | [diff] [blame] | 626 | help='Override values from buildconfig, run no ' |
| 627 | 'tests, and build no autotest and artifacts.') |
| 628 | group.add_remote_option('--novmtests', action='store_false', dest='vmtests', |
| 629 | default=True, |
| 630 | help='Override values from buildconfig, run no ' |
| 631 | 'vmtests.') |
Nam T. Nguyen | c93f134 | 2014-07-11 14:40:54 -0700 | [diff] [blame] | 632 | group.add_remote_option('--noimagetests', action='store_false', |
| 633 | dest='image_test', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 634 | help='Override values from buildconfig and run no ' |
| 635 | 'image tests.') |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 636 | group.add_remote_option('--nouprev', action='store_false', dest='uprev', |
| 637 | default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 638 | help='Override values from buildconfig and never ' |
| 639 | 'uprev.') |
| 640 | group.add_option('--reference-repo', |
| 641 | help='Reuse git data stored in an existing repo ' |
| 642 | 'checkout. This can drastically reduce the network ' |
| 643 | 'time spent setting up the trybot checkout. By ' |
| 644 | "default, if this option isn't given but cbuildbot " |
| 645 | 'is invoked from a repo checkout, cbuildbot will ' |
| 646 | 'use the repo root.') |
Ryan Cui | cedd8a5 | 2012-03-22 02:28:35 -0700 | [diff] [blame] | 647 | group.add_option('--resume', action='store_true', default=False, |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 648 | help='Skip stages already successfully completed.') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 649 | group.add_remote_option('--timeout', type='int', default=0, |
| 650 | help='Specify the maximum amount of time this job ' |
| 651 | 'can run for, at which point the build will be ' |
| 652 | 'aborted. If set to zero, then there is no ' |
| 653 | 'timeout.') |
| 654 | group.add_remote_option('--version', dest='force_version', |
| 655 | help='Used with manifest logic. Forces use of this ' |
| 656 | 'version rather than create or get latest. ' |
| 657 | 'Examples: 4815.0.0-rc1, 4815.1.2') |
| 658 | group.add_remote_option('--git-cache-dir', type='path', |
Don Garrett | bb79be9 | 2016-09-27 11:14:07 -0700 | [diff] [blame] | 659 | api=constants.REEXEC_API_GIT_CACHE_DIR, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 660 | help='Specify the cache directory to store the ' |
| 661 | 'project caches populated by the git-cache ' |
| 662 | 'tool. Bootstrap the projects based on the git ' |
| 663 | 'cache files instead of fetching them directly ' |
| 664 | 'from the GoB servers.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 665 | |
| 666 | parser.add_option_group(group) |
| 667 | |
| 668 | # |
| 669 | # Internal options. |
| 670 | # |
| 671 | |
| 672 | group = CustomGroup( |
| 673 | parser, |
Mike Frysinger | 34db869 | 2013-11-11 14:54:08 -0500 | [diff] [blame] | 674 | 'Internal Chromium OS Build Team Options', |
| 675 | 'Caution: these are for meant for the Chromium OS build team only') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 676 | |
| 677 | group.add_remote_option('--archive-base', type='gs_path', |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 678 | help='Base GS URL (gs://<bucket_name>/<path>) to ' |
| 679 | 'upload archive artifacts to') |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 680 | group.add_remote_option( |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 681 | '--cq-gerrit-query', dest='cq_gerrit_override', |
| 682 | help='If given, this gerrit query will be used to find what patches to ' |
| 683 | "test, rather than the normal 'CommitQueue>=1 AND Verified=1 AND " |
| 684 | "CodeReview=2' query it defaults to. Use with care- note " |
| 685 | 'additionally this setting only has an effect if the buildbot ' |
| 686 | "target is a cq target, and we're in buildbot mode.") |
| 687 | group.add_option('--pass-through', action='append', type='string', |
| 688 | dest='pass_through_args', default=[]) |
| 689 | group.add_option('--reexec-api-version', action='store_true', |
| 690 | dest='output_api_version', default=False, |
| 691 | help='Used for handling forwards/backwards compatibility ' |
| 692 | 'with --resume and --bootstrap') |
| 693 | group.add_option('--remote-trybot', action='store_true', default=False, |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 694 | help='Indicates this is running on a remote trybot machine') |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 695 | group.add_option('--buildbucket-id', |
| 696 | help='The unique ID in buildbucket of current build ' |
| 697 | 'generated by buildbucket.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 698 | group.add_remote_option('--remote-patches', action='extend', default=[], |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 699 | help='Patches uploaded by the trybot client when ' |
| 700 | 'run using the -p option') |
Brian Harring | f611e6e | 2012-07-17 18:47:44 -0700 | [diff] [blame] | 701 | # Note the default here needs to be hardcoded to 3; that is the last version |
| 702 | # that lacked this functionality. |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 703 | group.add_option('--remote-version', type='int', default=3, |
| 704 | help='Used for compatibility checks w/tryjobs running in ' |
| 705 | 'older chromite instances') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 706 | group.add_option('--sourceroot', type='path', default=constants.SOURCE_ROOT) |
Paul Hobbs | 3cbdf33 | 2017-07-05 22:55:32 -0700 | [diff] [blame] | 707 | group.add_option('--ts-mon-task-num', type='int', default=0, |
Don Garrett | 5cd946b | 2017-07-20 13:42:20 -0700 | [diff] [blame^] | 708 | api=constants.REEXEC_API_TSMON_TASK_NUM, |
Paul Hobbs | 3cbdf33 | 2017-07-05 22:55:32 -0700 | [diff] [blame] | 709 | help='The task number of this process. Defaults to 0. ' |
| 710 | 'This argument is useful for running multiple copies ' |
| 711 | 'of cbuildbot without their metrics colliding.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 712 | group.add_remote_option('--test-bootstrap', action='store_true', |
| 713 | default=False, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 714 | help='Causes cbuildbot to bootstrap itself twice, ' |
| 715 | 'in the sequence A->B->C: A(unpatched) patches ' |
| 716 | 'and bootstraps B; B patches and bootstraps C') |
| 717 | group.add_remote_option('--validation_pool', |
| 718 | help='Path to a pickled validation pool. Intended ' |
| 719 | 'for use only with the commit queue.') |
| 720 | group.add_remote_option('--metadata_dump', |
| 721 | help='Path to a json dumped metadata file. This ' |
| 722 | 'will be used as the initial metadata.') |
| 723 | group.add_remote_option('--master-build-id', type='int', |
Aviv Keshet | acf4cfb | 2014-07-30 12:31:22 -0700 | [diff] [blame] | 724 | api=constants.REEXEC_API_MASTER_BUILD_ID, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 725 | help='cidb build id of the master build to this ' |
| 726 | 'slave build.') |
| 727 | group.add_remote_option('--mock-tree-status', |
| 728 | help='Override the tree status value that would be ' |
| 729 | 'returned from the the actual tree. Example ' |
| 730 | 'values: open, closed, throttled. When used ' |
| 731 | 'in conjunction with --debug, the tree status ' |
| 732 | 'will not be ignored as it usually is in a ' |
| 733 | '--debug run.') |
| 734 | group.add_remote_option('--mock-slave-status', |
| 735 | metavar='MOCK_SLAVE_STATUS_PICKLE_FILE', |
| 736 | help='Override the result of the _FetchSlaveStatuses ' |
| 737 | 'method of MasterSlaveSyncCompletionStage, by ' |
| 738 | 'specifying a file with a pickle of the result ' |
| 739 | 'to be returned.') |
Mike Frysinger | 81af6ef | 2013-04-03 02:24:09 -0400 | [diff] [blame] | 740 | |
| 741 | parser.add_option_group(group) |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 742 | |
| 743 | # |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 744 | # Debug options |
Ryan Cui | f4f84be | 2012-07-09 18:50:41 -0700 | [diff] [blame] | 745 | # |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 746 | # Temporary hack; in place till --dry-run replaces --debug. |
| 747 | # pylint: disable=W0212 |
Brian Harring | 009db50 | 2012-10-10 02:21:37 -0700 | [diff] [blame] | 748 | group = parser.debug_group |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 749 | 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] | 750 | debug.help += ' Currently functions as --dry-run in addition.' |
Brian Harring | fec89fe | 2012-09-23 07:30:54 -0700 | [diff] [blame] | 751 | debug.pass_through = True |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 752 | group.add_option('--notee', action='store_false', dest='tee', default=True, |
Hidehiko Abe | 863d788 | 2017-03-09 22:27:28 +0900 | [diff] [blame] | 753 | help='Disable logging and internal tee process. Primarily ' |
| 754 | 'used for debugging cbuildbot itself.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 755 | return parser |
| 756 | |
| 757 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 758 | def _FinishParsing(options, args): |
| 759 | """Perform some parsing tasks that need to take place after optparse. |
| 760 | |
| 761 | This function needs to be easily testable! Keep it free of |
| 762 | environment-dependent code. Put more detailed usage validation in |
| 763 | _PostParseCheck(). |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 764 | |
| 765 | Args: |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 766 | options: The options object returned by optparse |
| 767 | args: The args object returned by optparse |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 768 | """ |
Ryan Cui | 41023d9 | 2012-11-13 19:59:50 -0800 | [diff] [blame] | 769 | # Populate options.pass_through_args. |
| 770 | accepted, _ = commandline.FilteringParser.FilterArgs( |
| 771 | options.parsed_args, lambda x: x.opt_inst.pass_through) |
| 772 | options.pass_through_args.extend(accepted) |
Brian Harring | 07039b5 | 2012-05-13 17:56:47 -0700 | [diff] [blame] | 773 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 774 | if options.chrome_root: |
| 775 | if options.chrome_rev != constants.CHROME_REV_LOCAL: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 776 | cros_build_lib.Die('Chrome rev must be %s if chrome_root is set.' % |
| 777 | constants.CHROME_REV_LOCAL) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 778 | elif options.chrome_rev == constants.CHROME_REV_LOCAL: |
| 779 | cros_build_lib.Die('Chrome root must be set if chrome_rev is %s.' % |
| 780 | constants.CHROME_REV_LOCAL) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 781 | |
| 782 | if options.chrome_version: |
| 783 | if options.chrome_rev != constants.CHROME_REV_SPEC: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 784 | cros_build_lib.Die('Chrome rev must be %s if chrome_version is set.' % |
| 785 | constants.CHROME_REV_SPEC) |
David James | a0a664e | 2013-02-13 09:52:01 -0800 | [diff] [blame] | 786 | elif options.chrome_rev == constants.CHROME_REV_SPEC: |
| 787 | cros_build_lib.Die( |
| 788 | 'Chrome rev must not be %s if chrome_version is not set.' |
| 789 | % constants.CHROME_REV_SPEC) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 790 | |
David James | 9e27e66 | 2013-02-14 13:42:43 -0800 | [diff] [blame] | 791 | patches = bool(options.gerrit_patches or options.local_patches or |
| 792 | options.rietveld_patches) |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 793 | if options.remote: |
| 794 | if options.local: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 795 | cros_build_lib.Die('Cannot specify both --remote and --local') |
Ryan Cui | 54da070 | 2012-04-19 18:38:08 -0700 | [diff] [blame] | 796 | |
Don Garrett | 5af1d26 | 2014-05-16 15:49:37 -0700 | [diff] [blame] | 797 | # options.channels is a convenient way to detect payloads builds. |
Prathmesh Prabhu | 0bc7f12 | 2015-07-25 17:09:26 -0700 | [diff] [blame] | 798 | if (not options.list and not options.buildbot and not options.channels and |
| 799 | not patches): |
Gaurav Shah | ed0399e | 2014-02-03 13:36:22 -0800 | [diff] [blame] | 800 | prompt = ('No patches were provided; are you sure you want to just ' |
| 801 | 'run a remote build of %s?' % ( |
| 802 | options.branch if options.branch else 'ToT')) |
| 803 | if not cros_build_lib.BooleanPrompt(prompt=prompt, default=False): |
Brian Harring | 7cc4b93 | 2012-11-01 16:58:55 -0700 | [diff] [blame] | 804 | cros_build_lib.Die('Must provide patches when running with --remote.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 805 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 806 | # --debug needs to be explicitly passed through for remote invocations. |
| 807 | release_mode_with_patches = (options.buildbot and patches and |
| 808 | '--debug' not in options.pass_through_args) |
| 809 | else: |
| 810 | if len(args) > 1: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 811 | cros_build_lib.Die('Multiple configs not supported if not running with ' |
Brian Harring | f1aad83 | 2012-07-18 10:46:39 -0700 | [diff] [blame] | 812 | '--remote. Got %r', args) |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 813 | |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 814 | if options.slaves: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 815 | cros_build_lib.Die('Cannot use --slaves if not running with --remote.') |
Ryan Cui | 79319ab | 2012-05-21 12:59:18 -0700 | [diff] [blame] | 816 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 817 | release_mode_with_patches = (options.buildbot and patches and |
| 818 | not options.debug) |
| 819 | |
David James | 5734ea3 | 2012-08-15 20:23:49 -0700 | [diff] [blame] | 820 | # When running in release mode, make sure we are running with checked-in code. |
| 821 | # We want checked-in cbuildbot/scripts to prevent errors, and we want to build |
| 822 | # a release image with checked-in code for CrOS packages. |
| 823 | if release_mode_with_patches: |
| 824 | cros_build_lib.Die( |
| 825 | 'Cannot provide patches when running with --buildbot!') |
| 826 | |
Ryan Cui | ba41ad3 | 2012-03-08 17:15:29 -0800 | [diff] [blame] | 827 | if options.buildbot and options.remote_trybot: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 828 | cros_build_lib.Die( |
| 829 | '--buildbot and --remote-trybot cannot be used together.') |
Ryan Cui | ba41ad3 | 2012-03-08 17:15:29 -0800 | [diff] [blame] | 830 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 831 | # Record whether --debug was set explicitly vs. it was inferred. |
| 832 | options.debug_forced = False |
| 833 | if options.debug: |
| 834 | options.debug_forced = True |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 835 | if not options.debug: |
Ryan Cui | 16ca581 | 2012-03-08 20:34:27 -0800 | [diff] [blame] | 836 | # We don't set debug by default for |
| 837 | # 1. --buildbot invocations. |
| 838 | # 2. --remote invocations, because it needs to push changes to the tryjob |
| 839 | # repo. |
| 840 | options.debug = not options.buildbot and not options.remote |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 841 | |
Ryan Cui | 1c13a25 | 2012-10-16 15:00:16 -0700 | [diff] [blame] | 842 | # Record the configs targeted. |
| 843 | options.build_targets = args[:] |
| 844 | |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 845 | if constants.BRANCH_UTIL_CONFIG in options.build_targets: |
Ryan Cui | 7bd8db6 | 2013-08-08 16:29:51 -0700 | [diff] [blame] | 846 | if options.remote: |
| 847 | cros_build_lib.Die( |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 848 | 'Running %s as a remote tryjob is not yet supported.', |
| 849 | constants.BRANCH_UTIL_CONFIG) |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 850 | if len(options.build_targets) > 1: |
| 851 | cros_build_lib.Die( |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 852 | 'Cannot run %s with any other configs.', |
| 853 | constants.BRANCH_UTIL_CONFIG) |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 854 | if not options.branch_name: |
| 855 | cros_build_lib.Die( |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 856 | 'Must specify --branch-name with the %s config.', |
| 857 | constants.BRANCH_UTIL_CONFIG) |
| 858 | if options.branch and options.branch != options.branch_name: |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 859 | cros_build_lib.Die( |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 860 | 'If --branch is specified with the %s config, it must' |
| 861 | ' have the same value as --branch-name.', |
| 862 | constants.BRANCH_UTIL_CONFIG) |
| 863 | |
| 864 | exclusive_opts = {'--version': options.force_version, |
| 865 | '--delete-branch': options.delete_branch, |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 866 | '--rename-to': options.rename_to} |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 867 | if 1 != sum(1 for x in exclusive_opts.values() if x): |
| 868 | cros_build_lib.Die('When using the %s config, you must' |
| 869 | ' specifiy one and only one of the following' |
| 870 | ' options: %s.', constants.BRANCH_UTIL_CONFIG, |
| 871 | ', '.join(exclusive_opts.keys())) |
| 872 | |
| 873 | # When deleting or renaming a branch, the --branch and --nobootstrap |
| 874 | # options are implied. |
| 875 | if options.delete_branch or options.rename_to: |
| 876 | if not options.branch: |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 877 | logging.info('Automatically enabling sync to branch %s for this %s ' |
| 878 | 'flow.', options.branch_name, |
| 879 | constants.BRANCH_UTIL_CONFIG) |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 880 | options.branch = options.branch_name |
| 881 | if options.bootstrap: |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 882 | logging.info('Automatically disabling bootstrap step for this %s flow.', |
| 883 | constants.BRANCH_UTIL_CONFIG) |
Matt Tennant | a130ea3 | 2013-12-19 09:38:39 -0800 | [diff] [blame] | 884 | options.bootstrap = False |
| 885 | |
Ryan Cui | 88b901c | 2013-06-21 11:35:30 -0700 | [diff] [blame] | 886 | elif any([options.delete_branch, options.rename_to, options.branch_name]): |
| 887 | cros_build_lib.Die( |
| 888 | 'Cannot specify --delete-branch, --rename-to or --branch-name when not ' |
| 889 | 'running the %s config', constants.BRANCH_UTIL_CONFIG) |
| 890 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 891 | |
Brian Harring | 1d7ba94 | 2012-04-24 06:37:18 -0700 | [diff] [blame] | 892 | # pylint: disable=W0613 |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 893 | def _PostParseCheck(parser, options, args, site_config): |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 894 | """Perform some usage validation after we've parsed the arguments |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 895 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 896 | Args: |
Aviv Keshet | 9e4236b | 2013-12-13 13:07:50 -0800 | [diff] [blame] | 897 | parser: Option parser that was used to parse arguments. |
| 898 | options: The options returned by optparse. |
| 899 | args: The args returned by optparse. |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 900 | site_config: config_lib.SiteConfig containing all config info. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 901 | """ |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 902 | if not args: |
| 903 | parser.error('Invalid usage: no configuration targets provided.' |
| 904 | 'Use -h to see usage. Use -l to list supported configs.') |
| 905 | |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 906 | if not options.branch: |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 907 | options.branch = git.GetChromiteTrackingBranch() |
Ryan Cui | e1e4e66 | 2012-05-21 16:39:46 -0700 | [diff] [blame] | 908 | |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 909 | if not repository.IsARepoRoot(options.sourceroot): |
| 910 | if options.local_patches: |
| 911 | raise Exception('Could not find repo checkout at %s!' |
| 912 | % options.sourceroot) |
| 913 | |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 914 | # Because the default cache dir depends on other options, FindCacheDir |
| 915 | # always returns None, and we setup the default here. |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 916 | if options.cache_dir is None: |
| 917 | # Note, options.sourceroot is set regardless of the path |
| 918 | # actually existing. |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 919 | if options.buildroot is not None: |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 920 | options.cache_dir = os.path.join(options.buildroot, '.cache') |
David James | ac8c2a7 | 2013-02-13 18:44:33 -0800 | [diff] [blame] | 921 | elif os.path.exists(options.sourceroot): |
| 922 | options.cache_dir = os.path.join(options.sourceroot, '.cache') |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 923 | else: |
| 924 | options.cache_dir = parser.FindCacheDir(parser, options) |
| 925 | options.cache_dir = os.path.abspath(options.cache_dir) |
Brian Harring | 8c1d7b1 | 2012-10-04 17:36:32 -0700 | [diff] [blame] | 926 | parser.ConfigureCacheDir(options.cache_dir) |
Brian Harring | ae0a532 | 2012-09-15 01:46:51 -0700 | [diff] [blame] | 927 | |
Yu-Ju Hong | 2c06676 | 2013-10-28 14:05:08 -0700 | [diff] [blame] | 928 | osutils.SafeMakedirsNonRoot(options.cache_dir) |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 929 | |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 930 | if options.local_patches: |
Brian Harring | 1d7ba94 | 2012-04-24 06:37:18 -0700 | [diff] [blame] | 931 | options.local_patches = _CheckLocalPatches( |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 932 | options.sourceroot, options.local_patches) |
Brian Harring | 1d7ba94 | 2012-04-24 06:37:18 -0700 | [diff] [blame] | 933 | |
| 934 | default = os.environ.get('CBUILDBOT_DEFAULT_MODE') |
| 935 | if (default and not any([options.local, options.buildbot, |
| 936 | options.remote, options.remote_trybot])): |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 937 | logging.info('CBUILDBOT_DEFAULT_MODE=%s env var detected, using it.' |
| 938 | % default) |
Brian Harring | 1d7ba94 | 2012-04-24 06:37:18 -0700 | [diff] [blame] | 939 | default = default.lower() |
| 940 | if default == 'local': |
| 941 | options.local = True |
| 942 | elif default == 'remote': |
| 943 | options.remote = True |
| 944 | elif default == 'buildbot': |
| 945 | options.buildbot = True |
| 946 | else: |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 947 | cros_build_lib.Die("CBUILDBOT_DEFAULT_MODE value %s isn't supported. " |
| 948 | % default) |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 949 | |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 950 | # Ensure that all args are legitimate config targets. |
Chris Sosa | 55cdc94 | 2014-04-16 13:08:37 -0700 | [diff] [blame] | 951 | invalid_targets = [] |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 952 | for arg in args: |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 953 | if arg not in site_config: |
Chris Sosa | 55cdc94 | 2014-04-16 13:08:37 -0700 | [diff] [blame] | 954 | invalid_targets.append(arg) |
Ralph Nathan | 5990042 | 2015-03-24 10:41:17 -0700 | [diff] [blame] | 955 | logging.error('No such configuraton target: "%s".', arg) |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 956 | continue |
| 957 | |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 958 | build_config = site_config[arg] |
| 959 | |
Don Garrett | 5af1d26 | 2014-05-16 15:49:37 -0700 | [diff] [blame] | 960 | is_payloads_build = build_config.build_type == constants.PAYLOADS_TYPE |
| 961 | |
| 962 | if options.channels and not is_payloads_build: |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 963 | cros_build_lib.Die('--channel must only be used with a payload config,' |
| 964 | ' not target (%s).' % arg) |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 965 | |
Don Garrett | 5af1d26 | 2014-05-16 15:49:37 -0700 | [diff] [blame] | 966 | if not options.channels and is_payloads_build: |
| 967 | cros_build_lib.Die('payload configs (%s) require --channel to do anything' |
| 968 | ' useful.' % arg) |
| 969 | |
Matt Tennant | 2c19203 | 2014-01-16 13:49:28 -0800 | [diff] [blame] | 970 | # The --version option is not compatible with an external target unless the |
| 971 | # --buildbot option is specified. More correctly, only "paladin versions" |
| 972 | # will work with external targets, and those are only used with --buildbot. |
| 973 | # If --buildbot is specified, then user should know what they are doing and |
| 974 | # only specify a version that will work. See crbug.com/311648. |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 975 | if (options.force_version and |
| 976 | not (options.buildbot or build_config.internal)): |
| 977 | cros_build_lib.Die('Cannot specify --version without --buildbot for an' |
| 978 | ' external target (%s).' % arg) |
Matt Tennant | 2c19203 | 2014-01-16 13:49:28 -0800 | [diff] [blame] | 979 | |
Chris Sosa | 55cdc94 | 2014-04-16 13:08:37 -0700 | [diff] [blame] | 980 | if invalid_targets: |
| 981 | cros_build_lib.Die('One or more invalid configuration targets specified. ' |
| 982 | 'You can check the available configs by running ' |
| 983 | '`cbuildbot --list --all`') |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 984 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 985 | |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 986 | def ParseCommandLine(parser, argv): |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 987 | """Completely parse the commandline arguments""" |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 988 | (options, args) = parser.parse_args(argv) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 989 | |
Matt Tennant | 763497d | 2014-01-17 16:45:54 -0800 | [diff] [blame] | 990 | # Strip out null arguments. |
| 991 | # TODO(rcui): Remove when buildbot is fixed |
| 992 | args = [arg for arg in args if arg] |
| 993 | |
Don Garrett | 6b0cf68 | 2017-03-29 18:21:04 -0700 | [diff] [blame] | 994 | if options.deprecated_use_buildbucket: |
| 995 | logging.warning('--use-buildbucket is deprecated, and ignored.') |
| 996 | |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 997 | if options.output_api_version: |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 998 | print(constants.REEXEC_API_VERSION) |
Brian Harring | 37e559b | 2012-05-22 20:47:32 -0700 | [diff] [blame] | 999 | sys.exit(0) |
| 1000 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1001 | _FinishParsing(options, args) |
| 1002 | return options, args |
| 1003 | |
| 1004 | |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1005 | _ENVIRONMENT_PROD = 'prod' |
| 1006 | _ENVIRONMENT_DEBUG = 'debug' |
| 1007 | _ENVIRONMENT_STANDALONE = 'standalone' |
| 1008 | |
| 1009 | |
| 1010 | def _GetRunEnvironment(options, build_config): |
| 1011 | """Determine whether this is a prod/debug/standalone run.""" |
| 1012 | # TODO(akeshet): This is a temporary workaround to make sure that the cidb |
| 1013 | # is not used on waterfalls that the db schema does not support (in particular |
| 1014 | # the chromeos.chrome waterfall). |
| 1015 | # See crbug.com/406940 |
| 1016 | waterfall = os.environ.get('BUILDBOT_MASTERNAME', '') |
| 1017 | if not waterfall in constants.CIDB_KNOWN_WATERFALLS: |
| 1018 | return _ENVIRONMENT_STANDALONE |
| 1019 | |
| 1020 | # TODO(akeshet): Clean up this code once we have better defined flags to |
| 1021 | # specify on-or-off waterfall and on-or-off production runs of cbuildbot. |
| 1022 | # See crbug.com/331417 |
| 1023 | |
| 1024 | # --buildbot runs should use the production services, unless the --debug flag |
| 1025 | # is also present. |
| 1026 | if options.buildbot: |
| 1027 | if options.debug: |
| 1028 | return _ENVIRONMENT_DEBUG |
| 1029 | else: |
| 1030 | return _ENVIRONMENT_PROD |
| 1031 | |
| 1032 | # --remote-trybot runs should use the debug services, with the exception of |
| 1033 | # pre-cq builds, which should use the production services. |
| 1034 | if options.remote_trybot: |
| 1035 | if build_config['pre_cq']: |
| 1036 | return _ENVIRONMENT_PROD |
| 1037 | else: |
| 1038 | return _ENVIRONMENT_DEBUG |
| 1039 | |
| 1040 | # If neither --buildbot nor --remote-trybot flag was used, don't use external |
| 1041 | # services. |
| 1042 | return _ENVIRONMENT_STANDALONE |
| 1043 | |
| 1044 | |
Gabe Black | de694a3 | 2015-02-19 15:11:11 -0800 | [diff] [blame] | 1045 | def _SetupConnections(options, build_config): |
Aviv Keshet | 5549124 | 2017-07-13 17:04:07 -0700 | [diff] [blame] | 1046 | """Set up CIDB connections using the appropriate Setup call. |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1047 | |
| 1048 | Args: |
| 1049 | options: Command line options structure. |
Aviv Keshet | 6413302 | 2014-08-25 15:50:52 -0700 | [diff] [blame] | 1050 | build_config: Config object for this build. |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1051 | """ |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1052 | # Outline: |
| 1053 | # 1) Based on options and build_config, decide whether we are a production |
| 1054 | # run, debug run, or standalone run. |
| 1055 | # 2) Set up cidb instance accordingly. |
| 1056 | # 3) Update topology info from cidb, so that any other service set up can use |
| 1057 | # topology. |
| 1058 | # 4) Set up any other services. |
| 1059 | run_type = _GetRunEnvironment(options, build_config) |
| 1060 | |
| 1061 | if run_type == _ENVIRONMENT_PROD: |
| 1062 | cidb.CIDBConnectionFactory.SetupProdCidb() |
Paul Hobbs | 3cbdf33 | 2017-07-05 22:55:32 -0700 | [diff] [blame] | 1063 | context = ts_mon_config.SetupTsMonGlobalState( |
| 1064 | 'cbuildbot', indirect=True, task_num=options.ts_mon_task_num) |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1065 | elif run_type == _ENVIRONMENT_DEBUG: |
| 1066 | cidb.CIDBConnectionFactory.SetupDebugCidb() |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1067 | context = ts_mon_config.TrivialContextManager() |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1068 | else: |
Aviv Keshet | 62d1a0e | 2014-08-22 21:16:13 -0700 | [diff] [blame] | 1069 | cidb.CIDBConnectionFactory.SetupNoCidb() |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1070 | context = ts_mon_config.TrivialContextManager() |
Aviv Keshet | 62d1a0e | 2014-08-22 21:16:13 -0700 | [diff] [blame] | 1071 | |
Aviv Keshet | 420de51 | 2015-05-18 14:28:48 -0700 | [diff] [blame] | 1072 | db = cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() |
| 1073 | topology.FetchTopologyFromCIDB(db) |
Aviv Keshet | 6413302 | 2014-08-25 15:50:52 -0700 | [diff] [blame] | 1074 | |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1075 | return context |
| 1076 | |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1077 | |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 1078 | # TODO(build): This function is too damn long. |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1079 | def main(argv): |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 1080 | # Turn on strict sudo checks. |
| 1081 | cros_build_lib.STRICT_SUDO = True |
| 1082 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1083 | # Set umask to 022 so files created by buildbot are readable. |
Mike Frysinger | 60ec101 | 2013-10-21 00:11:10 -0400 | [diff] [blame] | 1084 | os.umask(0o22) |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1085 | |
Ryan Cui | 8586797 | 2012-02-23 18:21:49 -0800 | [diff] [blame] | 1086 | parser = _CreateParser() |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 1087 | options, args = ParseCommandLine(parser, argv) |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 1088 | |
Don Garrett | de81cc7 | 2015-07-07 13:23:28 -0700 | [diff] [blame] | 1089 | if options.config_repo: |
Don Garrett | 58e85e0 | 2017-06-21 15:24:29 -0700 | [diff] [blame] | 1090 | cros_build_lib.Die('Deprecated usage. Ping crbug.com/735696 you need it.') |
Don Garrett | de81cc7 | 2015-07-07 13:23:28 -0700 | [diff] [blame] | 1091 | |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 1092 | # 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] | 1093 | site_config = config_lib.GetConfig() |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 1094 | |
Don Garrett | 0a873e0 | 2015-06-30 17:55:10 -0700 | [diff] [blame] | 1095 | if options.list: |
| 1096 | _PrintValidConfigs(site_config, options.print_all) |
| 1097 | sys.exit(0) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1098 | |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 1099 | _PostParseCheck(parser, options, args, site_config) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1100 | |
Mike Frysinger | 8fd67dc | 2012-12-03 23:51:18 -0500 | [diff] [blame] | 1101 | cros_build_lib.AssertOutsideChroot() |
Zdenek Behan | 98ec2fb | 2012-08-31 17:12:18 +0200 | [diff] [blame] | 1102 | |
Prathmesh Prabhu | 51d774f | 2015-07-17 15:11:49 -0700 | [diff] [blame] | 1103 | if options.enable_buildbot_tags: |
| 1104 | logging.EnableBuildbotMarkers() |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1105 | if options.remote: |
Ralph Nathan | 23a1221 | 2015-03-25 10:27:54 -0700 | [diff] [blame] | 1106 | logging.getLogger().setLevel(logging.WARNING) |
Ryan Cui | 16ca581 | 2012-03-08 20:34:27 -0800 | [diff] [blame] | 1107 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1108 | # Verify configs are valid. |
Dan Shi | 0bdb713 | 2013-07-30 16:22:12 -0700 | [diff] [blame] | 1109 | # If hwtest flag is enabled, post a warning that HWTest step may fail if the |
| 1110 | # specified board is not a released platform or it is a generic overlay. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1111 | for bot in args: |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 1112 | build_config = site_config[bot] |
Aviv Keshet | a96a2a9 | 2013-02-05 17:21:51 -0800 | [diff] [blame] | 1113 | if options.hwtest: |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 1114 | logging.warning( |
Dan Shi | 0bdb713 | 2013-07-30 16:22:12 -0700 | [diff] [blame] | 1115 | 'If %s is not a released platform or it is a generic overlay, ' |
| 1116 | 'the HWTest step will most likely not run; please ask the lab ' |
| 1117 | 'team for help if this is unexpected.' % build_config['boards']) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1118 | |
| 1119 | # Verify gerrit patches are valid. |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 1120 | print('Verifying patches...') |
Mike Frysinger | b80d019 | 2015-02-04 22:08:59 -0500 | [diff] [blame] | 1121 | patch_pool = trybot_patch_pool.TrybotPatchPool.FromOptions( |
| 1122 | gerrit_patches=options.gerrit_patches, |
| 1123 | local_patches=options.local_patches, |
| 1124 | sourceroot=options.sourceroot, |
| 1125 | remote_patches=options.remote_patches) |
Ryan Cui | 16d9e1f | 2012-05-11 10:50:18 -0700 | [diff] [blame] | 1126 | |
Ryan Cui | eaa9efd | 2012-04-25 17:56:45 -0700 | [diff] [blame] | 1127 | # --debug need to be explicitly passed through for remote invocations. |
| 1128 | if options.buildbot and '--debug' not in options.pass_through_args: |
| 1129 | _ConfirmRemoteBuildbotRun() |
| 1130 | |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 1131 | print('Submitting tryjob...') |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1132 | with _SetupConnections(options, build_config): |
Don Garrett | 887ca93 | 2017-06-22 15:32:31 -0700 | [diff] [blame] | 1133 | description = options.remote_description |
| 1134 | if description is None: |
| 1135 | description = remote_try.DefaultDescription( |
| 1136 | options.branch, |
| 1137 | options.gerrit_patches+options.local_patches) |
| 1138 | |
| 1139 | tryjob = remote_try.RemoteTryJob(args, patch_pool.local_patches, |
| 1140 | options.pass_through_args, |
| 1141 | options.cache_dir, |
| 1142 | description, |
| 1143 | options.committer_email, |
| 1144 | options.use_buildbucket, |
| 1145 | options.slaves) |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1146 | tryjob.Submit(testjob=options.test_tryjob, dryrun=False) |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 1147 | print('Tryjob submitted!') |
| 1148 | print(('Go to %s to view the status of your job.' |
| 1149 | % tryjob.GetTrybotWaterfallLink())) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1150 | sys.exit(0) |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 1151 | |
Ryan Cui | 54da070 | 2012-04-19 18:38:08 -0700 | [diff] [blame] | 1152 | elif (not options.buildbot and not options.remote_trybot |
| 1153 | and not options.resume and not options.local): |
Mike Frysinger | 5672a2a | 2014-05-31 22:29:57 -0400 | [diff] [blame] | 1154 | cros_build_lib.Die('Please use --remote or --local to run trybots') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1155 | |
Ningning Xia | c691e43 | 2016-08-11 14:52:59 -0700 | [diff] [blame] | 1156 | elif options.buildbot and not options.debug: |
| 1157 | if not cros_build_lib.HostIsCIBuilder(): |
| 1158 | # Cannot run --buildbot if both --debug and --remote aren't specified. |
| 1159 | cros_build_lib.Die('This host isn\'t a continuous-integration builder.') |
| 1160 | |
Matt Tennant | 759e235 | 2013-09-27 15:14:44 -0700 | [diff] [blame] | 1161 | # Only one config arg is allowed in this mode, which was confirmed earlier. |
Ryan Cui | 8be1606 | 2012-04-24 12:05:26 -0700 | [diff] [blame] | 1162 | bot_id = args[-1] |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 1163 | build_config = site_config[bot_id] |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1164 | |
Don Garrett | bbd7b55 | 2014-05-16 13:15:21 -0700 | [diff] [blame] | 1165 | # TODO: Re-enable this block when reference_repo support handles this |
| 1166 | # properly. (see chromium:330775) |
| 1167 | # if options.reference_repo is None: |
| 1168 | # repo_path = os.path.join(options.sourceroot, '.repo') |
| 1169 | # # If we're being run from a repo checkout, reuse the repo's git pool to |
| 1170 | # # cut down on sync time. |
| 1171 | # if os.path.exists(repo_path): |
| 1172 | # options.reference_repo = options.sourceroot |
| 1173 | |
| 1174 | if options.reference_repo: |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 1175 | if not os.path.exists(options.reference_repo): |
| 1176 | parser.error('Reference path %s does not exist' |
| 1177 | % (options.reference_repo,)) |
| 1178 | elif not os.path.exists(os.path.join(options.reference_repo, '.repo')): |
| 1179 | parser.error('Reference path %s does not look to be the base of a ' |
| 1180 | 'repo checkout; no .repo exists in the root.' |
| 1181 | % (options.reference_repo,)) |
| 1182 | |
Brian Harring | f11bf68 | 2012-05-14 15:53:43 -0700 | [diff] [blame] | 1183 | if (options.buildbot or options.remote_trybot) and not options.resume: |
Brian Harring | 470f611 | 2012-03-02 11:47:10 -0800 | [diff] [blame] | 1184 | if not options.cgroups: |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 1185 | parser.error('Options --buildbot/--remote-trybot and --nocgroups cannot ' |
| 1186 | 'be used together. Cgroup support is required for ' |
| 1187 | 'buildbot/remote-trybot mode.') |
Mike Frysinger | a78a56e | 2012-11-20 06:02:30 -0500 | [diff] [blame] | 1188 | if not cgroups.Cgroup.IsSupported(): |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 1189 | parser.error('Option --buildbot/--remote-trybot was given, but this ' |
| 1190 | 'system does not support cgroups. Failing.') |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1191 | |
David James | aad5cc7 | 2012-10-26 15:03:13 -0700 | [diff] [blame] | 1192 | missing = osutils.FindMissingBinaries(_BUILDBOT_REQUIRED_BINARIES) |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 1193 | if missing: |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 1194 | parser.error('Option --buildbot/--remote-trybot requires the following ' |
Ryan Cui | d4a2421 | 2012-04-04 18:08:12 -0700 | [diff] [blame] | 1195 | "binaries which couldn't be found in $PATH: %s" |
Brian Harring | 351ce44 | 2012-03-09 16:38:14 -0800 | [diff] [blame] | 1196 | % (', '.join(missing))) |
| 1197 | |
David James | dac7a91 | 2013-11-18 11:14:44 -0800 | [diff] [blame] | 1198 | if options.reference_repo: |
| 1199 | options.reference_repo = os.path.abspath(options.reference_repo) |
| 1200 | |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1201 | if not options.buildroot: |
| 1202 | if options.buildbot: |
Gaurav Shah | 59abcb5 | 2014-12-09 15:27:11 -0800 | [diff] [blame] | 1203 | parser.error('Please specify a buildroot with the --buildroot option.') |
Matt Tennant | d55b1f4 | 2012-04-13 14:15:01 -0700 | [diff] [blame] | 1204 | |
Ryan Cui | 5ba7e15 | 2012-05-10 14:36:52 -0700 | [diff] [blame] | 1205 | options.buildroot = _DetermineDefaultBuildRoot(options.sourceroot, |
| 1206 | build_config['internal']) |
Brian Harring | 470f611 | 2012-03-02 11:47:10 -0800 | [diff] [blame] | 1207 | # We use a marker file in the buildroot to indicate the user has |
| 1208 | # consented to using this directory. |
| 1209 | if not os.path.exists(repository.GetTrybotMarkerPath(options.buildroot)): |
| 1210 | _ConfirmBuildRoot(options.buildroot) |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1211 | |
| 1212 | # Sanity check of buildroot- specifically that it's not pointing into the |
| 1213 | # midst of an existing repo since git-repo doesn't support nesting. |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1214 | if (not repository.IsARepoRoot(options.buildroot) and |
David James | 13a69c9 | 2013-05-09 10:37:42 -0700 | [diff] [blame] | 1215 | git.FindRepoDir(options.buildroot)): |
Brian Harring | 3fec5a8 | 2012-03-01 05:57:03 -0800 | [diff] [blame] | 1216 | parser.error('Configured buildroot %s points into a repository checkout, ' |
| 1217 | 'rather than the root of it. This is not supported.' |
| 1218 | % options.buildroot) |
| 1219 | |
Chris Sosa | b5ea3b4 | 2012-10-25 15:25:20 -0700 | [diff] [blame] | 1220 | if not options.log_dir: |
| 1221 | options.log_dir = os.path.join(options.buildroot, _DEFAULT_LOG_DIR) |
| 1222 | |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1223 | log_file = None |
| 1224 | if options.tee: |
Chris Sosa | b5ea3b4 | 2012-10-25 15:25:20 -0700 | [diff] [blame] | 1225 | log_file = os.path.join(options.log_dir, _BUILDBOT_LOG_FILE) |
| 1226 | osutils.SafeMakedirs(options.log_dir) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1227 | _BackupPreviousLog(log_file) |
| 1228 | |
Brian Harring | 1b8c4c8 | 2012-05-29 23:03:04 -0700 | [diff] [blame] | 1229 | with cros_build_lib.ContextManagerStack() as stack: |
Ningning Xia | 96876d5 | 2016-03-31 10:26:39 -0700 | [diff] [blame] | 1230 | options.preserve_paths = set() |
David James | cebc727 | 2013-07-17 16:45:05 -0700 | [diff] [blame] | 1231 | if log_file is not None: |
| 1232 | # We don't want the critical section to try to clean up the tee process, |
| 1233 | # so we run Tee (forked off) outside of it. This prevents a deadlock |
| 1234 | # because the Tee process only exits when its pipe is closed, and the |
| 1235 | # critical section accidentally holds on to that file handle. |
| 1236 | stack.Add(tee.Tee, log_file) |
| 1237 | options.preserve_paths.add(_DEFAULT_LOG_DIR) |
| 1238 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1239 | critical_section = stack.Add(cleanup.EnforcedCleanupSection) |
| 1240 | stack.Add(sudo.SudoKeepAlive) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1241 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1242 | if not options.resume: |
Brian Harring | 2bf55e1 | 2012-05-13 21:31:55 -0700 | [diff] [blame] | 1243 | # If we're in resume mode, use our parents tempdir rather than |
| 1244 | # nesting another layer. |
David James | 4bc1370 | 2013-03-26 08:08:04 -0700 | [diff] [blame] | 1245 | stack.Add(osutils.TempDir, prefix='cbuildbot-tmp', set_global=True) |
David James | eecba23 | 2014-06-11 11:35:11 -0700 | [diff] [blame] | 1246 | logging.debug('Cbuildbot tempdir is %r.', os.environ.get('TMP')) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1247 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1248 | if options.cgroups: |
| 1249 | stack.Add(cgroups.SimpleContainChildren, 'cbuildbot') |
Brian Harring | a184efa | 2012-03-04 11:51:25 -0800 | [diff] [blame] | 1250 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1251 | # Mark everything between EnforcedCleanupSection and here as having to |
| 1252 | # be rolled back via the contextmanager cleanup handlers. This |
| 1253 | # ensures that sudo bits cannot outlive cbuildbot, that anything |
| 1254 | # cgroups would kill gets killed, etc. |
David James | fb3aac9 | 2013-10-16 13:26:52 -0700 | [diff] [blame] | 1255 | stack.Add(critical_section.ForkWatchdog) |
Brian Harring | d166aaf | 2012-05-14 18:31:53 -0700 | [diff] [blame] | 1256 | |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1257 | if not options.buildbot: |
Don Garrett | 6747eba | 2015-06-25 16:00:16 -0700 | [diff] [blame] | 1258 | build_config = config_lib.OverrideConfigForTrybot( |
Don Garrett | 4bb2168 | 2014-03-03 16:16:23 -0800 | [diff] [blame] | 1259 | build_config, options) |
Brian Harring | c2d09d9 | 2012-05-13 22:03:15 -0700 | [diff] [blame] | 1260 | |
Aviv Keshet | a0159be | 2013-12-12 13:56:28 -0800 | [diff] [blame] | 1261 | if options.mock_tree_status is not None: |
Prathmesh Prabhu | d51d750 | 2014-12-21 01:42:55 -0800 | [diff] [blame] | 1262 | stack.Add(mock.patch.object, tree_status, '_GetStatus', |
Aviv Keshet | a0159be | 2013-12-12 13:56:28 -0800 | [diff] [blame] | 1263 | return_value=options.mock_tree_status) |
| 1264 | |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 1265 | if options.mock_slave_status is not None: |
| 1266 | with open(options.mock_slave_status, 'r') as f: |
Aviv Keshet | 4e75002 | 2014-03-07 16:50:34 -0800 | [diff] [blame] | 1267 | mock_statuses = pickle.load(f) |
| 1268 | for key, value in mock_statuses.iteritems(): |
Ningning Xia | f342b95 | 2017-02-15 14:13:33 -0800 | [diff] [blame] | 1269 | mock_statuses[key] = builder_status_lib.BuilderStatus(**value) |
Yu-Ju Hong | d0fda38 | 2014-05-09 15:28:24 -0700 | [diff] [blame] | 1270 | stack.Add(mock.patch.object, |
| 1271 | completion_stages.MasterSlaveSyncCompletionStage, |
| 1272 | '_FetchSlaveStatuses', |
| 1273 | return_value=mock_statuses) |
Aviv Keshet | cf9c272 | 2014-02-25 15:15:10 -0800 | [diff] [blame] | 1274 | |
Paul Hobbs | d5a0f81 | 2016-07-26 16:10:31 -0700 | [diff] [blame] | 1275 | stack.Add(_SetupConnections, options, build_config) |
Don Garrett | b431836 | 2014-10-03 15:49:36 -0700 | [diff] [blame] | 1276 | retry_stats.SetupStats() |
Aviv Keshet | 2982af5 | 2014-08-13 16:07:57 -0700 | [diff] [blame] | 1277 | |
Aviv Keshet | 446f07f | 2016-03-08 11:32:31 -0800 | [diff] [blame] | 1278 | timeout_display_message = None |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 1279 | # For master-slave builds: Update slave's timeout using master's published |
| 1280 | # deadline. |
| 1281 | if options.buildbot and options.master_build_id is not None: |
| 1282 | slave_timeout = None |
| 1283 | if cidb.CIDBConnectionFactory.IsCIDBSetup(): |
| 1284 | cidb_handle = cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() |
| 1285 | if cidb_handle: |
| 1286 | slave_timeout = cidb_handle.GetTimeToDeadline(options.master_build_id) |
| 1287 | |
| 1288 | if slave_timeout is not None: |
Prathmesh Prabhu | e49f2aa | 2017-04-25 12:02:18 -0700 | [diff] [blame] | 1289 | # We artificially set a minimum slave_timeout because '0' is handled |
| 1290 | # specially, and because we don't want to timeout while trying to set |
| 1291 | # things up. |
| 1292 | slave_timeout = max(slave_timeout, 20) |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 1293 | if options.timeout == 0 or slave_timeout < options.timeout: |
| 1294 | logging.info('Updating slave build timeout to %d seconds enforced ' |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 1295 | 'by the master', slave_timeout) |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 1296 | options.timeout = slave_timeout |
Aviv Keshet | 8401758 | 2016-05-18 16:59:59 -0700 | [diff] [blame] | 1297 | timeout_display_message = ( |
| 1298 | 'This build has reached the timeout deadline set by the master. ' |
| 1299 | 'Either this stage or a previous one took too long (see stage ' |
| 1300 | 'timing historical summary in ReportStage) or the build failed ' |
| 1301 | 'to start on time.') |
Prathmesh Prabhu | 80e05df | 2014-12-11 15:20:33 -0800 | [diff] [blame] | 1302 | else: |
| 1303 | logging.warning('Could not get master deadline for master-slave build. ' |
| 1304 | 'Can not set slave timeout.') |
| 1305 | |
| 1306 | if options.timeout > 0: |
Aviv Keshet | 446f07f | 2016-03-08 11:32:31 -0800 | [diff] [blame] | 1307 | stack.Add(timeout_util.FatalTimeout, options.timeout, |
| 1308 | timeout_display_message) |
Ningning Xia | ad48354 | 2016-05-24 12:27:21 -0700 | [diff] [blame] | 1309 | try: |
| 1310 | _RunBuildStagesWrapper(options, site_config, build_config) |
| 1311 | except failures_lib.ExitEarlyException as ex: |
| 1312 | # This build finished successfully. Do not re-raise ExitEarlyException. |
| 1313 | logging.info('One stage exited early: %s', ex) |