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