blob: 63a8d2d5020367fb2681b7d6d1c904e4fde85914 [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
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070018import base64
19import distutils.version
Chris Sosa8be39132011-04-14 12:09:24 -070020import filecmp
Chris Sosadad0d322011-01-31 16:37:33 -080021import optparse
22import os
23import re
Chris Masone592cab52011-08-02 14:05:48 -070024import sys
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070025import urlparse
Chris Sosadad0d322011-01-31 16:37:33 -080026
Don Garrett88b8d782014-05-13 17:30:55 -070027from chromite.cbuildbot import constants
28from chromite.cbuildbot import portage_utilities
David James1b363582012-12-17 11:53:11 -080029from chromite.lib import cros_build_lib
David James97d95872012-11-16 15:09:56 -080030from chromite.lib import git
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070031from chromite.lib import gob_util
32from chromite.lib import timeout_util
Mike Frysinger6cb624a2012-05-24 18:17:38 -040033from chromite.scripts import cros_mark_as_stable
Chris Sosadad0d322011-01-31 16:37:33 -080034
Chris Sosadad0d322011-01-31 16:37:33 -080035# Helper regex's for finding ebuilds.
David James7c352bc2013-03-15 14:19:57 -070036_CHROME_VERSION_REGEX = r'\d+\.\d+\.\d+\.\d+'
37_NON_STICKY_REGEX = r'%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
Chris Sosadad0d322011-01-31 16:37:33 -080038
39# Dir where all the action happens.
David James629febb2012-11-25 13:07:34 -080040_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay/' +
41 constants.CHROME_CP)
Chris Sosadad0d322011-01-31 16:37:33 -080042
43_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
44 '%(chrome_version)s as stable.')
45
Chris Masone592cab52011-08-02 14:05:48 -070046# URLs that print lists of chrome revisions between two versions of the browser.
47_CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?'
48 'old_version=%(old)s&new_version=%(new)s')
Chris Sosadd611df2012-02-03 15:26:23 -080049
50# Only print links when we rev these types.
51_REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST,
52 constants.CHROME_REV_STICKY]
Chris Masone592cab52011-08-02 14:05:48 -070053
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070054# TODO(szager): This is inaccurate, but is it safe to change? I have no idea.
Chris Masone592cab52011-08-02 14:05:48 -070055_CHROME_SVN_TAG = 'CROS_SVN_COMMIT'
Chris Sosadad0d322011-01-31 16:37:33 -080056
ChromeOS Developer03118eb2013-02-12 14:27:09 -080057
petermayo@chromium.org163b3372011-09-12 02:06:05 -040058def _GetVersionContents(chrome_version_info):
Peter Mayo177500f2011-09-09 17:25:23 -040059 """Returns the current Chromium version, from the contents of a VERSION file.
Chris Sosadad0d322011-01-31 16:37:33 -080060
Peter Mayo177500f2011-09-09 17:25:23 -040061 Args:
62 chrome_version_info: The contents of a chromium VERSION file.
63 """
Chris Sosadad0d322011-01-31 16:37:33 -080064 chrome_version_array = []
Chris Sosadad0d322011-01-31 16:37:33 -080065 for line in chrome_version_info.splitlines():
66 chrome_version_array.append(line.rpartition('=')[2])
67
68 return '.'.join(chrome_version_array)
69
Mike Frysingercc838832014-05-24 13:10:30 -040070
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070071def _GetSpecificVersionUrl(git_url, revision, time_to_wait=600):
petermayo@chromium.org163b3372011-09-12 02:06:05 -040072 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040073
74 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070075 git_url: Repository URL for chromium.
76 revision: the git revision we want to use.
petermayo@chromium.org163b3372011-09-12 02:06:05 -040077 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 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070080 parsed_url = urlparse.urlparse(git_url)
81 host = parsed_url[1]
82 path = parsed_url[2].rstrip('/') + (
83 '/+/%s/chrome/VERSION?format=text' % revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040084
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070085 # Allow for git repository replication lag with sleep/retry loop.
86 def _fetch():
87 fh = gob_util.FetchUrl(host, path, ignore_404=True)
88 return fh.read() if fh else None
petermayo@chromium.org163b3372011-09-12 02:06:05 -040089
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070090 def _wait_msg(_remaining_minutes):
91 cros_build_lib.Info(
92 'Repository does not yet have revision %s. Sleeping...',
93 revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040094
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070095 content = timeout_util.WaitForSuccess(
96 retry_check=lambda x: not bool(x),
97 func=_fetch,
98 timeout=time_to_wait,
99 period=30,
100 side_effect_func=_wait_msg)
101 return _GetVersionContents(base64.b64decode(content))
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400102
Peter Mayo177500f2011-09-09 17:25:23 -0400103
104def _GetTipOfTrunkVersionFile(root):
105 """Returns the current Chromium version, from a file in a checkout.
106
107 Args:
108 root: path to the root of the chromium checkout.
109 """
110 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800111 chrome_version_info = cros_build_lib.RunCommand(
Peter Mayo177500f2011-09-09 17:25:23 -0400112 ['cat', version_file],
113 redirect_stdout=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800114 error_message='Could not read version file at %s.' % version_file).output
Peter Mayo177500f2011-09-09 17:25:23 -0400115
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400116 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400117
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800118
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700119def CheckIfChromeRightForOS(deps_content):
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700120 """Checks if DEPS is right for Chrome OS.
121
122 This function checks for a variable called 'buildspec_platforms' to
123 find out if its 'chromeos' or 'all'. If any of those values,
124 then it chooses that DEPS.
125
126 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700127 deps_content: Content of release buildspec DEPS file.
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700128
129 Returns:
130 True if DEPS is the right Chrome for Chrome OS.
131 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700132 platforms_search = re.search(r'buildspec_platforms.*\s.*\s', deps_content)
Dharani Govindancbbf69c2014-07-29 15:37:39 -0700133
134 if platforms_search:
135 platforms = platforms_search.group()
136 if 'chromeos' in platforms or 'all' in platforms:
137 return True
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700138
139 return False
140
141
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700142def GetLatestRelease(git_url, branch=None):
143 """Gets the latest release version from the release tags in the repository.
Chris Sosadad0d322011-01-31 16:37:33 -0800144
145 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700146 git_url: URL of git repository.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500147 branch: If set, gets the latest release for branch, otherwise latest
Chris Sosadad0d322011-01-31 16:37:33 -0800148 release.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500149
Chris Sosadad0d322011-01-31 16:37:33 -0800150 Returns:
151 Latest version string.
152 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700153 # TODO(szager): This only works for public release buildspecs in the chromium
154 # src repository. Internal buildspecs are tracked differently. At the time
155 # of writing, I can't find any callers that use this method to scan for
156 # internal buildspecs. But there may be something lurking...
157
158 parsed_url = urlparse.urlparse(git_url)
159 path = parsed_url[2].rstrip('/') + '/+refs/tags?format=JSON'
160 j = gob_util.FetchUrlJson(parsed_url[1], path, ignore_404=False)
Chris Sosadad0d322011-01-31 16:37:33 -0800161 if branch:
David James7c352bc2013-03-15 14:19:57 -0700162 chrome_version_re = re.compile(r'^%s\.\d+.*' % branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800163 else:
David James7c352bc2013-03-15 14:19:57 -0700164 chrome_version_re = re.compile(r'^[0-9]+\..*')
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700165 matching_versions = [key for key in j.keys() if chrome_version_re.match(key)]
166 matching_versions.sort(key=distutils.version.LooseVersion)
167 for chrome_version in reversed(matching_versions):
168 path = parsed_url[2].rstrip() + (
169 '/+/refs/tags/%s/DEPS?format=text' % chrome_version)
170 fh = gob_util.FetchUrl(parsed_url[1], path, ignore_404=False)
171 content = fh.read() if fh else None
172 if content:
173 deps_content = base64.b64decode(content)
174 if CheckIfChromeRightForOS(deps_content):
175 return chrome_version
Peter Mayoad8173d2011-11-08 16:18:23 -0500176
177 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800178
179
180def _GetStickyEBuild(stable_ebuilds):
181 """Returns the sticky ebuild."""
182 sticky_ebuilds = []
183 non_sticky_re = re.compile(_NON_STICKY_REGEX)
184 for ebuild in stable_ebuilds:
185 if not non_sticky_re.match(ebuild.version):
186 sticky_ebuilds.append(ebuild)
187
188 if not sticky_ebuilds:
189 raise Exception('No sticky ebuilds found')
190 elif len(sticky_ebuilds) > 1:
David James1b363582012-12-17 11:53:11 -0800191 cros_build_lib.Warning('More than one sticky ebuild found')
Chris Sosadad0d322011-01-31 16:37:33 -0800192
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800193 return portage_utilities.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800194
195
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800196class ChromeEBuild(portage_utilities.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800197 """Thin sub-class of EBuild that adds a chrome_version field."""
David James7c352bc2013-03-15 14:19:57 -0700198 chrome_version_re = re.compile(r'.*%s-(%s|9999).*' % (
David James629febb2012-11-25 13:07:34 -0800199 constants.CHROME_PN, _CHROME_VERSION_REGEX))
Chris Sosadad0d322011-01-31 16:37:33 -0800200 chrome_version = ''
201
202 def __init__(self, path):
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800203 portage_utilities.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800204 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
205 if re_match:
206 self.chrome_version = re_match.group(1)
207
Chris Sosadad0d322011-01-31 16:37:33 -0800208 def __str__(self):
209 return self.ebuild_path
210
211
212def FindChromeCandidates(overlay_dir):
213 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
214
215 Args:
216 overlay_dir: The path to chrome's portage overlay dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500217
Chris Sosadad0d322011-01-31 16:37:33 -0800218 Returns:
219 Tuple [unstable_ebuild, stable_ebuilds].
Mike Frysinger1a736a82013-12-12 01:50:59 -0500220
Chris Sosadad0d322011-01-31 16:37:33 -0800221 Raises:
222 Exception: if no unstable ebuild exists for Chrome.
223 """
224 stable_ebuilds = []
225 unstable_ebuilds = []
226 for path in [
227 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
228 if path.endswith('.ebuild'):
229 ebuild = ChromeEBuild(path)
230 if not ebuild.chrome_version:
David James1b363582012-12-17 11:53:11 -0800231 cros_build_lib.Warning('Poorly formatted ebuild found at %s' % path)
Chris Sosadad0d322011-01-31 16:37:33 -0800232 else:
233 if '9999' in ebuild.version:
234 unstable_ebuilds.append(ebuild)
235 else:
236 stable_ebuilds.append(ebuild)
237
238 # Apply some sanity checks.
239 if not unstable_ebuilds:
240 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
241 if not stable_ebuilds:
David James1b363582012-12-17 11:53:11 -0800242 cros_build_lib.Warning('Missing stable ebuild for %s' % overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800243
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800244 return portage_utilities.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800245
246
247def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
248 """Finds the Chrome uprev candidate for the given chrome_rev.
249
250 Using the pre-flight logic, this means the stable ebuild you are uprevving
251 from. The difference here is that the version could be different and in
252 that case we want to find it to delete it.
253
254 Args:
255 stable_ebuilds: A list of stable ebuilds.
256 chrome_rev: The chrome_rev designating which candidate to find.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500257 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800258 components. For example: 9.0.553. Can be None but not if chrome_rev
259 is CHROME_REV_STICKY.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500260
Chris Sosadad0d322011-01-31 16:37:33 -0800261 Returns:
Mike Frysinger1a736a82013-12-12 01:50:59 -0500262 The EBuild, otherwise None if none found.
Chris Sosadad0d322011-01-31 16:37:33 -0800263 """
264 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400265 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
266 constants.CHROME_REV_SPEC]:
267 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400268 # not just for the fun of confusion.
David James7c352bc2013-03-15 14:19:57 -0700269 chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800270 for ebuild in stable_ebuilds:
271 if chrome_branch_re.search(ebuild.version):
272 candidates.append(ebuild)
273
Ryan Cuic6e097d2011-06-16 12:23:14 -0700274 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800275 assert sticky_branch is not None
David James7c352bc2013-03-15 14:19:57 -0700276 chrome_branch_re = re.compile(r'%s\..*' % sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800277 for ebuild in stable_ebuilds:
278 if chrome_branch_re.search(ebuild.version):
279 candidates.append(ebuild)
280
281 else:
David James7c352bc2013-03-15 14:19:57 -0700282 chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800283 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800284 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800285 candidates.append(ebuild)
286
287 if candidates:
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800288 return portage_utilities.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800289 else:
290 return None
291
Mike Frysingercc838832014-05-24 13:10:30 -0400292
Chris Masone592cab52011-08-02 14:05:48 -0700293def _AnnotateAndPrint(text, url):
294 """Add buildbot trappings to print <a href='url'>text</a> in the waterfall.
295
296 Args:
297 text: Anchor text for the link
298 url: the URL to which to link
299 """
Don Garrette60de902011-10-17 18:52:05 -0700300 print >> sys.stderr, '\n@@@STEP_LINK@%(text)s@%(url)s@@@' % { 'text': text,
Chris Masone592cab52011-08-02 14:05:48 -0700301 'url': url }
302
303def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
304 """Return appropriately formatted link to revision info, given versions
305
306 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
307 page that prints the Chromium revisions between those two versions.
308
309 Args:
310 old_chrome_version: version to diff from
311 chrome_version: version to which to diff
Mike Frysinger1a736a82013-12-12 01:50:59 -0500312
Chris Masone592cab52011-08-02 14:05:48 -0700313 Returns:
314 The desired URL.
315 """
316 return _CHROME_VERSION_URL % { 'old': old_chrome_version,
317 'new': chrome_version }
318
Chris Masone592cab52011-08-02 14:05:48 -0700319def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
320 """Returns a link to the list of revisions between two Chromium versions
321
322 Given two ChromeEBuilds and the kind of rev we're doing, generate a
323 link to a page that prints the Chromium changes between those two
324 revisions, inclusive.
325
326 Args:
327 old_chrome: ebuild for the version to diff from
328 new_chrome: ebuild for the version to which to diff
329 chrome_rev: one of constants.VALID_CHROME_REVISIONS
Mike Frysinger1a736a82013-12-12 01:50:59 -0500330
Chris Masone592cab52011-08-02 14:05:48 -0700331 Returns:
332 The desired URL.
333 """
Chris Sosadd611df2012-02-03 15:26:23 -0800334 assert chrome_rev in _REV_TYPES_FOR_LINKS
335 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
336 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800337
Mike Frysingercc838832014-05-24 13:10:30 -0400338
Chris Sosadad0d322011-01-31 16:37:33 -0800339def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800340 chrome_version, commit, overlay_dir):
David James7c352bc2013-03-15 14:19:57 -0700341 r"""Uprevs the chrome ebuild specified by chrome_rev.
Chris Sosadad0d322011-01-31 16:37:33 -0800342
343 This is the main function that uprevs the chrome_rev from a stable candidate
344 to its new version.
345
346 Args:
347 stable_candidate: ebuild that corresponds to the stable ebuild we are
348 revving from. If None, builds the a new ebuild given the version
349 and logic for chrome_rev type with revision set to 1.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500350 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
Peter Mayo177500f2011-09-09 17:25:23 -0400351 chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400352 constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for
353 the specified version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700354 constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for
355 the TOT version and uses the portage suffix of _alpha.
Peter Mayo177500f2011-09-09 17:25:23 -0400356 constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for
357 the local version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700358 constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they
359 are release candidates for the next sticky version.
360 constants.CHROME_REV_STICKY - Revs the sticky version.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500361 chrome_version: The \d.\d.\d.\d version of Chrome.
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700362 commit: Used with constants.CHROME_REV_TOT. The git revision of chrome.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500363 overlay_dir: Path to the chromeos-chrome package dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500364
Chris Sosadad0d322011-01-31 16:37:33 -0800365 Returns:
366 Full portage version atom (including rc's, etc) that was revved.
367 """
Chris Sosa8be39132011-04-14 12:09:24 -0700368 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
369 """Returns True if the new ebuild is redundant.
370
371 This is True if there if the current stable ebuild is the exact same copy
David James89608f92012-11-03 14:14:12 -0700372 of the new one.
Chris Sosa8be39132011-04-14 12:09:24 -0700373 """
374 if not stable_ebuild:
375 return False
376
377 if stable_candidate.chrome_version == new_ebuild.chrome_version:
David James89608f92012-11-03 14:14:12 -0700378 return filecmp.cmp(
379 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
Chris Sosa8be39132011-04-14 12:09:24 -0700380
David James629febb2012-11-25 13:07:34 -0800381 # Mark latest release and sticky branches as stable.
382 mark_stable = chrome_rev not in [constants.CHROME_REV_TOT,
383 constants.CHROME_REV_SPEC,
384 constants.CHROME_REV_LOCAL]
385
Chris Sosadad0d322011-01-31 16:37:33 -0800386 # Case where we have the last stable candidate with same version just rev.
387 if stable_candidate and stable_candidate.chrome_version == chrome_version:
388 new_ebuild_path = '%s-r%d.ebuild' % (
389 stable_candidate.ebuild_path_no_revision,
390 stable_candidate.current_revision + 1)
391 else:
David James629febb2012-11-25 13:07:34 -0800392 suffix = 'rc' if mark_stable else 'alpha'
393 pf = '%s-%s_%s-r1' % (constants.CHROME_PN, chrome_version, suffix)
394 new_ebuild_path = os.path.join(overlay_dir, '%s.ebuild' % pf)
Chris Sosadad0d322011-01-31 16:37:33 -0800395
David Jamesa6792552012-04-03 10:05:35 -0700396 chrome_variables = dict()
397 if commit:
398 chrome_variables[_CHROME_SVN_TAG] = commit
399
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800400 portage_utilities.EBuild.MarkAsStable(
David James065b2012012-04-01 14:51:11 -0700401 unstable_ebuild.ebuild_path, new_ebuild_path,
David Jamesa6792552012-04-03 10:05:35 -0700402 chrome_variables, make_stable=mark_stable)
Chris Sosadad0d322011-01-31 16:37:33 -0800403 new_ebuild = ChromeEBuild(new_ebuild_path)
Chris Sosa8be39132011-04-14 12:09:24 -0700404
405 # Determine whether this is ebuild is redundant.
406 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
David James1b363582012-12-17 11:53:11 -0800407 msg = 'Previous ebuild with same version found and ebuild is redundant.'
408 cros_build_lib.Info(msg)
Chris Sosa8be39132011-04-14 12:09:24 -0700409 os.unlink(new_ebuild_path)
410 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800411
Chris Sosadd611df2012-02-03 15:26:23 -0800412 if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS:
Chris Masone592cab52011-08-02 14:05:48 -0700413 _AnnotateAndPrint('Chromium revisions',
414 GetChromeRevisionListLink(stable_candidate,
415 new_ebuild,
416 chrome_rev))
417
David James67d73252013-09-19 17:33:12 -0700418 git.RunGit(overlay_dir, ['add', new_ebuild_path])
Chris Sosa9ba47752012-02-27 15:27:37 -0800419 if stable_candidate and not stable_candidate.IsSticky():
David James67d73252013-09-19 17:33:12 -0700420 git.RunGit(overlay_dir, ['rm', stable_candidate.ebuild_path])
Chris Sosadad0d322011-01-31 16:37:33 -0800421
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800422 portage_utilities.EBuild.CommitChange(
Chris Sosadad0d322011-01-31 16:37:33 -0800423 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400424 'chrome_version': chrome_version},
425 overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800426
Chris Sosadad0d322011-01-31 16:37:33 -0800427 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
428
429
David James1b363582012-12-17 11:53:11 -0800430def main(_argv):
Chris Sosa0f295aa2011-10-21 14:10:28 -0700431 usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700432 usage = '%s OPTIONS [%s]' % (__file__, usage_options)
Chris Sosadad0d322011-01-31 16:37:33 -0800433 parser = optparse.OptionParser(usage)
Yu-Ju Hong575b3662014-08-05 13:33:41 -0700434 parser.add_option('-b', '--boards', default=None)
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700435 parser.add_option('-c', '--chrome_url',
436 default=constants.CHROMIUM_GOB_URL)
David Jamesfb160012014-07-01 10:00:57 -0700437 parser.add_option('-f', '--force_version', default=None,
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700438 help='Chrome version or git revision hash to use')
Chris Sosadad0d322011-01-31 16:37:33 -0800439 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
440 'trunk', 'src'),
441 help='Path to the src directory')
442 parser.add_option('-t', '--tracking_branch', default='cros/master',
443 help='Branch we are tracking changes against')
444 (options, args) = parser.parse_args()
445
Ryan Cuic6e097d2011-06-16 12:23:14 -0700446 if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
447 parser.error('Commit requires arg set to one of %s.'
448 % constants.VALID_CHROME_REVISIONS)
Chris Sosadad0d322011-01-31 16:37:33 -0800449
David James9a5980e2014-07-16 09:37:00 -0700450 if options.force_version and args[0] not in (constants.CHROME_REV_SPEC,
451 constants.CHROME_REV_LATEST):
David Jamesfb160012014-07-01 10:00:57 -0700452 parser.error('--force_version is not compatible with the %r '
453 'option.' % (args[0],))
454
Chris Sosadad0d322011-01-31 16:37:33 -0800455 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
456 {'srcroot': options.srcroot})
457 chrome_rev = args[0]
458 version_to_uprev = None
459 commit_to_use = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800460 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800461
462 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800463
Peter Mayo177500f2011-09-09 17:25:23 -0400464 if chrome_rev == constants.CHROME_REV_LOCAL:
465 if 'CHROME_ROOT' in os.environ:
466 chrome_root = os.environ['CHROME_ROOT']
467 else:
468 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
469
470 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
471 commit_to_use = 'Unknown'
David James1b363582012-12-17 11:53:11 -0800472 cros_build_lib.Info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400473 elif chrome_rev == constants.CHROME_REV_SPEC:
David Jamesfb160012014-07-01 10:00:57 -0700474 if '.' in options.force_version:
475 version_to_uprev = options.force_version
476 else:
477 commit_to_use = options.force_version
478 if '@' in commit_to_use:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700479 commit_to_use = commit_to_use.rpartition('@')[2]
David Jamesfb160012014-07-01 10:00:57 -0700480 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
481 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400482 elif chrome_rev == constants.CHROME_REV_TOT:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700483 commit_to_use = gob_util.GetTipOfTrunkRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400484 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
485 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700486 elif chrome_rev == constants.CHROME_REV_LATEST:
David James9a5980e2014-07-16 09:37:00 -0700487 if options.force_version:
488 if '.' not in options.force_version:
489 parser.error('%s only accepts released Chrome versions, not SVN or '
490 'Git revisions.' % (chrome_rev,))
491 version_to_uprev = options.force_version
492 else:
493 version_to_uprev = GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800494 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800495 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
496 sticky_version = sticky_ebuild.chrome_version
497 sticky_branch = sticky_version.rpartition('.')[0]
Yu-Ju Hong39806322014-06-24 16:46:32 -0700498 version_to_uprev = GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800499
500 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
501 sticky_branch)
502
503 if stable_candidate:
David James1b363582012-12-17 11:53:11 -0800504 cros_build_lib.Info('Stable candidate found %s' % stable_candidate)
Chris Sosadad0d322011-01-31 16:37:33 -0800505 else:
David James1b363582012-12-17 11:53:11 -0800506 cros_build_lib.Info('No stable candidate found.')
Chris Sosadad0d322011-01-31 16:37:33 -0800507
Chris Sosa8049f3b2011-05-02 20:09:28 -0700508 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David James97d95872012-11-16 15:09:56 -0800509 existing_branch = git.GetCurrentBranch(overlay_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700510 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400511 tracking_branch, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800512 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700513
514 # In the case of uprevving overlays that have patches applied to them,
515 # include the patched changes in the stabilizing branch.
516 if existing_branch:
David James67d73252013-09-19 17:33:12 -0700517 git.RunGit(overlay_dir, ['rebase', existing_branch])
David Jamesd6708c02012-03-22 10:49:15 -0700518
Chris Sosadad0d322011-01-31 16:37:33 -0800519 chrome_version_atom = MarkChromeEBuildAsStable(
520 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800521 commit_to_use, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800522 # Explicit print to communicate to caller.
Yu-Ju Hong078c9ec2014-08-06 18:25:16 -0700523 if chrome_version_atom:
524 if options.boards:
525 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
526 [chrome_version_atom])
Chris Sosadad0d322011-01-31 16:37:33 -0800527 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom