blob: 94e94d5b69d2638b66794818e90279af592d02c1 [file] [log] [blame]
Chris Sosadad0d322011-01-31 16:37:33 -08001#!/usr/bin/python
Chris Sosa9ba47752012-02-27 15:27:37 -08002# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Sosadad0d322011-01-31 16:37:33 -08003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""This module uprevs Chrome for cbuildbot.
7
8After calling, it prints outs CHROME_VERSION_ATOM=(version atom string). A
9caller could then use this atom with emerge to build the newly uprevved version
10of Chrome e.g.
11
12./cros_mark_chrome_as_stable tot
13Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
14
15emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
16"""
17
Chris Sosa8be39132011-04-14 12:09:24 -070018import filecmp
Chris Sosadad0d322011-01-31 16:37:33 -080019import optparse
20import os
21import re
Chris Masone592cab52011-08-02 14:05:48 -070022import sys
petermayo@chromium.org163b3372011-09-12 02:06:05 -040023import time
Chris Sosadad0d322011-01-31 16:37:33 -080024
Mike Frysinger6cb624a2012-05-24 18:17:38 -040025from chromite.buildbot import constants
J. Richard Barnettef6697cf2011-11-18 12:42:08 -080026from chromite.buildbot import portage_utilities
David James1b363582012-12-17 11:53:11 -080027from chromite.lib import cros_build_lib
David Jamesef74b1c2012-11-12 07:47:47 -080028from chromite.lib import gclient
David James97d95872012-11-16 15:09:56 -080029from chromite.lib import git
Mike Frysinger6cb624a2012-05-24 18:17:38 -040030from chromite.scripts import cros_mark_as_stable
Chris Sosadad0d322011-01-31 16:37:33 -080031
Chris Sosadad0d322011-01-31 16:37:33 -080032# Helper regex's for finding ebuilds.
David James7c352bc2013-03-15 14:19:57 -070033_CHROME_VERSION_REGEX = r'\d+\.\d+\.\d+\.\d+'
34_NON_STICKY_REGEX = r'%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
Chris Sosadad0d322011-01-31 16:37:33 -080035
36# Dir where all the action happens.
David James629febb2012-11-25 13:07:34 -080037_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay/' +
38 constants.CHROME_CP)
Chris Sosadad0d322011-01-31 16:37:33 -080039
40_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
41 '%(chrome_version)s as stable.')
42
Chris Masone592cab52011-08-02 14:05:48 -070043# URLs that print lists of chrome revisions between two versions of the browser.
44_CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?'
45 'old_version=%(old)s&new_version=%(new)s')
Chris Sosadd611df2012-02-03 15:26:23 -080046
47# Only print links when we rev these types.
48_REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST,
49 constants.CHROME_REV_STICKY]
Chris Masone592cab52011-08-02 14:05:48 -070050
51_CHROME_SVN_TAG = 'CROS_SVN_COMMIT'
Chris Sosadad0d322011-01-31 16:37:33 -080052
ChromeOS Developer03118eb2013-02-12 14:27:09 -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
petermayo@chromium.org163b3372011-09-12 02:06:05 -040059def _GetVersionContents(chrome_version_info):
Peter Mayo177500f2011-09-09 17:25:23 -040060 """Returns the current Chromium version, from the contents of a VERSION file.
Chris Sosadad0d322011-01-31 16:37:33 -080061
Peter Mayo177500f2011-09-09 17:25:23 -040062 Args:
63 chrome_version_info: The contents of a chromium VERSION file.
64 """
Chris Sosadad0d322011-01-31 16:37:33 -080065 chrome_version_array = []
Chris Sosadad0d322011-01-31 16:37:33 -080066 for line in chrome_version_info.splitlines():
67 chrome_version_array.append(line.rpartition('=')[2])
68
69 return '.'.join(chrome_version_array)
70
petermayo@chromium.org163b3372011-09-12 02:06:05 -040071def _GetSpecificVersionUrl(base_url, revision, time_to_wait=600):
72 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040073
74 Args:
75 base_url: URL for the root of the chromium checkout.
petermayo@chromium.org163b3372011-09-12 02:06:05 -040076 revision: the SVN revision we want to use.
77 time_to_wait: the minimum period before abandoning our wait for the
78 desired revision to be present.
Peter Mayo177500f2011-09-09 17:25:23 -040079 """
petermayo@chromium.org163b3372011-09-12 02:06:05 -040080 svn_url = os.path.join(_GetSvnUrl(base_url), 'src', 'chrome', 'VERSION')
petermayo@chromium.org163b3372011-09-12 02:06:05 -040081 if not revision or not (int(revision) > 0):
82 raise Exception('Revision must be positive, got %s' % revision)
83
84 start = time.time()
85 # Use the fact we are SVN, hence ordered.
86 # Dodge the fact it will silently ignore the revision if it is not
87 # yet known. (i.e. too high)
ChromeOS Developer03118eb2013-02-12 14:27:09 -080088 repo_version = gclient.GetTipOfTrunkSvnRevision(base_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040089 while revision > repo_version:
90 if time.time() - start > time_to_wait:
91 raise Exception('Timeout Exceeeded')
92
David James1b363582012-12-17 11:53:11 -080093 msg = 'Repository only has version %s, looking for %s. Sleeping...'
94 cros_build_lib.Info(msg, repo_version, revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040095 time.sleep(30)
ChromeOS Developer03118eb2013-02-12 14:27:09 -080096 repo_version = gclient.GetTipOfTrunkSvnRevision(base_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040097
ChromeOS Developer03118eb2013-02-12 14:27:09 -080098 chrome_version_info = cros_build_lib.RunCommand(
petermayo@chromium.org163b3372011-09-12 02:06:05 -040099 ['svn', 'cat', '-r', revision, svn_url],
100 redirect_stdout=True,
101 error_message='Could not read version file at %s revision %s.' %
J. Richard Barnetted422f622011-11-17 09:39:46 -0800102 (svn_url, revision)).output
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400103
104 return _GetVersionContents(chrome_version_info)
105
Peter Mayo177500f2011-09-09 17:25:23 -0400106
107def _GetTipOfTrunkVersionFile(root):
108 """Returns the current Chromium version, from a file in a checkout.
109
110 Args:
111 root: path to the root of the chromium checkout.
112 """
113 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800114 chrome_version_info = cros_build_lib.RunCommand(
Peter Mayo177500f2011-09-09 17:25:23 -0400115 ['cat', version_file],
116 redirect_stdout=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800117 error_message='Could not read version file at %s.' % version_file).output
Peter Mayo177500f2011-09-09 17:25:23 -0400118
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400119 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400120
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800121
Peter Mayof65b8412011-08-26 01:22:21 -0400122def _GetLatestRelease(base_url, branch=None):
Chris Sosadad0d322011-01-31 16:37:33 -0800123 """Gets the latest release version from the buildspec_url for the branch.
124
125 Args:
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500126 branch: If set, gets the latest release for branch, otherwise latest
Chris Sosadad0d322011-01-31 16:37:33 -0800127 release.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500128
Chris Sosadad0d322011-01-31 16:37:33 -0800129 Returns:
130 Latest version string.
131 """
Peter Mayof65b8412011-08-26 01:22:21 -0400132 buildspec_url = os.path.join(base_url, 'releases')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800133 svn_ls = cros_build_lib.RunCommand(['svn', 'ls', buildspec_url],
134 redirect_stdout=True).output
135 sorted_ls = cros_build_lib.RunCommand(['sort', '--version-sort', '-r'],
136 input=svn_ls,
137 redirect_stdout=True).output
Chris Sosadad0d322011-01-31 16:37:33 -0800138 if branch:
David James7c352bc2013-03-15 14:19:57 -0700139 chrome_version_re = re.compile(r'^%s\.\d+.*' % branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800140 else:
David James7c352bc2013-03-15 14:19:57 -0700141 chrome_version_re = re.compile(r'^[0-9]+\..*')
Chris Sosadad0d322011-01-31 16:37:33 -0800142
Peter Mayoad8173d2011-11-08 16:18:23 -0500143 for chrome_version in sorted_ls.splitlines():
J. Richard Barnetted422f622011-11-17 09:39:46 -0800144 if chrome_version_re.match(chrome_version):
145 deps_url = os.path.join(buildspec_url, chrome_version, 'DEPS')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800146 deps_check = cros_build_lib.RunCommand(['svn', 'ls', deps_url],
147 error_code_ok=True,
148 redirect_stdout=True).output
J. Richard Barnetted422f622011-11-17 09:39:46 -0800149 if deps_check == 'DEPS\n':
150 return chrome_version.rstrip('/')
Peter Mayoad8173d2011-11-08 16:18:23 -0500151
152 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800153
154
155def _GetStickyEBuild(stable_ebuilds):
156 """Returns the sticky ebuild."""
157 sticky_ebuilds = []
158 non_sticky_re = re.compile(_NON_STICKY_REGEX)
159 for ebuild in stable_ebuilds:
160 if not non_sticky_re.match(ebuild.version):
161 sticky_ebuilds.append(ebuild)
162
163 if not sticky_ebuilds:
164 raise Exception('No sticky ebuilds found')
165 elif len(sticky_ebuilds) > 1:
David James1b363582012-12-17 11:53:11 -0800166 cros_build_lib.Warning('More than one sticky ebuild found')
Chris Sosadad0d322011-01-31 16:37:33 -0800167
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800168 return portage_utilities.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800169
170
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800171class ChromeEBuild(portage_utilities.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800172 """Thin sub-class of EBuild that adds a chrome_version field."""
David James7c352bc2013-03-15 14:19:57 -0700173 chrome_version_re = re.compile(r'.*%s-(%s|9999).*' % (
David James629febb2012-11-25 13:07:34 -0800174 constants.CHROME_PN, _CHROME_VERSION_REGEX))
Chris Sosadad0d322011-01-31 16:37:33 -0800175 chrome_version = ''
176
177 def __init__(self, path):
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800178 portage_utilities.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800179 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
180 if re_match:
181 self.chrome_version = re_match.group(1)
182
Chris Sosadad0d322011-01-31 16:37:33 -0800183 def __str__(self):
184 return self.ebuild_path
185
186
187def FindChromeCandidates(overlay_dir):
188 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
189
190 Args:
191 overlay_dir: The path to chrome's portage overlay dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500192
Chris Sosadad0d322011-01-31 16:37:33 -0800193 Returns:
194 Tuple [unstable_ebuild, stable_ebuilds].
Mike Frysinger1a736a82013-12-12 01:50:59 -0500195
Chris Sosadad0d322011-01-31 16:37:33 -0800196 Raises:
197 Exception: if no unstable ebuild exists for Chrome.
198 """
199 stable_ebuilds = []
200 unstable_ebuilds = []
201 for path in [
202 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
203 if path.endswith('.ebuild'):
204 ebuild = ChromeEBuild(path)
205 if not ebuild.chrome_version:
David James1b363582012-12-17 11:53:11 -0800206 cros_build_lib.Warning('Poorly formatted ebuild found at %s' % path)
Chris Sosadad0d322011-01-31 16:37:33 -0800207 else:
208 if '9999' in ebuild.version:
209 unstable_ebuilds.append(ebuild)
210 else:
211 stable_ebuilds.append(ebuild)
212
213 # Apply some sanity checks.
214 if not unstable_ebuilds:
215 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
216 if not stable_ebuilds:
David James1b363582012-12-17 11:53:11 -0800217 cros_build_lib.Warning('Missing stable ebuild for %s' % overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800218
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800219 return portage_utilities.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800220
221
222def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
223 """Finds the Chrome uprev candidate for the given chrome_rev.
224
225 Using the pre-flight logic, this means the stable ebuild you are uprevving
226 from. The difference here is that the version could be different and in
227 that case we want to find it to delete it.
228
229 Args:
230 stable_ebuilds: A list of stable ebuilds.
231 chrome_rev: The chrome_rev designating which candidate to find.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500232 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800233 components. For example: 9.0.553. Can be None but not if chrome_rev
234 is CHROME_REV_STICKY.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500235
Chris Sosadad0d322011-01-31 16:37:33 -0800236 Returns:
Mike Frysinger1a736a82013-12-12 01:50:59 -0500237 The EBuild, otherwise None if none found.
Chris Sosadad0d322011-01-31 16:37:33 -0800238 """
239 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400240 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
241 constants.CHROME_REV_SPEC]:
242 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400243 # not just for the fun of confusion.
David James7c352bc2013-03-15 14:19:57 -0700244 chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800245 for ebuild in stable_ebuilds:
246 if chrome_branch_re.search(ebuild.version):
247 candidates.append(ebuild)
248
Ryan Cuic6e097d2011-06-16 12:23:14 -0700249 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800250 assert sticky_branch is not None
David James7c352bc2013-03-15 14:19:57 -0700251 chrome_branch_re = re.compile(r'%s\..*' % sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800252 for ebuild in stable_ebuilds:
253 if chrome_branch_re.search(ebuild.version):
254 candidates.append(ebuild)
255
256 else:
David James7c352bc2013-03-15 14:19:57 -0700257 chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800258 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800259 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800260 candidates.append(ebuild)
261
262 if candidates:
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800263 return portage_utilities.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800264 else:
265 return None
266
Chris Masone592cab52011-08-02 14:05:48 -0700267def _AnnotateAndPrint(text, url):
268 """Add buildbot trappings to print <a href='url'>text</a> in the waterfall.
269
270 Args:
271 text: Anchor text for the link
272 url: the URL to which to link
273 """
Don Garrette60de902011-10-17 18:52:05 -0700274 print >> sys.stderr, '\n@@@STEP_LINK@%(text)s@%(url)s@@@' % { 'text': text,
Chris Masone592cab52011-08-02 14:05:48 -0700275 'url': url }
276
277def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
278 """Return appropriately formatted link to revision info, given versions
279
280 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
281 page that prints the Chromium revisions between those two versions.
282
283 Args:
284 old_chrome_version: version to diff from
285 chrome_version: version to which to diff
Mike Frysinger1a736a82013-12-12 01:50:59 -0500286
Chris Masone592cab52011-08-02 14:05:48 -0700287 Returns:
288 The desired URL.
289 """
290 return _CHROME_VERSION_URL % { 'old': old_chrome_version,
291 'new': chrome_version }
292
Chris Masone592cab52011-08-02 14:05:48 -0700293def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
294 """Returns a link to the list of revisions between two Chromium versions
295
296 Given two ChromeEBuilds and the kind of rev we're doing, generate a
297 link to a page that prints the Chromium changes between those two
298 revisions, inclusive.
299
300 Args:
301 old_chrome: ebuild for the version to diff from
302 new_chrome: ebuild for the version to which to diff
303 chrome_rev: one of constants.VALID_CHROME_REVISIONS
Mike Frysinger1a736a82013-12-12 01:50:59 -0500304
Chris Masone592cab52011-08-02 14:05:48 -0700305 Returns:
306 The desired URL.
307 """
Chris Sosadd611df2012-02-03 15:26:23 -0800308 assert chrome_rev in _REV_TYPES_FOR_LINKS
309 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
310 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800311
312def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800313 chrome_version, commit, overlay_dir):
David James7c352bc2013-03-15 14:19:57 -0700314 r"""Uprevs the chrome ebuild specified by chrome_rev.
Chris Sosadad0d322011-01-31 16:37:33 -0800315
316 This is the main function that uprevs the chrome_rev from a stable candidate
317 to its new version.
318
319 Args:
320 stable_candidate: ebuild that corresponds to the stable ebuild we are
321 revving from. If None, builds the a new ebuild given the version
322 and logic for chrome_rev type with revision set to 1.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500323 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
Peter Mayo177500f2011-09-09 17:25:23 -0400324 chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400325 constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for
326 the specified version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700327 constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for
328 the TOT version and uses the portage suffix of _alpha.
Peter Mayo177500f2011-09-09 17:25:23 -0400329 constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for
330 the local version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700331 constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they
332 are release candidates for the next sticky version.
333 constants.CHROME_REV_STICKY - Revs the sticky version.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500334 chrome_version: The \d.\d.\d.\d version of Chrome.
335 commit: Used with constants.CHROME_REV_TOT. The svn revision of chrome.
336 overlay_dir: Path to the chromeos-chrome package dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500337
Chris Sosadad0d322011-01-31 16:37:33 -0800338 Returns:
339 Full portage version atom (including rc's, etc) that was revved.
340 """
Chris Sosa8be39132011-04-14 12:09:24 -0700341 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
342 """Returns True if the new ebuild is redundant.
343
344 This is True if there if the current stable ebuild is the exact same copy
David James89608f92012-11-03 14:14:12 -0700345 of the new one.
Chris Sosa8be39132011-04-14 12:09:24 -0700346 """
347 if not stable_ebuild:
348 return False
349
350 if stable_candidate.chrome_version == new_ebuild.chrome_version:
David James89608f92012-11-03 14:14:12 -0700351 return filecmp.cmp(
352 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
Chris Sosa8be39132011-04-14 12:09:24 -0700353
David James629febb2012-11-25 13:07:34 -0800354 # Mark latest release and sticky branches as stable.
355 mark_stable = chrome_rev not in [constants.CHROME_REV_TOT,
356 constants.CHROME_REV_SPEC,
357 constants.CHROME_REV_LOCAL]
358
Chris Sosadad0d322011-01-31 16:37:33 -0800359 # Case where we have the last stable candidate with same version just rev.
360 if stable_candidate and stable_candidate.chrome_version == chrome_version:
361 new_ebuild_path = '%s-r%d.ebuild' % (
362 stable_candidate.ebuild_path_no_revision,
363 stable_candidate.current_revision + 1)
364 else:
David James629febb2012-11-25 13:07:34 -0800365 suffix = 'rc' if mark_stable else 'alpha'
366 pf = '%s-%s_%s-r1' % (constants.CHROME_PN, chrome_version, suffix)
367 new_ebuild_path = os.path.join(overlay_dir, '%s.ebuild' % pf)
Chris Sosadad0d322011-01-31 16:37:33 -0800368
David Jamesa6792552012-04-03 10:05:35 -0700369 chrome_variables = dict()
370 if commit:
371 chrome_variables[_CHROME_SVN_TAG] = commit
372
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800373 portage_utilities.EBuild.MarkAsStable(
David James065b2012012-04-01 14:51:11 -0700374 unstable_ebuild.ebuild_path, new_ebuild_path,
David Jamesa6792552012-04-03 10:05:35 -0700375 chrome_variables, make_stable=mark_stable)
Chris Sosadad0d322011-01-31 16:37:33 -0800376 new_ebuild = ChromeEBuild(new_ebuild_path)
Chris Sosa8be39132011-04-14 12:09:24 -0700377
378 # Determine whether this is ebuild is redundant.
379 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
David James1b363582012-12-17 11:53:11 -0800380 msg = 'Previous ebuild with same version found and ebuild is redundant.'
381 cros_build_lib.Info(msg)
Chris Sosa8be39132011-04-14 12:09:24 -0700382 os.unlink(new_ebuild_path)
383 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800384
Chris Sosadd611df2012-02-03 15:26:23 -0800385 if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS:
Chris Masone592cab52011-08-02 14:05:48 -0700386 _AnnotateAndPrint('Chromium revisions',
387 GetChromeRevisionListLink(stable_candidate,
388 new_ebuild,
389 chrome_rev))
390
David James67d73252013-09-19 17:33:12 -0700391 git.RunGit(overlay_dir, ['add', new_ebuild_path])
Chris Sosa9ba47752012-02-27 15:27:37 -0800392 if stable_candidate and not stable_candidate.IsSticky():
David James67d73252013-09-19 17:33:12 -0700393 git.RunGit(overlay_dir, ['rm', stable_candidate.ebuild_path])
Chris Sosadad0d322011-01-31 16:37:33 -0800394
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800395 portage_utilities.EBuild.CommitChange(
Chris Sosadad0d322011-01-31 16:37:33 -0800396 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400397 'chrome_version': chrome_version},
398 overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800399
Chris Sosadad0d322011-01-31 16:37:33 -0800400 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
401
402
Chris Sosad53f8fd2011-10-21 15:15:19 -0700403def ParseMaxRevision(revision_list):
404 """Returns the max revision from a list of url@revision string."""
David James7c352bc2013-03-15 14:19:57 -0700405 revision_re = re.compile(r'.*@(\d+)')
Chris Sosad53f8fd2011-10-21 15:15:19 -0700406
407 def RevisionKey(revision):
408 return revision_re.match(revision).group(1)
409
410 max_revision = max(revision_list.split(), key=RevisionKey)
411 return max_revision.rpartition('@')[2]
412
413
David James1b363582012-12-17 11:53:11 -0800414def main(_argv):
Chris Sosa0f295aa2011-10-21 14:10:28 -0700415 usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700416 usage = '%s OPTIONS [%s]' % (__file__, usage_options)
Chris Sosadad0d322011-01-31 16:37:33 -0800417 parser = optparse.OptionParser(usage)
David Jamescc09c9b2012-01-26 22:10:13 -0800418 parser.add_option('-b', '--boards', default='x86-generic')
David Jamesef74b1c2012-11-12 07:47:47 -0800419 parser.add_option('-c', '--chrome_url', default=gclient.GetBaseURLs()[0])
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400420 parser.add_option('-f', '--force_revision', default=None)
Chris Sosadad0d322011-01-31 16:37:33 -0800421 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
422 'trunk', 'src'),
423 help='Path to the src directory')
424 parser.add_option('-t', '--tracking_branch', default='cros/master',
425 help='Branch we are tracking changes against')
426 (options, args) = parser.parse_args()
427
Ryan Cuic6e097d2011-06-16 12:23:14 -0700428 if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
429 parser.error('Commit requires arg set to one of %s.'
430 % constants.VALID_CHROME_REVISIONS)
Chris Sosadad0d322011-01-31 16:37:33 -0800431
432 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
433 {'srcroot': options.srcroot})
434 chrome_rev = args[0]
435 version_to_uprev = None
436 commit_to_use = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800437 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800438
439 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800440
Peter Mayo177500f2011-09-09 17:25:23 -0400441 if chrome_rev == constants.CHROME_REV_LOCAL:
442 if 'CHROME_ROOT' in os.environ:
443 chrome_root = os.environ['CHROME_ROOT']
444 else:
445 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
446
447 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
448 commit_to_use = 'Unknown'
David James1b363582012-12-17 11:53:11 -0800449 cros_build_lib.Info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400450 elif chrome_rev == constants.CHROME_REV_SPEC:
451 commit_to_use = options.force_revision
Mike Frysingerf02736e2013-11-08 15:27:00 -0500452 if '@' in commit_to_use:
453 commit_to_use = ParseMaxRevision(commit_to_use)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400454 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
455 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400456 elif chrome_rev == constants.CHROME_REV_TOT:
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800457 commit_to_use = gclient.GetTipOfTrunkSvnRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400458 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
459 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700460 elif chrome_rev == constants.CHROME_REV_LATEST:
Peter Mayof65b8412011-08-26 01:22:21 -0400461 version_to_uprev = _GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800462 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800463 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
464 sticky_version = sticky_ebuild.chrome_version
465 sticky_branch = sticky_version.rpartition('.')[0]
Peter Mayof65b8412011-08-26 01:22:21 -0400466 version_to_uprev = _GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800467
468 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
469 sticky_branch)
470
471 if stable_candidate:
David James1b363582012-12-17 11:53:11 -0800472 cros_build_lib.Info('Stable candidate found %s' % stable_candidate)
Chris Sosadad0d322011-01-31 16:37:33 -0800473 else:
David James1b363582012-12-17 11:53:11 -0800474 cros_build_lib.Info('No stable candidate found.')
Chris Sosadad0d322011-01-31 16:37:33 -0800475
Chris Sosa8049f3b2011-05-02 20:09:28 -0700476 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David James97d95872012-11-16 15:09:56 -0800477 existing_branch = git.GetCurrentBranch(overlay_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700478 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400479 tracking_branch, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800480 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700481
482 # In the case of uprevving overlays that have patches applied to them,
483 # include the patched changes in the stabilizing branch.
484 if existing_branch:
David James67d73252013-09-19 17:33:12 -0700485 git.RunGit(overlay_dir, ['rebase', existing_branch])
David Jamesd6708c02012-03-22 10:49:15 -0700486
Chris Sosadad0d322011-01-31 16:37:33 -0800487 chrome_version_atom = MarkChromeEBuildAsStable(
488 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800489 commit_to_use, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800490 # Explicit print to communicate to caller.
491 if chrome_version_atom:
David Jamescc09c9b2012-01-26 22:10:13 -0800492 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
493 [chrome_version_atom])
Chris Sosadad0d322011-01-31 16:37:33 -0800494 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom