Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 1 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Bootstrap for cbuildbot. |
| 6 | |
| 7 | This script is intended to checkout chromite on the branch specified by -b or |
| 8 | --branch (as normally accepted by cbuildbot), and then invoke cbuildbot. Most |
| 9 | arguments are not parsed, only passed along. If a branch is not specified, this |
| 10 | script will use 'master'. |
| 11 | |
| 12 | Among other things, this allows us to invoke build configs that exist on a given |
| 13 | branch, but not on TOT. |
| 14 | """ |
| 15 | |
| 16 | from __future__ import print_function |
| 17 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 18 | import functools |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 19 | import os |
| 20 | |
| 21 | from chromite.cbuildbot import repository |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 22 | from chromite.cbuildbot.stages import sync_stages |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 23 | from chromite.lib import config_lib |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 24 | from chromite.lib import cros_build_lib |
| 25 | from chromite.lib import cros_logging as logging |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 26 | from chromite.lib import metrics |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 27 | from chromite.lib import osutils |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 28 | from chromite.lib import ts_mon_config |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 29 | from chromite.scripts import cbuildbot |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 30 | |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 31 | |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 32 | # This number should be incremented when we change the layout of the buildroot |
| 33 | # in a non-backwards compatible way. This wipes all buildroots. |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 34 | BUILDROOT_BUILDROOT_LAYOUT = 1 |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 35 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 36 | # Metrics reported to Monarch. |
| 37 | METRIC_INVOKED = 'chromeos/chromite/cbuildbot_launch/invoked' |
| 38 | METRIC_COMPLETED = 'chromeos/chromite/cbuildbot_launch/completed' |
| 39 | METRIC_PREP = 'chromeos/chromite/cbuildbot_launch/prep_completed' |
| 40 | METRIC_CLEAN = 'chromeos/chromite/cbuildbot_launch/clean_buildroot_durations' |
| 41 | METRIC_INITIAL = 'chromeos/chromite/cbuildbot_launch/initial_checkout_durations' |
| 42 | METRIC_CBUILDBOT = 'chromeos/chromite/cbuildbot_launch/cbuildbot_durations' |
| 43 | METRIC_CLOBBER = 'chromeos/chromite/cbuildbot_launch/clobber' |
| 44 | METRIC_BRANCH_CLEANUP = 'chromeos/chromite/cbuildbot_launch/branch_cleanup' |
| 45 | |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 46 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 47 | def StageDecorator(functor): |
| 48 | """A Decorator that adds buildbot stage tags around a method. |
| 49 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 50 | It uses the method name as the stage name, and assumes failure on a true |
| 51 | return value, or an exception. |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 52 | """ |
| 53 | @functools.wraps(functor) |
| 54 | def wrapped_functor(*args, **kwargs): |
| 55 | try: |
| 56 | logging.PrintBuildbotStepName(functor.__name__) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 57 | result = functor(*args, **kwargs) |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 58 | except Exception: |
| 59 | logging.PrintBuildbotStepFailure() |
| 60 | raise |
| 61 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 62 | if result: |
| 63 | logging.PrintBuildbotStepFailure() |
| 64 | return result |
| 65 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 66 | return wrapped_functor |
| 67 | |
| 68 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 69 | def field(fields, **kwargs): |
| 70 | """Helper for inserting more fields into a metrics fields dictionary. |
| 71 | |
| 72 | Args: |
| 73 | fields: Dictionary of metrics fields. |
| 74 | kwargs: Each argument is a key/value pair to insert into dict. |
| 75 | |
| 76 | Returns: |
| 77 | Copy of original dictionary with kwargs set as fields. |
| 78 | """ |
| 79 | f = fields.copy() |
| 80 | f.update(kwargs) |
| 81 | return f |
| 82 | |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 83 | def PreParseArguments(argv): |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 84 | """Extract the branch name from cbuildbot command line arguments. |
| 85 | |
| 86 | Ignores all arguments, other than the branch name. |
| 87 | |
| 88 | Args: |
| 89 | argv: The command line arguments to parse. |
| 90 | |
| 91 | Returns: |
| 92 | Branch as a string ('master' if nothing is specified). |
| 93 | """ |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 94 | parser = cbuildbot.CreateParser() |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 95 | options, args = cbuildbot.ParseCommandLine(parser, argv) |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 96 | |
| 97 | # This option isn't required for cbuildbot, but is for us. |
| 98 | if not options.buildroot: |
| 99 | cros_build_lib.Die('--buildroot is a required option.') |
| 100 | |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 101 | # Save off the build targets, in a mirror of cbuildbot code. |
| 102 | options.build_targets = args |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 103 | options.Freeze() |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 104 | |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 105 | return options |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 106 | |
| 107 | |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 108 | def GetBuildrootState(buildroot): |
| 109 | state_file = os.path.join(buildroot, '.cbuildbot_launch_state') |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 110 | |
| 111 | try: |
| 112 | state = osutils.ReadFile(state_file) |
| 113 | buildroot_layout, branchname = state.split() |
| 114 | buildroot_layout = int(buildroot_layout) |
| 115 | return buildroot_layout, branchname |
| 116 | except (IOError, ValueError): |
| 117 | # If we are unable to either read or parse the state file, we get here. |
| 118 | return 0, '' |
| 119 | |
| 120 | |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 121 | def SetBuildrootState(branchname, buildroot): |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 122 | assert branchname |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 123 | state_file = os.path.join(buildroot, '.cbuildbot_launch_state') |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 124 | new_state = '%d %s' % (BUILDROOT_BUILDROOT_LAYOUT, branchname) |
| 125 | osutils.WriteFile(state_file, new_state) |
| 126 | |
| 127 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 128 | @StageDecorator |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 129 | def CleanBuildroot(buildroot, repo, metrics_fields): |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 130 | """Some kinds of branch transitions break builds. |
| 131 | |
| 132 | This method tries to detect cases where that can happen, and clobber what's |
| 133 | needed to succeed. However, the clobbers are costly, and should be avoided |
| 134 | if necessary. |
| 135 | |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 136 | Args: |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 137 | buildroot: Directory with old buildroot to clean as needed. |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 138 | repo: repository.RepoRepository instance. |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 139 | metrics_fields: Dictionary of fields to include in metrics. |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 140 | """ |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 141 | old_buildroot_layout, old_branch = GetBuildrootState(buildroot) |
Don Garrett | e17e1d9 | 2017-04-12 15:28:19 -0700 | [diff] [blame] | 142 | |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 143 | if old_buildroot_layout != BUILDROOT_BUILDROOT_LAYOUT: |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 144 | logging.PrintBuildbotStepText('Unknown layout: Wiping buildroot.') |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 145 | metrics.Counter(METRIC_CLOBBER).increment( |
| 146 | field(metrics_fields, reason='layout_change')) |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 147 | osutils.RmDir(buildroot, ignore_missing=True, sudo=True) |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 148 | else: |
| 149 | if old_branch != repo.branch: |
| 150 | logging.PrintBuildbotStepText('Branch change: Cleaning buildroot.') |
| 151 | logging.info('Unmatched branch: %s -> %s', old_branch, repo.branch) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 152 | metrics.Counter(METRIC_BRANCH_CLEANUP).increment( |
| 153 | field(metrics_fields, old_branch=old_branch)) |
Don Garrett | 3996360 | 2017-02-27 14:41:58 -0800 | [diff] [blame] | 154 | |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 155 | logging.info('Remove Chroot.') |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 156 | osutils.RmDir(os.path.join(buildroot, 'chroot'), |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 157 | ignore_missing=True, sudo=True) |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 158 | |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 159 | logging.info('Remove Chrome checkout.') |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 160 | osutils.RmDir(os.path.join(buildroot, '.cache', 'distfiles'), |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 161 | ignore_missing=True, sudo=True) |
| 162 | |
| 163 | try: |
| 164 | # If there is any failure doing the cleanup, wipe everything. |
| 165 | repo.BuildRootGitCleanup(prune_all=True) |
| 166 | except Exception: |
| 167 | logging.info('Checkout cleanup failed, wiping buildroot:', exc_info=True) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 168 | metrics.Counter(METRIC_CLOBBER).increment( |
| 169 | field(metrics_fields, reason='repo_cleanup_failure')) |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 170 | repository.ClearBuildRoot(buildroot) |
Don Garrett | 3996360 | 2017-02-27 14:41:58 -0800 | [diff] [blame] | 171 | |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 172 | # Ensure buildroot exists. |
| 173 | osutils.SafeMakedirs(buildroot) |
| 174 | SetBuildrootState(repo.branch, buildroot) |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 175 | |
| 176 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 177 | @StageDecorator |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 178 | def InitialCheckout(repo): |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 179 | """Preliminary ChromeOS checkout. |
| 180 | |
| 181 | Perform a complete checkout of ChromeOS on the specified branch. This does NOT |
| 182 | match what the build needs, but ensures the buildroot both has a 'hot' |
| 183 | checkout, and is close enough that the branched cbuildbot can successfully get |
| 184 | the right checkout. |
| 185 | |
| 186 | This checks out full ChromeOS, even if a ChromiumOS build is going to be |
| 187 | performed. This is because we have no knowledge of the build config to be |
| 188 | used. |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 189 | |
| 190 | Args: |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 191 | repo: repository.RepoRepository instance. |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 192 | """ |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 193 | logging.PrintBuildbotStepText('Branch: %s' % repo.branch) |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 194 | logging.info('Bootstrap script starting initial sync on branch: %s', |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 195 | repo.branch) |
Don Garrett | 7649691 | 2017-05-11 16:59:11 -0700 | [diff] [blame] | 196 | repo.Sync(detach=True) |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 197 | |
| 198 | |
Don Garrett | 125d4dc | 2017-04-25 16:26:03 -0700 | [diff] [blame] | 199 | @StageDecorator |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 200 | def RunCbuildbot(options): |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 201 | """Start cbuildbot in specified directory with all arguments. |
| 202 | |
| 203 | Args: |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 204 | options: Parse command line options. |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 205 | |
| 206 | Returns: |
| 207 | Return code of cbuildbot as an integer. |
| 208 | """ |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 209 | logging.info('Bootstrap cbuildbot in: %s', options.buildroot) |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 210 | cbuildbot_path = os.path.join( |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 211 | options.buildroot, 'chromite', 'bin', 'cbuildbot') |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 212 | |
| 213 | cmd = sync_stages.BootstrapStage.FilterArgsForTargetCbuildbot( |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 214 | options.buildroot, cbuildbot_path, options) |
Don Garrett | 597ddff | 2017-02-17 18:29:37 -0800 | [diff] [blame] | 215 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 216 | result = cros_build_lib.RunCommand(cmd, error_code_ok=True, |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 217 | cwd=options.buildroot) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 218 | return result.returncode |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 219 | |
Don Garrett | 6096792 | 2017-04-12 18:51:44 -0700 | [diff] [blame] | 220 | |
Don Garrett | f15d65b | 2017-04-12 12:39:55 -0700 | [diff] [blame] | 221 | def ConfigureGlobalEnvironment(): |
| 222 | """Setup process wide environmental changes.""" |
Don Garrett | f15d65b | 2017-04-12 12:39:55 -0700 | [diff] [blame] | 223 | # Set umask to 022 so files created by buildbot are readable. |
| 224 | os.umask(0o22) |
| 225 | |
Don Garrett | 86fec48 | 2017-05-17 18:13:33 -0700 | [diff] [blame] | 226 | # These variables can interfere with LANG / locale behavior. |
| 227 | unwanted_local_vars = [ |
| 228 | 'LC_ALL', 'LC_CTYPE', 'LC_COLLATE', 'LC_TIME', 'LC_NUMERIC', |
| 229 | 'LC_MONETARY', 'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS', |
| 230 | 'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION', |
| 231 | ] |
| 232 | for v in unwanted_local_vars: |
| 233 | os.environ.pop(v, None) |
| 234 | |
| 235 | # This variable is required for repo sync's to work in all cases. |
| 236 | os.environ['LANG'] = 'en_US.UTF-8' |
| 237 | |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 238 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 239 | def _main(argv): |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 240 | """main method of script. |
| 241 | |
| 242 | Args: |
| 243 | argv: All command line arguments to pass as list of strings. |
| 244 | |
| 245 | Returns: |
| 246 | Return code of cbuildbot as an integer. |
| 247 | """ |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 248 | metrics_fields = {'branch_name': 'unknown'} |
Don Garrett | f15d65b | 2017-04-12 12:39:55 -0700 | [diff] [blame] | 249 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 250 | # Does the entire build pass or fail. |
| 251 | with metrics.SuccessCounter(METRIC_COMPLETED, metrics_fields) as c_fields: |
Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 252 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 253 | # Preliminary set, mostly command line parsing. |
| 254 | with metrics.SuccessCounter(METRIC_INVOKED, metrics_fields) as i_fields: |
| 255 | logging.EnableBuildbotMarkers() |
| 256 | ConfigureGlobalEnvironment() |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 257 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 258 | options = PreParseArguments(argv) |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 259 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 260 | branchname = options.branch or 'master' |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 261 | buildroot = options.buildroot |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 262 | git_cache_dir = options.git_cache_dir |
Don Garrett | f324bc3 | 2017-05-23 14:00:53 -0700 | [diff] [blame] | 263 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 264 | # Update metrics fields after parsing command line arguments. |
| 265 | metrics_fields['branch_name'] = branchname |
| 266 | i_fields.update(metrics_fields) |
| 267 | c_fields.update(metrics_fields) |
Don Garrett | 7ade05a | 2017-02-17 13:31:47 -0800 | [diff] [blame] | 268 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 269 | # Prepare the buildroot with source for the build. |
| 270 | with metrics.SuccessCounter(METRIC_PREP, metrics_fields): |
| 271 | site_config = config_lib.GetConfig() |
| 272 | manifest_url = site_config.params['MANIFEST_INT_URL'] |
| 273 | repo = repository.RepoRepository(manifest_url, buildroot, |
| 274 | branch=branchname, |
| 275 | git_cache_dir=git_cache_dir) |
Don Garrett | 86881cb | 2017-02-15 15:41:55 -0800 | [diff] [blame] | 276 | |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 277 | # Clean up the buildroot to a safe state. |
| 278 | with metrics.SecondsTimer(METRIC_CLEAN, fields=metrics_fields): |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 279 | CleanBuildroot(buildroot, repo, metrics_fields) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 280 | |
| 281 | # Get a checkout close enough the branched cbuildbot can handle it. |
| 282 | with metrics.SecondsTimer(METRIC_INITIAL, fields=metrics_fields): |
| 283 | InitialCheckout(repo) |
| 284 | |
| 285 | # Run cbuildbot inside the full ChromeOS checkout, on the specified branch. |
| 286 | with metrics.SecondsTimer(METRIC_CBUILDBOT, fields=metrics_fields): |
Ben Zhang | 30e5aac | 2017-05-31 15:02:12 +0000 | [diff] [blame^] | 287 | result = RunCbuildbot(options) |
Don Garrett | acbb239 | 2017-05-11 18:27:41 -0700 | [diff] [blame] | 288 | c_fields['success'] = (result == 0) |
| 289 | return result |
| 290 | |
| 291 | |
| 292 | def main(argv): |
| 293 | # Enable Monarch metrics gathering. |
| 294 | with ts_mon_config.SetupTsMonGlobalState('cbuildbot_launch', indirect=True): |
| 295 | return _main(argv) |