blob: 48b6a43479c24b41ea452abbed0f726a09b1aa27 [file] [log] [blame]
Chris Sosadad0d322011-01-31 16:37:33 -08001#!/usr/bin/python
2
Chris Sosa9ba47752012-02-27 15:27:37 -08003# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Sosadad0d322011-01-31 16:37:33 -08004# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""This module uprevs Chrome for cbuildbot.
8
9After calling, it prints outs CHROME_VERSION_ATOM=(version atom string). A
10caller could then use this atom with emerge to build the newly uprevved version
11of Chrome e.g.
12
13./cros_mark_chrome_as_stable tot
14Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
15
16emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
17"""
18
Chris Sosa8be39132011-04-14 12:09:24 -070019import filecmp
Chris Sosadad0d322011-01-31 16:37:33 -080020import optparse
21import os
22import re
Chris Masone592cab52011-08-02 14:05:48 -070023import sys
petermayo@chromium.org163b3372011-09-12 02:06:05 -040024import time
Chris Sosadad0d322011-01-31 16:37:33 -080025
Mike Frysinger6cb624a2012-05-24 18:17:38 -040026from chromite.buildbot import constants
J. Richard Barnettef6697cf2011-11-18 12:42:08 -080027from chromite.buildbot import portage_utilities
David Jamesef74b1c2012-11-12 07:47:47 -080028from chromite.lib import gclient
David James97d95872012-11-16 15:09:56 -080029from chromite.lib import git
J. Richard Barnetted422f622011-11-17 09:39:46 -080030from chromite.lib.cros_build_lib import RunCommand, Info, Warning
Mike Frysinger6cb624a2012-05-24 18:17:38 -040031from chromite.scripts import cros_mark_as_stable
Chris Sosadad0d322011-01-31 16:37:33 -080032
Chris Sosadad0d322011-01-31 16:37:33 -080033# Helper regex's for finding ebuilds.
34_CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+'
35_NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
36
37# Dir where all the action happens.
38_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay'
39 '/chromeos-base/chromeos-chrome')
40
41_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
42 '%(chrome_version)s as stable.')
43
Chris Masone592cab52011-08-02 14:05:48 -070044# URLs that print lists of chrome revisions between two versions of the browser.
45_CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?'
46 'old_version=%(old)s&new_version=%(new)s')
Chris Sosadd611df2012-02-03 15:26:23 -080047
48# Only print links when we rev these types.
49_REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST,
50 constants.CHROME_REV_STICKY]
Chris Masone592cab52011-08-02 14:05:48 -070051
52_CHROME_SVN_TAG = 'CROS_SVN_COMMIT'
Chris Sosadad0d322011-01-31 16:37:33 -080053
Peter Mayof65b8412011-08-26 01:22:21 -040054def _GetSvnUrl(base_url):
Chris Sosadad0d322011-01-31 16:37:33 -080055 """Returns the path to the svn url for the given chrome branch."""
Peter Mayof65b8412011-08-26 01:22:21 -040056 return os.path.join(base_url, 'trunk')
Chris Sosadad0d322011-01-31 16:37:33 -080057
58
Peter Mayof65b8412011-08-26 01:22:21 -040059def _GetTipOfTrunkSvnRevision(base_url):
Chris Sosadad0d322011-01-31 16:37:33 -080060 """Returns the current svn revision for the chrome tree."""
Peter Mayof65b8412011-08-26 01:22:21 -040061 svn_url = _GetSvnUrl(base_url)
J. Richard Barnetted422f622011-11-17 09:39:46 -080062 svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True).output
Chris Sosadad0d322011-01-31 16:37:33 -080063
64 revision_re = re.compile('^Revision:\s+(\d+).*')
65 for line in svn_info.splitlines():
66 match = revision_re.search(line)
67 if match:
68 svn_revision = match.group(1)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040069 Info('Found SVN Revision %s' % svn_revision)
Chris Sosadad0d322011-01-31 16:37:33 -080070 return svn_revision
71
72 raise Exception('Could not find revision information from %s' % svn_url)
73
74
petermayo@chromium.org163b3372011-09-12 02:06:05 -040075def _GetVersionContents(chrome_version_info):
Peter Mayo177500f2011-09-09 17:25:23 -040076 """Returns the current Chromium version, from the contents of a VERSION file.
Chris Sosadad0d322011-01-31 16:37:33 -080077
Peter Mayo177500f2011-09-09 17:25:23 -040078 Args:
79 chrome_version_info: The contents of a chromium VERSION file.
80 """
Chris Sosadad0d322011-01-31 16:37:33 -080081 chrome_version_array = []
Chris Sosadad0d322011-01-31 16:37:33 -080082 for line in chrome_version_info.splitlines():
83 chrome_version_array.append(line.rpartition('=')[2])
84
85 return '.'.join(chrome_version_array)
86
petermayo@chromium.org163b3372011-09-12 02:06:05 -040087def _GetSpecificVersionUrl(base_url, revision, time_to_wait=600):
88 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040089
90 Args:
91 base_url: URL for the root of the chromium checkout.
petermayo@chromium.org163b3372011-09-12 02:06:05 -040092 revision: the SVN revision we want to use.
93 time_to_wait: the minimum period before abandoning our wait for the
94 desired revision to be present.
Peter Mayo177500f2011-09-09 17:25:23 -040095 """
petermayo@chromium.org163b3372011-09-12 02:06:05 -040096 svn_url = os.path.join(_GetSvnUrl(base_url), 'src', 'chrome', 'VERSION')
petermayo@chromium.org163b3372011-09-12 02:06:05 -040097 if not revision or not (int(revision) > 0):
98 raise Exception('Revision must be positive, got %s' % revision)
99
100 start = time.time()
101 # Use the fact we are SVN, hence ordered.
102 # Dodge the fact it will silently ignore the revision if it is not
103 # yet known. (i.e. too high)
104 repo_version = _GetTipOfTrunkSvnRevision(base_url)
105 while revision > repo_version:
106 if time.time() - start > time_to_wait:
107 raise Exception('Timeout Exceeeded')
108
109 Info('Repository only has version %s, looking for %s. Sleeping...' %
110 (repo_version, revision))
111 time.sleep(30)
112 repo_version = _GetTipOfTrunkSvnRevision(base_url)
113
114 chrome_version_info = RunCommand(
115 ['svn', 'cat', '-r', revision, svn_url],
116 redirect_stdout=True,
117 error_message='Could not read version file at %s revision %s.' %
J. Richard Barnetted422f622011-11-17 09:39:46 -0800118 (svn_url, revision)).output
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400119
120 return _GetVersionContents(chrome_version_info)
121
Peter Mayo177500f2011-09-09 17:25:23 -0400122
123def _GetTipOfTrunkVersionFile(root):
124 """Returns the current Chromium version, from a file in a checkout.
125
126 Args:
127 root: path to the root of the chromium checkout.
128 """
129 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
130 chrome_version_info = RunCommand(
131 ['cat', version_file],
132 redirect_stdout=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800133 error_message='Could not read version file at %s.' % version_file).output
Peter Mayo177500f2011-09-09 17:25:23 -0400134
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400135 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400136
Peter Mayof65b8412011-08-26 01:22:21 -0400137def _GetLatestRelease(base_url, branch=None):
Chris Sosadad0d322011-01-31 16:37:33 -0800138 """Gets the latest release version from the buildspec_url for the branch.
139
140 Args:
141 branch: If set, gets the latest release for branch, otherwise latest
142 release.
143 Returns:
144 Latest version string.
145 """
Peter Mayof65b8412011-08-26 01:22:21 -0400146 buildspec_url = os.path.join(base_url, 'releases')
J. Richard Barnetted422f622011-11-17 09:39:46 -0800147 svn_ls = RunCommand(['svn', 'ls', buildspec_url],
148 redirect_stdout=True).output
Peter Mayoad8173d2011-11-08 16:18:23 -0500149 sorted_ls = RunCommand(['sort', '--version-sort', '-r'], input=svn_ls,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800150 redirect_stdout=True).output
Chris Sosadad0d322011-01-31 16:37:33 -0800151 if branch:
152 chrome_version_re = re.compile('^%s\.\d+.*' % branch)
153 else:
154 chrome_version_re = re.compile('^[0-9]+\..*')
Chris Sosadad0d322011-01-31 16:37:33 -0800155
Peter Mayoad8173d2011-11-08 16:18:23 -0500156 for chrome_version in sorted_ls.splitlines():
J. Richard Barnetted422f622011-11-17 09:39:46 -0800157 if chrome_version_re.match(chrome_version):
158 deps_url = os.path.join(buildspec_url, chrome_version, 'DEPS')
159 deps_check = RunCommand(['svn', 'ls', deps_url],
Brian Harringfa310772012-09-22 21:38:39 -0700160 error_code_ok=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800161 redirect_stdout=True).output
162 if deps_check == 'DEPS\n':
163 return chrome_version.rstrip('/')
Peter Mayoad8173d2011-11-08 16:18:23 -0500164
165 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800166
167
168def _GetStickyEBuild(stable_ebuilds):
169 """Returns the sticky ebuild."""
170 sticky_ebuilds = []
171 non_sticky_re = re.compile(_NON_STICKY_REGEX)
172 for ebuild in stable_ebuilds:
173 if not non_sticky_re.match(ebuild.version):
174 sticky_ebuilds.append(ebuild)
175
176 if not sticky_ebuilds:
177 raise Exception('No sticky ebuilds found')
178 elif len(sticky_ebuilds) > 1:
179 Warning('More than one sticky ebuild found')
180
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800181 return portage_utilities.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800182
183
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800184class ChromeEBuild(portage_utilities.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800185 """Thin sub-class of EBuild that adds a chrome_version field."""
186 chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % (
187 _CHROME_VERSION_REGEX))
188 chrome_version = ''
189
190 def __init__(self, path):
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800191 portage_utilities.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800192 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
193 if re_match:
194 self.chrome_version = re_match.group(1)
195
Chris Sosadad0d322011-01-31 16:37:33 -0800196 def __str__(self):
197 return self.ebuild_path
198
199
200def FindChromeCandidates(overlay_dir):
201 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
202
203 Args:
204 overlay_dir: The path to chrome's portage overlay dir.
205 Returns:
206 Tuple [unstable_ebuild, stable_ebuilds].
207 Raises:
208 Exception: if no unstable ebuild exists for Chrome.
209 """
210 stable_ebuilds = []
211 unstable_ebuilds = []
212 for path in [
213 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
214 if path.endswith('.ebuild'):
215 ebuild = ChromeEBuild(path)
216 if not ebuild.chrome_version:
217 Warning('Poorly formatted ebuild found at %s' % path)
218 else:
219 if '9999' in ebuild.version:
220 unstable_ebuilds.append(ebuild)
221 else:
222 stable_ebuilds.append(ebuild)
223
224 # Apply some sanity checks.
225 if not unstable_ebuilds:
226 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
227 if not stable_ebuilds:
228 Warning('Missing stable ebuild for %s' % overlay_dir)
229
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800230 return portage_utilities.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800231
232
233def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
234 """Finds the Chrome uprev candidate for the given chrome_rev.
235
236 Using the pre-flight logic, this means the stable ebuild you are uprevving
237 from. The difference here is that the version could be different and in
238 that case we want to find it to delete it.
239
240 Args:
241 stable_ebuilds: A list of stable ebuilds.
242 chrome_rev: The chrome_rev designating which candidate to find.
243 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800244 components. For example: 9.0.553. Can be None but not if chrome_rev
245 is CHROME_REV_STICKY.
Chris Sosadad0d322011-01-31 16:37:33 -0800246 Returns:
247 Returns the EBuild, otherwise None if none found.
248 """
249 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400250 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
251 constants.CHROME_REV_SPEC]:
252 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400253 # not just for the fun of confusion.
Chris Sosadad0d322011-01-31 16:37:33 -0800254 chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX)
255 for ebuild in stable_ebuilds:
256 if chrome_branch_re.search(ebuild.version):
257 candidates.append(ebuild)
258
Ryan Cuic6e097d2011-06-16 12:23:14 -0700259 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800260 assert sticky_branch is not None
Chris Sosadad0d322011-01-31 16:37:33 -0800261 chrome_branch_re = re.compile('%s\..*' % sticky_branch)
262 for ebuild in stable_ebuilds:
263 if chrome_branch_re.search(ebuild.version):
264 candidates.append(ebuild)
265
266 else:
267 chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX)
268 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800269 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800270 candidates.append(ebuild)
271
272 if candidates:
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800273 return portage_utilities.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800274 else:
275 return None
276
Chris Masone592cab52011-08-02 14:05:48 -0700277def _AnnotateAndPrint(text, url):
278 """Add buildbot trappings to print <a href='url'>text</a> in the waterfall.
279
280 Args:
281 text: Anchor text for the link
282 url: the URL to which to link
283 """
Don Garrette60de902011-10-17 18:52:05 -0700284 print >> sys.stderr, '\n@@@STEP_LINK@%(text)s@%(url)s@@@' % { 'text': text,
Chris Masone592cab52011-08-02 14:05:48 -0700285 'url': url }
286
287def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
288 """Return appropriately formatted link to revision info, given versions
289
290 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
291 page that prints the Chromium revisions between those two versions.
292
293 Args:
294 old_chrome_version: version to diff from
295 chrome_version: version to which to diff
296 Returns:
297 The desired URL.
298 """
299 return _CHROME_VERSION_URL % { 'old': old_chrome_version,
300 'new': chrome_version }
301
Chris Masone592cab52011-08-02 14:05:48 -0700302def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
303 """Returns a link to the list of revisions between two Chromium versions
304
305 Given two ChromeEBuilds and the kind of rev we're doing, generate a
306 link to a page that prints the Chromium changes between those two
307 revisions, inclusive.
308
309 Args:
310 old_chrome: ebuild for the version to diff from
311 new_chrome: ebuild for the version to which to diff
312 chrome_rev: one of constants.VALID_CHROME_REVISIONS
313 Returns:
314 The desired URL.
315 """
Chris Sosadd611df2012-02-03 15:26:23 -0800316 assert chrome_rev in _REV_TYPES_FOR_LINKS
317 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
318 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800319
320def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800321 chrome_version, commit, overlay_dir):
Chris Sosadad0d322011-01-31 16:37:33 -0800322 """Uprevs the chrome ebuild specified by chrome_rev.
323
324 This is the main function that uprevs the chrome_rev from a stable candidate
325 to its new version.
326
327 Args:
328 stable_candidate: ebuild that corresponds to the stable ebuild we are
329 revving from. If None, builds the a new ebuild given the version
330 and logic for chrome_rev type with revision set to 1.
331 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
Peter Mayo177500f2011-09-09 17:25:23 -0400332 chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400333 constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for
334 the specified version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700335 constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for
336 the TOT version and uses the portage suffix of _alpha.
Peter Mayo177500f2011-09-09 17:25:23 -0400337 constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for
338 the local version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700339 constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they
340 are release candidates for the next sticky version.
341 constants.CHROME_REV_STICKY - Revs the sticky version.
Chris Sosadad0d322011-01-31 16:37:33 -0800342 chrome_version: The \d.\d.\d.\d version of Chrome.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700343 commit: Used with constants.CHROME_REV_TOT. The svn revision of chrome.
Chris Sosadad0d322011-01-31 16:37:33 -0800344 overlay_dir: Path to the chromeos-chrome package dir.
Chris Sosadad0d322011-01-31 16:37:33 -0800345 Returns:
346 Full portage version atom (including rc's, etc) that was revved.
347 """
Chris Sosa8be39132011-04-14 12:09:24 -0700348 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
349 """Returns True if the new ebuild is redundant.
350
351 This is True if there if the current stable ebuild is the exact same copy
David James89608f92012-11-03 14:14:12 -0700352 of the new one.
Chris Sosa8be39132011-04-14 12:09:24 -0700353 """
354 if not stable_ebuild:
355 return False
356
357 if stable_candidate.chrome_version == new_ebuild.chrome_version:
David James89608f92012-11-03 14:14:12 -0700358 return filecmp.cmp(
359 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
Chris Sosa8be39132011-04-14 12:09:24 -0700360
Chris Sosadad0d322011-01-31 16:37:33 -0800361 base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version)
362 # Case where we have the last stable candidate with same version just rev.
363 if stable_candidate and stable_candidate.chrome_version == chrome_version:
364 new_ebuild_path = '%s-r%d.ebuild' % (
365 stable_candidate.ebuild_path_no_revision,
366 stable_candidate.current_revision + 1)
367 else:
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400368 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
369 constants.CHROME_REV_SPEC]:
Chris Sosadad0d322011-01-31 16:37:33 -0800370 portage_suffix = '_alpha'
371 else:
372 portage_suffix = '_rc'
373
374 new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix)
375
376 # Mark latest release and sticky branches as stable.
Peter Mayo177500f2011-09-09 17:25:23 -0400377 mark_stable = chrome_rev not in [constants.CHROME_REV_TOT,
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400378 constants.CHROME_REV_SPEC,
Peter Mayo177500f2011-09-09 17:25:23 -0400379 constants.CHROME_REV_LOCAL]
Chris Sosadad0d322011-01-31 16:37:33 -0800380
David Jamesa6792552012-04-03 10:05:35 -0700381 chrome_variables = dict()
382 if commit:
383 chrome_variables[_CHROME_SVN_TAG] = commit
384
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800385 portage_utilities.EBuild.MarkAsStable(
David James065b2012012-04-01 14:51:11 -0700386 unstable_ebuild.ebuild_path, new_ebuild_path,
David Jamesa6792552012-04-03 10:05:35 -0700387 chrome_variables, make_stable=mark_stable)
Chris Sosadad0d322011-01-31 16:37:33 -0800388 new_ebuild = ChromeEBuild(new_ebuild_path)
Chris Sosa8be39132011-04-14 12:09:24 -0700389
390 # Determine whether this is ebuild is redundant.
391 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
392 Info('Previous ebuild with same version found and ebuild is redundant.')
393 os.unlink(new_ebuild_path)
394 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800395
Chris Sosadd611df2012-02-03 15:26:23 -0800396 if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS:
Chris Masone592cab52011-08-02 14:05:48 -0700397 _AnnotateAndPrint('Chromium revisions',
398 GetChromeRevisionListLink(stable_candidate,
399 new_ebuild,
400 chrome_rev))
401
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400402 RunCommand(['git', 'add', new_ebuild_path], cwd=overlay_dir)
Chris Sosa9ba47752012-02-27 15:27:37 -0800403 if stable_candidate and not stable_candidate.IsSticky():
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400404 RunCommand(['git', 'rm', stable_candidate.ebuild_path], cwd=overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800405
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800406 portage_utilities.EBuild.CommitChange(
Chris Sosadad0d322011-01-31 16:37:33 -0800407 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400408 'chrome_version': chrome_version},
409 overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800410
Chris Sosadad0d322011-01-31 16:37:33 -0800411 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
412
413
Chris Sosad53f8fd2011-10-21 15:15:19 -0700414def ParseMaxRevision(revision_list):
415 """Returns the max revision from a list of url@revision string."""
416 revision_re = re.compile('.*@(\d+)')
417
418 def RevisionKey(revision):
419 return revision_re.match(revision).group(1)
420
421 max_revision = max(revision_list.split(), key=RevisionKey)
422 return max_revision.rpartition('@')[2]
423
424
Mike Frysinger368bbb72012-05-23 15:57:10 -0400425def main(argv):
Chris Sosa0f295aa2011-10-21 14:10:28 -0700426 usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700427 usage = '%s OPTIONS [%s]' % (__file__, usage_options)
Chris Sosadad0d322011-01-31 16:37:33 -0800428 parser = optparse.OptionParser(usage)
David Jamescc09c9b2012-01-26 22:10:13 -0800429 parser.add_option('-b', '--boards', default='x86-generic')
David Jamesef74b1c2012-11-12 07:47:47 -0800430 parser.add_option('-c', '--chrome_url', default=gclient.GetBaseURLs()[0])
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400431 parser.add_option('-f', '--force_revision', default=None)
Chris Sosadad0d322011-01-31 16:37:33 -0800432 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
433 'trunk', 'src'),
434 help='Path to the src directory')
435 parser.add_option('-t', '--tracking_branch', default='cros/master',
436 help='Branch we are tracking changes against')
437 (options, args) = parser.parse_args()
438
Ryan Cuic6e097d2011-06-16 12:23:14 -0700439 if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
440 parser.error('Commit requires arg set to one of %s.'
441 % constants.VALID_CHROME_REVISIONS)
Chris Sosadad0d322011-01-31 16:37:33 -0800442
443 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
444 {'srcroot': options.srcroot})
445 chrome_rev = args[0]
446 version_to_uprev = None
447 commit_to_use = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800448 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800449
450 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800451
Peter Mayo177500f2011-09-09 17:25:23 -0400452 if chrome_rev == constants.CHROME_REV_LOCAL:
453 if 'CHROME_ROOT' in os.environ:
454 chrome_root = os.environ['CHROME_ROOT']
455 else:
456 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
457
458 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
459 commit_to_use = 'Unknown'
460 Info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400461 elif chrome_rev == constants.CHROME_REV_SPEC:
462 commit_to_use = options.force_revision
Chris Sosad53f8fd2011-10-21 15:15:19 -0700463 if '@' in commit_to_use: commit_to_use = ParseMaxRevision(commit_to_use)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400464 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
465 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400466 elif chrome_rev == constants.CHROME_REV_TOT:
Peter Mayof65b8412011-08-26 01:22:21 -0400467 commit_to_use = _GetTipOfTrunkSvnRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400468 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
469 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700470 elif chrome_rev == constants.CHROME_REV_LATEST:
Peter Mayof65b8412011-08-26 01:22:21 -0400471 version_to_uprev = _GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800472 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800473 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
474 sticky_version = sticky_ebuild.chrome_version
475 sticky_branch = sticky_version.rpartition('.')[0]
Peter Mayof65b8412011-08-26 01:22:21 -0400476 version_to_uprev = _GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800477
478 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
479 sticky_branch)
480
481 if stable_candidate:
482 Info('Stable candidate found %s' % stable_candidate)
483 else:
484 Info('No stable candidate found.')
485
Chris Sosa8049f3b2011-05-02 20:09:28 -0700486 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David James97d95872012-11-16 15:09:56 -0800487 existing_branch = git.GetCurrentBranch(overlay_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700488 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400489 tracking_branch, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800490 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700491
492 # In the case of uprevving overlays that have patches applied to them,
493 # include the patched changes in the stabilizing branch.
494 if existing_branch:
495 RunCommand(['git', 'rebase', existing_branch], cwd=overlay_dir)
496
Chris Sosadad0d322011-01-31 16:37:33 -0800497 chrome_version_atom = MarkChromeEBuildAsStable(
498 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800499 commit_to_use, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800500 # Explicit print to communicate to caller.
501 if chrome_version_atom:
David Jamescc09c9b2012-01-26 22:10:13 -0800502 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
503 [chrome_version_atom])
Chris Sosadad0d322011-01-31 16:37:33 -0800504 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom