blob: 124df0a92787c9630f59b030b85abb9b5e09524b [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
Don Garrett88b8d782014-05-13 17:30:55 -070025from chromite.cbuildbot import constants
26from chromite.cbuildbot 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
Mike Frysingercc838832014-05-24 13:10:30 -040071
petermayo@chromium.org163b3372011-09-12 02:06:05 -040072def _GetSpecificVersionUrl(base_url, revision, time_to_wait=600):
73 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040074
75 Args:
76 base_url: URL for the root of the chromium checkout.
petermayo@chromium.org163b3372011-09-12 02:06:05 -040077 revision: the SVN revision we want to use.
78 time_to_wait: the minimum period before abandoning our wait for the
79 desired revision to be present.
Peter Mayo177500f2011-09-09 17:25:23 -040080 """
petermayo@chromium.org163b3372011-09-12 02:06:05 -040081 svn_url = os.path.join(_GetSvnUrl(base_url), 'src', 'chrome', 'VERSION')
petermayo@chromium.org163b3372011-09-12 02:06:05 -040082 if not revision or not (int(revision) > 0):
83 raise Exception('Revision must be positive, got %s' % revision)
84
85 start = time.time()
86 # Use the fact we are SVN, hence ordered.
87 # Dodge the fact it will silently ignore the revision if it is not
88 # yet known. (i.e. too high)
ChromeOS Developer03118eb2013-02-12 14:27:09 -080089 repo_version = gclient.GetTipOfTrunkSvnRevision(base_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040090 while revision > repo_version:
91 if time.time() - start > time_to_wait:
92 raise Exception('Timeout Exceeeded')
93
David James1b363582012-12-17 11:53:11 -080094 msg = 'Repository only has version %s, looking for %s. Sleeping...'
95 cros_build_lib.Info(msg, repo_version, revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040096 time.sleep(30)
ChromeOS Developer03118eb2013-02-12 14:27:09 -080097 repo_version = gclient.GetTipOfTrunkSvnRevision(base_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040098
ChromeOS Developer03118eb2013-02-12 14:27:09 -080099 chrome_version_info = cros_build_lib.RunCommand(
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400100 ['svn', 'cat', '-r', revision, svn_url],
101 redirect_stdout=True,
102 error_message='Could not read version file at %s revision %s.' %
J. Richard Barnetted422f622011-11-17 09:39:46 -0800103 (svn_url, revision)).output
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400104
105 return _GetVersionContents(chrome_version_info)
106
Peter Mayo177500f2011-09-09 17:25:23 -0400107
108def _GetTipOfTrunkVersionFile(root):
109 """Returns the current Chromium version, from a file in a checkout.
110
111 Args:
112 root: path to the root of the chromium checkout.
113 """
114 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800115 chrome_version_info = cros_build_lib.RunCommand(
Peter Mayo177500f2011-09-09 17:25:23 -0400116 ['cat', version_file],
117 redirect_stdout=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800118 error_message='Could not read version file at %s.' % version_file).output
Peter Mayo177500f2011-09-09 17:25:23 -0400119
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400120 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400121
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800122
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700123def CheckIfChromeRightForOS(url):
124 """Checks if DEPS is right for Chrome OS.
125
126 This function checks for a variable called 'buildspec_platforms' to
127 find out if its 'chromeos' or 'all'. If any of those values,
128 then it chooses that DEPS.
129
130 Args:
131 url: url where DEPS file present.
132
133 Returns:
134 True if DEPS is the right Chrome for Chrome OS.
135 """
136 deps_contents = cros_build_lib.RunCommand(['svn', 'cat', url],
137 redirect_stdout=True).output
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700138
Dharani Govindancbbf69c2014-07-29 15:37:39 -0700139 platforms_search = re.search(r'buildspec_platforms.*\s.*\s', deps_contents)
140
141 if platforms_search:
142 platforms = platforms_search.group()
143 if 'chromeos' in platforms or 'all' in platforms:
144 return True
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700145
146 return False
147
148
Yu-Ju Hong39806322014-06-24 16:46:32 -0700149def GetLatestRelease(base_url, branch=None):
Chris Sosadad0d322011-01-31 16:37:33 -0800150 """Gets the latest release version from the buildspec_url for the branch.
151
152 Args:
Don Garrett25f309a2014-03-19 14:02:12 -0700153 base_url: Base URL for the SVN repository.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500154 branch: If set, gets the latest release for branch, otherwise latest
Chris Sosadad0d322011-01-31 16:37:33 -0800155 release.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500156
Chris Sosadad0d322011-01-31 16:37:33 -0800157 Returns:
158 Latest version string.
159 """
Peter Mayof65b8412011-08-26 01:22:21 -0400160 buildspec_url = os.path.join(base_url, 'releases')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800161 svn_ls = cros_build_lib.RunCommand(['svn', 'ls', buildspec_url],
162 redirect_stdout=True).output
163 sorted_ls = cros_build_lib.RunCommand(['sort', '--version-sort', '-r'],
164 input=svn_ls,
165 redirect_stdout=True).output
Chris Sosadad0d322011-01-31 16:37:33 -0800166 if branch:
David James7c352bc2013-03-15 14:19:57 -0700167 chrome_version_re = re.compile(r'^%s\.\d+.*' % branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800168 else:
David James7c352bc2013-03-15 14:19:57 -0700169 chrome_version_re = re.compile(r'^[0-9]+\..*')
Chris Sosadad0d322011-01-31 16:37:33 -0800170
Peter Mayoad8173d2011-11-08 16:18:23 -0500171 for chrome_version in sorted_ls.splitlines():
J. Richard Barnetted422f622011-11-17 09:39:46 -0800172 if chrome_version_re.match(chrome_version):
173 deps_url = os.path.join(buildspec_url, chrome_version, 'DEPS')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800174 deps_check = cros_build_lib.RunCommand(['svn', 'ls', deps_url],
175 error_code_ok=True,
176 redirect_stdout=True).output
J. Richard Barnetted422f622011-11-17 09:39:46 -0800177 if deps_check == 'DEPS\n':
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700178 if CheckIfChromeRightForOS(deps_url):
179 return chrome_version.rstrip('/')
Peter Mayoad8173d2011-11-08 16:18:23 -0500180
181 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800182
183
184def _GetStickyEBuild(stable_ebuilds):
185 """Returns the sticky ebuild."""
186 sticky_ebuilds = []
187 non_sticky_re = re.compile(_NON_STICKY_REGEX)
188 for ebuild in stable_ebuilds:
189 if not non_sticky_re.match(ebuild.version):
190 sticky_ebuilds.append(ebuild)
191
192 if not sticky_ebuilds:
193 raise Exception('No sticky ebuilds found')
194 elif len(sticky_ebuilds) > 1:
David James1b363582012-12-17 11:53:11 -0800195 cros_build_lib.Warning('More than one sticky ebuild found')
Chris Sosadad0d322011-01-31 16:37:33 -0800196
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800197 return portage_utilities.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800198
199
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800200class ChromeEBuild(portage_utilities.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800201 """Thin sub-class of EBuild that adds a chrome_version field."""
David James7c352bc2013-03-15 14:19:57 -0700202 chrome_version_re = re.compile(r'.*%s-(%s|9999).*' % (
David James629febb2012-11-25 13:07:34 -0800203 constants.CHROME_PN, _CHROME_VERSION_REGEX))
Chris Sosadad0d322011-01-31 16:37:33 -0800204 chrome_version = ''
205
206 def __init__(self, path):
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800207 portage_utilities.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800208 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
209 if re_match:
210 self.chrome_version = re_match.group(1)
211
Chris Sosadad0d322011-01-31 16:37:33 -0800212 def __str__(self):
213 return self.ebuild_path
214
215
216def FindChromeCandidates(overlay_dir):
217 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
218
219 Args:
220 overlay_dir: The path to chrome's portage overlay dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500221
Chris Sosadad0d322011-01-31 16:37:33 -0800222 Returns:
223 Tuple [unstable_ebuild, stable_ebuilds].
Mike Frysinger1a736a82013-12-12 01:50:59 -0500224
Chris Sosadad0d322011-01-31 16:37:33 -0800225 Raises:
226 Exception: if no unstable ebuild exists for Chrome.
227 """
228 stable_ebuilds = []
229 unstable_ebuilds = []
230 for path in [
231 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
232 if path.endswith('.ebuild'):
233 ebuild = ChromeEBuild(path)
234 if not ebuild.chrome_version:
David James1b363582012-12-17 11:53:11 -0800235 cros_build_lib.Warning('Poorly formatted ebuild found at %s' % path)
Chris Sosadad0d322011-01-31 16:37:33 -0800236 else:
237 if '9999' in ebuild.version:
238 unstable_ebuilds.append(ebuild)
239 else:
240 stable_ebuilds.append(ebuild)
241
242 # Apply some sanity checks.
243 if not unstable_ebuilds:
244 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
245 if not stable_ebuilds:
David James1b363582012-12-17 11:53:11 -0800246 cros_build_lib.Warning('Missing stable ebuild for %s' % overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800247
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800248 return portage_utilities.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800249
250
251def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
252 """Finds the Chrome uprev candidate for the given chrome_rev.
253
254 Using the pre-flight logic, this means the stable ebuild you are uprevving
255 from. The difference here is that the version could be different and in
256 that case we want to find it to delete it.
257
258 Args:
259 stable_ebuilds: A list of stable ebuilds.
260 chrome_rev: The chrome_rev designating which candidate to find.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500261 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800262 components. For example: 9.0.553. Can be None but not if chrome_rev
263 is CHROME_REV_STICKY.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500264
Chris Sosadad0d322011-01-31 16:37:33 -0800265 Returns:
Mike Frysinger1a736a82013-12-12 01:50:59 -0500266 The EBuild, otherwise None if none found.
Chris Sosadad0d322011-01-31 16:37:33 -0800267 """
268 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400269 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
270 constants.CHROME_REV_SPEC]:
271 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400272 # not just for the fun of confusion.
David James7c352bc2013-03-15 14:19:57 -0700273 chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800274 for ebuild in stable_ebuilds:
275 if chrome_branch_re.search(ebuild.version):
276 candidates.append(ebuild)
277
Ryan Cuic6e097d2011-06-16 12:23:14 -0700278 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800279 assert sticky_branch is not None
David James7c352bc2013-03-15 14:19:57 -0700280 chrome_branch_re = re.compile(r'%s\..*' % sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800281 for ebuild in stable_ebuilds:
282 if chrome_branch_re.search(ebuild.version):
283 candidates.append(ebuild)
284
285 else:
David James7c352bc2013-03-15 14:19:57 -0700286 chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800287 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800288 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800289 candidates.append(ebuild)
290
291 if candidates:
J. Richard Barnettef6697cf2011-11-18 12:42:08 -0800292 return portage_utilities.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800293 else:
294 return None
295
Mike Frysingercc838832014-05-24 13:10:30 -0400296
Chris Masone592cab52011-08-02 14:05:48 -0700297def _AnnotateAndPrint(text, url):
298 """Add buildbot trappings to print <a href='url'>text</a> in the waterfall.
299
300 Args:
301 text: Anchor text for the link
302 url: the URL to which to link
303 """
Don Garrette60de902011-10-17 18:52:05 -0700304 print >> sys.stderr, '\n@@@STEP_LINK@%(text)s@%(url)s@@@' % { 'text': text,
Chris Masone592cab52011-08-02 14:05:48 -0700305 'url': url }
306
307def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
308 """Return appropriately formatted link to revision info, given versions
309
310 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
311 page that prints the Chromium revisions between those two versions.
312
313 Args:
314 old_chrome_version: version to diff from
315 chrome_version: version to which to diff
Mike Frysinger1a736a82013-12-12 01:50:59 -0500316
Chris Masone592cab52011-08-02 14:05:48 -0700317 Returns:
318 The desired URL.
319 """
320 return _CHROME_VERSION_URL % { 'old': old_chrome_version,
321 'new': chrome_version }
322
Chris Masone592cab52011-08-02 14:05:48 -0700323def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
324 """Returns a link to the list of revisions between two Chromium versions
325
326 Given two ChromeEBuilds and the kind of rev we're doing, generate a
327 link to a page that prints the Chromium changes between those two
328 revisions, inclusive.
329
330 Args:
331 old_chrome: ebuild for the version to diff from
332 new_chrome: ebuild for the version to which to diff
333 chrome_rev: one of constants.VALID_CHROME_REVISIONS
Mike Frysinger1a736a82013-12-12 01:50:59 -0500334
Chris Masone592cab52011-08-02 14:05:48 -0700335 Returns:
336 The desired URL.
337 """
Chris Sosadd611df2012-02-03 15:26:23 -0800338 assert chrome_rev in _REV_TYPES_FOR_LINKS
339 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
340 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800341
Mike Frysingercc838832014-05-24 13:10:30 -0400342
Chris Sosadad0d322011-01-31 16:37:33 -0800343def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800344 chrome_version, commit, overlay_dir):
David James7c352bc2013-03-15 14:19:57 -0700345 r"""Uprevs the chrome ebuild specified by chrome_rev.
Chris Sosadad0d322011-01-31 16:37:33 -0800346
347 This is the main function that uprevs the chrome_rev from a stable candidate
348 to its new version.
349
350 Args:
351 stable_candidate: ebuild that corresponds to the stable ebuild we are
352 revving from. If None, builds the a new ebuild given the version
353 and logic for chrome_rev type with revision set to 1.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500354 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
Peter Mayo177500f2011-09-09 17:25:23 -0400355 chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400356 constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for
357 the specified version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700358 constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for
359 the TOT version and uses the portage suffix of _alpha.
Peter Mayo177500f2011-09-09 17:25:23 -0400360 constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for
361 the local version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700362 constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they
363 are release candidates for the next sticky version.
364 constants.CHROME_REV_STICKY - Revs the sticky version.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500365 chrome_version: The \d.\d.\d.\d version of Chrome.
366 commit: Used with constants.CHROME_REV_TOT. The svn revision of chrome.
367 overlay_dir: Path to the chromeos-chrome package dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500368
Chris Sosadad0d322011-01-31 16:37:33 -0800369 Returns:
370 Full portage version atom (including rc's, etc) that was revved.
371 """
Chris Sosa8be39132011-04-14 12:09:24 -0700372 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
373 """Returns True if the new ebuild is redundant.
374
375 This is True if there if the current stable ebuild is the exact same copy
David James89608f92012-11-03 14:14:12 -0700376 of the new one.
Chris Sosa8be39132011-04-14 12:09:24 -0700377 """
378 if not stable_ebuild:
379 return False
380
381 if stable_candidate.chrome_version == new_ebuild.chrome_version:
David James89608f92012-11-03 14:14:12 -0700382 return filecmp.cmp(
383 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
Chris Sosa8be39132011-04-14 12:09:24 -0700384
David James629febb2012-11-25 13:07:34 -0800385 # Mark latest release and sticky branches as stable.
386 mark_stable = chrome_rev not in [constants.CHROME_REV_TOT,
387 constants.CHROME_REV_SPEC,
388 constants.CHROME_REV_LOCAL]
389
Chris Sosadad0d322011-01-31 16:37:33 -0800390 # Case where we have the last stable candidate with same version just rev.
391 if stable_candidate and stable_candidate.chrome_version == chrome_version:
392 new_ebuild_path = '%s-r%d.ebuild' % (
393 stable_candidate.ebuild_path_no_revision,
394 stable_candidate.current_revision + 1)
395 else:
David James629febb2012-11-25 13:07:34 -0800396 suffix = 'rc' if mark_stable else 'alpha'
397 pf = '%s-%s_%s-r1' % (constants.CHROME_PN, chrome_version, suffix)
398 new_ebuild_path = os.path.join(overlay_dir, '%s.ebuild' % pf)
Chris Sosadad0d322011-01-31 16:37:33 -0800399
David Jamesa6792552012-04-03 10:05:35 -0700400 chrome_variables = dict()
401 if commit:
402 chrome_variables[_CHROME_SVN_TAG] = commit
403
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800404 portage_utilities.EBuild.MarkAsStable(
David James065b2012012-04-01 14:51:11 -0700405 unstable_ebuild.ebuild_path, new_ebuild_path,
David Jamesa6792552012-04-03 10:05:35 -0700406 chrome_variables, make_stable=mark_stable)
Chris Sosadad0d322011-01-31 16:37:33 -0800407 new_ebuild = ChromeEBuild(new_ebuild_path)
Chris Sosa8be39132011-04-14 12:09:24 -0700408
409 # Determine whether this is ebuild is redundant.
410 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
David James1b363582012-12-17 11:53:11 -0800411 msg = 'Previous ebuild with same version found and ebuild is redundant.'
412 cros_build_lib.Info(msg)
Chris Sosa8be39132011-04-14 12:09:24 -0700413 os.unlink(new_ebuild_path)
414 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800415
Chris Sosadd611df2012-02-03 15:26:23 -0800416 if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS:
Chris Masone592cab52011-08-02 14:05:48 -0700417 _AnnotateAndPrint('Chromium revisions',
418 GetChromeRevisionListLink(stable_candidate,
419 new_ebuild,
420 chrome_rev))
421
David James67d73252013-09-19 17:33:12 -0700422 git.RunGit(overlay_dir, ['add', new_ebuild_path])
Chris Sosa9ba47752012-02-27 15:27:37 -0800423 if stable_candidate and not stable_candidate.IsSticky():
David James67d73252013-09-19 17:33:12 -0700424 git.RunGit(overlay_dir, ['rm', stable_candidate.ebuild_path])
Chris Sosadad0d322011-01-31 16:37:33 -0800425
J. Richard Barnette0cfc5052011-11-28 14:31:39 -0800426 portage_utilities.EBuild.CommitChange(
Chris Sosadad0d322011-01-31 16:37:33 -0800427 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400428 'chrome_version': chrome_version},
429 overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800430
Chris Sosadad0d322011-01-31 16:37:33 -0800431 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
432
433
Chris Sosad53f8fd2011-10-21 15:15:19 -0700434def ParseMaxRevision(revision_list):
435 """Returns the max revision from a list of url@revision string."""
David James7c352bc2013-03-15 14:19:57 -0700436 revision_re = re.compile(r'.*@(\d+)')
Chris Sosad53f8fd2011-10-21 15:15:19 -0700437
438 def RevisionKey(revision):
439 return revision_re.match(revision).group(1)
440
441 max_revision = max(revision_list.split(), key=RevisionKey)
442 return max_revision.rpartition('@')[2]
443
444
David James1b363582012-12-17 11:53:11 -0800445def main(_argv):
Chris Sosa0f295aa2011-10-21 14:10:28 -0700446 usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700447 usage = '%s OPTIONS [%s]' % (__file__, usage_options)
Chris Sosadad0d322011-01-31 16:37:33 -0800448 parser = optparse.OptionParser(usage)
Yu-Ju Hong575b3662014-08-05 13:33:41 -0700449 parser.add_option('-b', '--boards', default=None)
David Jamesef74b1c2012-11-12 07:47:47 -0800450 parser.add_option('-c', '--chrome_url', default=gclient.GetBaseURLs()[0])
David Jamesfb160012014-07-01 10:00:57 -0700451 parser.add_option('-f', '--force_version', default=None,
452 help='Chrome version or SVN revision number to use')
Chris Sosadad0d322011-01-31 16:37:33 -0800453 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
454 'trunk', 'src'),
455 help='Path to the src directory')
456 parser.add_option('-t', '--tracking_branch', default='cros/master',
457 help='Branch we are tracking changes against')
458 (options, args) = parser.parse_args()
459
Ryan Cuic6e097d2011-06-16 12:23:14 -0700460 if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
461 parser.error('Commit requires arg set to one of %s.'
462 % constants.VALID_CHROME_REVISIONS)
Chris Sosadad0d322011-01-31 16:37:33 -0800463
David James9a5980e2014-07-16 09:37:00 -0700464 if options.force_version and args[0] not in (constants.CHROME_REV_SPEC,
465 constants.CHROME_REV_LATEST):
David Jamesfb160012014-07-01 10:00:57 -0700466 parser.error('--force_version is not compatible with the %r '
467 'option.' % (args[0],))
468
Chris Sosadad0d322011-01-31 16:37:33 -0800469 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
470 {'srcroot': options.srcroot})
471 chrome_rev = args[0]
472 version_to_uprev = None
473 commit_to_use = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800474 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800475
476 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800477
Peter Mayo177500f2011-09-09 17:25:23 -0400478 if chrome_rev == constants.CHROME_REV_LOCAL:
479 if 'CHROME_ROOT' in os.environ:
480 chrome_root = os.environ['CHROME_ROOT']
481 else:
482 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
483
484 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
485 commit_to_use = 'Unknown'
David James1b363582012-12-17 11:53:11 -0800486 cros_build_lib.Info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400487 elif chrome_rev == constants.CHROME_REV_SPEC:
David Jamesfb160012014-07-01 10:00:57 -0700488 if '.' in options.force_version:
489 version_to_uprev = options.force_version
490 else:
491 commit_to_use = options.force_version
492 if '@' in commit_to_use:
493 commit_to_use = ParseMaxRevision(commit_to_use)
494 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
495 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400496 elif chrome_rev == constants.CHROME_REV_TOT:
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800497 commit_to_use = gclient.GetTipOfTrunkSvnRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400498 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
499 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700500 elif chrome_rev == constants.CHROME_REV_LATEST:
David James9a5980e2014-07-16 09:37:00 -0700501 if options.force_version:
502 if '.' not in options.force_version:
503 parser.error('%s only accepts released Chrome versions, not SVN or '
504 'Git revisions.' % (chrome_rev,))
505 version_to_uprev = options.force_version
506 else:
507 version_to_uprev = GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800508 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800509 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
510 sticky_version = sticky_ebuild.chrome_version
511 sticky_branch = sticky_version.rpartition('.')[0]
Yu-Ju Hong39806322014-06-24 16:46:32 -0700512 version_to_uprev = GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800513
514 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
515 sticky_branch)
516
517 if stable_candidate:
David James1b363582012-12-17 11:53:11 -0800518 cros_build_lib.Info('Stable candidate found %s' % stable_candidate)
Chris Sosadad0d322011-01-31 16:37:33 -0800519 else:
David James1b363582012-12-17 11:53:11 -0800520 cros_build_lib.Info('No stable candidate found.')
Chris Sosadad0d322011-01-31 16:37:33 -0800521
Chris Sosa8049f3b2011-05-02 20:09:28 -0700522 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David James97d95872012-11-16 15:09:56 -0800523 existing_branch = git.GetCurrentBranch(overlay_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700524 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400525 tracking_branch, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800526 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700527
528 # In the case of uprevving overlays that have patches applied to them,
529 # include the patched changes in the stabilizing branch.
530 if existing_branch:
David James67d73252013-09-19 17:33:12 -0700531 git.RunGit(overlay_dir, ['rebase', existing_branch])
David Jamesd6708c02012-03-22 10:49:15 -0700532
Chris Sosadad0d322011-01-31 16:37:33 -0800533 chrome_version_atom = MarkChromeEBuildAsStable(
534 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev,
Chris Sosa9ba47752012-02-27 15:27:37 -0800535 commit_to_use, overlay_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800536 # Explicit print to communicate to caller.
Yu-Ju Hong575b3662014-08-05 13:33:41 -0700537 if chrome_version_atom and options.boards:
David Jamescc09c9b2012-01-26 22:10:13 -0800538 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
539 [chrome_version_atom])
Chris Sosadad0d322011-01-31 16:37:33 -0800540 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom