blob: d45c70507cb519d6f8383ef4f85ebe687aa86d56 [file] [log] [blame]
Chris Sosa9ba47752012-02-27 15:27:37 -08001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Sosadad0d322011-01-31 16:37:33 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""This module uprevs Chrome for cbuildbot.
6
7After calling, it prints outs CHROME_VERSION_ATOM=(version atom string). A
8caller could then use this atom with emerge to build the newly uprevved version
9of Chrome e.g.
10
11./cros_mark_chrome_as_stable tot
12Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
13
14emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1
15"""
16
Mike Frysinger383367e2014-09-16 15:06:17 -040017from __future__ import print_function
18
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070019import base64
20import distutils.version
Chris Sosa8be39132011-04-14 12:09:24 -070021import filecmp
Chris Sosadad0d322011-01-31 16:37:33 -080022import optparse
23import os
24import re
Chris Masone592cab52011-08-02 14:05:48 -070025import sys
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070026import urlparse
Chris Sosadad0d322011-01-31 16:37:33 -080027
Don Garrett88b8d782014-05-13 17:30:55 -070028from chromite.cbuildbot import constants
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
Alex Deymo075c2292014-09-04 18:31:50 -070032from chromite.lib import portage_util
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070033from chromite.lib import timeout_util
Mike Frysinger6cb624a2012-05-24 18:17:38 -040034from chromite.scripts import cros_mark_as_stable
Chris Sosadad0d322011-01-31 16:37:33 -080035
Mike Frysinger750c5f52014-09-16 16:16:57 -040036
Chris Sosadad0d322011-01-31 16:37:33 -080037# Helper regex's for finding ebuilds.
David James7c352bc2013-03-15 14:19:57 -070038_CHROME_VERSION_REGEX = r'\d+\.\d+\.\d+\.\d+'
39_NON_STICKY_REGEX = r'%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
Chris Sosadad0d322011-01-31 16:37:33 -080040
41# Dir where all the action happens.
David Zeuthen665d3132014-08-25 15:27:02 -040042_OVERLAY_DIR = '%(srcroot)s/third_party/chromiumos-overlay/'
Chris Sosadad0d322011-01-31 16:37:33 -080043
David Zeuthen665d3132014-08-25 15:27:02 -040044_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for %(chrome_pn)s ebuild '
45 'with version %(chrome_version)s as stable.')
Chris Sosadad0d322011-01-31 16:37:33 -080046
Chris Masone592cab52011-08-02 14:05:48 -070047# URLs that print lists of chrome revisions between two versions of the browser.
48_CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?'
49 'old_version=%(old)s&new_version=%(new)s')
Chris Sosadd611df2012-02-03 15:26:23 -080050
51# Only print links when we rev these types.
52_REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST,
53 constants.CHROME_REV_STICKY]
Chris Masone592cab52011-08-02 14:05:48 -070054
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070055# TODO(szager): This is inaccurate, but is it safe to change? I have no idea.
Chris Masone592cab52011-08-02 14:05:48 -070056_CHROME_SVN_TAG = 'CROS_SVN_COMMIT'
Chris Sosadad0d322011-01-31 16:37:33 -080057
ChromeOS Developer03118eb2013-02-12 14:27:09 -080058
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
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070072def _GetSpecificVersionUrl(git_url, revision, time_to_wait=600):
petermayo@chromium.org163b3372011-09-12 02:06:05 -040073 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040074
75 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070076 git_url: Repository URL for chromium.
77 revision: the git revision we want to use.
petermayo@chromium.org163b3372011-09-12 02:06:05 -040078 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 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070081 parsed_url = urlparse.urlparse(git_url)
82 host = parsed_url[1]
83 path = parsed_url[2].rstrip('/') + (
84 '/+/%s/chrome/VERSION?format=text' % revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040085
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070086 # Allow for git repository replication lag with sleep/retry loop.
87 def _fetch():
88 fh = gob_util.FetchUrl(host, path, ignore_404=True)
89 return fh.read() if fh else None
petermayo@chromium.org163b3372011-09-12 02:06:05 -040090
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070091 def _wait_msg(_remaining_minutes):
92 cros_build_lib.Info(
93 'Repository does not yet have revision %s. Sleeping...',
94 revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040095
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070096 content = timeout_util.WaitForSuccess(
97 retry_check=lambda x: not bool(x),
98 func=_fetch,
99 timeout=time_to_wait,
100 period=30,
101 side_effect_func=_wait_msg)
102 return _GetVersionContents(base64.b64decode(content))
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400103
Peter Mayo177500f2011-09-09 17:25:23 -0400104
105def _GetTipOfTrunkVersionFile(root):
106 """Returns the current Chromium version, from a file in a checkout.
107
108 Args:
109 root: path to the root of the chromium checkout.
110 """
111 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800112 chrome_version_info = cros_build_lib.RunCommand(
Peter Mayo177500f2011-09-09 17:25:23 -0400113 ['cat', version_file],
114 redirect_stdout=True,
J. Richard Barnetted422f622011-11-17 09:39:46 -0800115 error_message='Could not read version file at %s.' % version_file).output
Peter Mayo177500f2011-09-09 17:25:23 -0400116
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400117 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400118
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800119
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700120def CheckIfChromeRightForOS(deps_content):
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700121 """Checks if DEPS is right for Chrome OS.
122
123 This function checks for a variable called 'buildspec_platforms' to
124 find out if its 'chromeos' or 'all'. If any of those values,
125 then it chooses that DEPS.
126
127 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700128 deps_content: Content of release buildspec DEPS file.
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700129
130 Returns:
131 True if DEPS is the right Chrome for Chrome OS.
132 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700133 platforms_search = re.search(r'buildspec_platforms.*\s.*\s', deps_content)
Dharani Govindancbbf69c2014-07-29 15:37:39 -0700134
135 if platforms_search:
136 platforms = platforms_search.group()
137 if 'chromeos' in platforms or 'all' in platforms:
138 return True
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700139
140 return False
141
142
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700143def GetLatestRelease(git_url, branch=None):
144 """Gets the latest release version from the release tags in the repository.
Chris Sosadad0d322011-01-31 16:37:33 -0800145
146 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700147 git_url: URL of git repository.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500148 branch: If set, gets the latest release for branch, otherwise latest
Chris Sosadad0d322011-01-31 16:37:33 -0800149 release.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500150
Chris Sosadad0d322011-01-31 16:37:33 -0800151 Returns:
152 Latest version string.
153 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700154 # TODO(szager): This only works for public release buildspecs in the chromium
155 # src repository. Internal buildspecs are tracked differently. At the time
156 # of writing, I can't find any callers that use this method to scan for
157 # internal buildspecs. But there may be something lurking...
158
159 parsed_url = urlparse.urlparse(git_url)
160 path = parsed_url[2].rstrip('/') + '/+refs/tags?format=JSON'
161 j = gob_util.FetchUrlJson(parsed_url[1], path, ignore_404=False)
Chris Sosadad0d322011-01-31 16:37:33 -0800162 if branch:
David James7c352bc2013-03-15 14:19:57 -0700163 chrome_version_re = re.compile(r'^%s\.\d+.*' % branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800164 else:
David James7c352bc2013-03-15 14:19:57 -0700165 chrome_version_re = re.compile(r'^[0-9]+\..*')
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700166 matching_versions = [key for key in j.keys() if chrome_version_re.match(key)]
167 matching_versions.sort(key=distutils.version.LooseVersion)
168 for chrome_version in reversed(matching_versions):
169 path = parsed_url[2].rstrip() + (
170 '/+/refs/tags/%s/DEPS?format=text' % chrome_version)
171 fh = gob_util.FetchUrl(parsed_url[1], path, ignore_404=False)
172 content = fh.read() if fh else None
173 if content:
174 deps_content = base64.b64decode(content)
175 if CheckIfChromeRightForOS(deps_content):
176 return chrome_version
Peter Mayoad8173d2011-11-08 16:18:23 -0500177
178 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800179
180
181def _GetStickyEBuild(stable_ebuilds):
182 """Returns the sticky ebuild."""
183 sticky_ebuilds = []
184 non_sticky_re = re.compile(_NON_STICKY_REGEX)
185 for ebuild in stable_ebuilds:
186 if not non_sticky_re.match(ebuild.version):
187 sticky_ebuilds.append(ebuild)
188
189 if not sticky_ebuilds:
190 raise Exception('No sticky ebuilds found')
191 elif len(sticky_ebuilds) > 1:
David James1b363582012-12-17 11:53:11 -0800192 cros_build_lib.Warning('More than one sticky ebuild found')
Chris Sosadad0d322011-01-31 16:37:33 -0800193
Alex Deymo075c2292014-09-04 18:31:50 -0700194 return portage_util.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800195
196
Alex Deymo075c2292014-09-04 18:31:50 -0700197class ChromeEBuild(portage_util.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800198 """Thin sub-class of EBuild that adds a chrome_version field."""
David Zeuthen665d3132014-08-25 15:27:02 -0400199 chrome_version_re = re.compile(r'.*-(%s|9999).*' % (
200 _CHROME_VERSION_REGEX))
Chris Sosadad0d322011-01-31 16:37:33 -0800201 chrome_version = ''
202
203 def __init__(self, path):
Alex Deymo075c2292014-09-04 18:31:50 -0700204 portage_util.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800205 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
206 if re_match:
207 self.chrome_version = re_match.group(1)
208
Chris Sosadad0d322011-01-31 16:37:33 -0800209 def __str__(self):
210 return self.ebuild_path
211
212
David Zeuthen665d3132014-08-25 15:27:02 -0400213def FindChromeCandidates(package_dir):
Chris Sosadad0d322011-01-31 16:37:33 -0800214 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
215
216 Args:
David Zeuthen665d3132014-08-25 15:27:02 -0400217 package_dir: The path to where the package ebuild is stored.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500218
Chris Sosadad0d322011-01-31 16:37:33 -0800219 Returns:
220 Tuple [unstable_ebuild, stable_ebuilds].
Mike Frysinger1a736a82013-12-12 01:50:59 -0500221
Chris Sosadad0d322011-01-31 16:37:33 -0800222 Raises:
223 Exception: if no unstable ebuild exists for Chrome.
224 """
225 stable_ebuilds = []
226 unstable_ebuilds = []
227 for path in [
David Zeuthen665d3132014-08-25 15:27:02 -0400228 os.path.join(package_dir, entry) for entry in os.listdir(package_dir)]:
Chris Sosadad0d322011-01-31 16:37:33 -0800229 if path.endswith('.ebuild'):
230 ebuild = ChromeEBuild(path)
231 if not ebuild.chrome_version:
David James1b363582012-12-17 11:53:11 -0800232 cros_build_lib.Warning('Poorly formatted ebuild found at %s' % path)
Chris Sosadad0d322011-01-31 16:37:33 -0800233 else:
234 if '9999' in ebuild.version:
235 unstable_ebuilds.append(ebuild)
236 else:
237 stable_ebuilds.append(ebuild)
238
239 # Apply some sanity checks.
240 if not unstable_ebuilds:
David Zeuthen665d3132014-08-25 15:27:02 -0400241 raise Exception('Missing 9999 ebuild for %s' % package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800242 if not stable_ebuilds:
David Zeuthen665d3132014-08-25 15:27:02 -0400243 cros_build_lib.Warning('Missing stable ebuild for %s' % package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800244
Alex Deymo075c2292014-09-04 18:31:50 -0700245 return portage_util.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800246
247
248def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
249 """Finds the Chrome uprev candidate for the given chrome_rev.
250
251 Using the pre-flight logic, this means the stable ebuild you are uprevving
252 from. The difference here is that the version could be different and in
253 that case we want to find it to delete it.
254
255 Args:
256 stable_ebuilds: A list of stable ebuilds.
257 chrome_rev: The chrome_rev designating which candidate to find.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500258 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800259 components. For example: 9.0.553. Can be None but not if chrome_rev
260 is CHROME_REV_STICKY.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500261
Chris Sosadad0d322011-01-31 16:37:33 -0800262 Returns:
Mike Frysinger1a736a82013-12-12 01:50:59 -0500263 The EBuild, otherwise None if none found.
Chris Sosadad0d322011-01-31 16:37:33 -0800264 """
265 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400266 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
267 constants.CHROME_REV_SPEC]:
268 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400269 # not just for the fun of confusion.
David James7c352bc2013-03-15 14:19:57 -0700270 chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800271 for ebuild in stable_ebuilds:
272 if chrome_branch_re.search(ebuild.version):
273 candidates.append(ebuild)
274
Ryan Cuic6e097d2011-06-16 12:23:14 -0700275 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800276 assert sticky_branch is not None
David James7c352bc2013-03-15 14:19:57 -0700277 chrome_branch_re = re.compile(r'%s\..*' % sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800278 for ebuild in stable_ebuilds:
279 if chrome_branch_re.search(ebuild.version):
280 candidates.append(ebuild)
281
282 else:
David James7c352bc2013-03-15 14:19:57 -0700283 chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800284 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800285 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800286 candidates.append(ebuild)
287
288 if candidates:
Alex Deymo075c2292014-09-04 18:31:50 -0700289 return portage_util.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800290 else:
291 return None
292
Mike Frysingercc838832014-05-24 13:10:30 -0400293
Chris Masone592cab52011-08-02 14:05:48 -0700294def _AnnotateAndPrint(text, url):
295 """Add buildbot trappings to print <a href='url'>text</a> in the waterfall.
296
297 Args:
298 text: Anchor text for the link
299 url: the URL to which to link
300 """
Mike Frysinger383367e2014-09-16 15:06:17 -0400301 print('\n@@@STEP_LINK@%(text)s@%(url)s@@@' % {'text': text, 'url': url},
302 file=sys.stderr)
Chris Masone592cab52011-08-02 14:05:48 -0700303
Mike Frysinger750c5f52014-09-16 16:16:57 -0400304
Chris Masone592cab52011-08-02 14:05:48 -0700305def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
306 """Return appropriately formatted link to revision info, given versions
307
308 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
309 page that prints the Chromium revisions between those two versions.
310
311 Args:
312 old_chrome_version: version to diff from
313 chrome_version: version to which to diff
Mike Frysinger1a736a82013-12-12 01:50:59 -0500314
Chris Masone592cab52011-08-02 14:05:48 -0700315 Returns:
316 The desired URL.
317 """
Mike Frysingerd6e2df02014-11-26 02:55:04 -0500318 return _CHROME_VERSION_URL % {'old': old_chrome_version,
319 'new': chrome_version}
Chris Masone592cab52011-08-02 14:05:48 -0700320
Mike Frysinger750c5f52014-09-16 16:16:57 -0400321
Chris Masone592cab52011-08-02 14:05:48 -0700322def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
323 """Returns a link to the list of revisions between two Chromium versions
324
325 Given two ChromeEBuilds and the kind of rev we're doing, generate a
326 link to a page that prints the Chromium changes between those two
327 revisions, inclusive.
328
329 Args:
330 old_chrome: ebuild for the version to diff from
331 new_chrome: ebuild for the version to which to diff
332 chrome_rev: one of constants.VALID_CHROME_REVISIONS
Mike Frysinger1a736a82013-12-12 01:50:59 -0500333
Chris Masone592cab52011-08-02 14:05:48 -0700334 Returns:
335 The desired URL.
336 """
Chris Sosadd611df2012-02-03 15:26:23 -0800337 assert chrome_rev in _REV_TYPES_FOR_LINKS
338 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
339 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800340
Mike Frysingercc838832014-05-24 13:10:30 -0400341
David Zeuthen665d3132014-08-25 15:27:02 -0400342def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_pn,
343 chrome_rev, chrome_version, commit, package_dir):
David James7c352bc2013-03-15 14:19:57 -0700344 r"""Uprevs the chrome ebuild specified by chrome_rev.
Chris Sosadad0d322011-01-31 16:37:33 -0800345
346 This is the main function that uprevs the chrome_rev from a stable candidate
347 to its new version.
348
349 Args:
350 stable_candidate: ebuild that corresponds to the stable ebuild we are
351 revving from. If None, builds the a new ebuild given the version
352 and logic for chrome_rev type with revision set to 1.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500353 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
David Zeuthen665d3132014-08-25 15:27:02 -0400354 chrome_pn: package name.
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.
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700366 commit: Used with constants.CHROME_REV_TOT. The git revision of chrome.
David Zeuthen665d3132014-08-25 15:27:02 -0400367 package_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'
David Zeuthen665d3132014-08-25 15:27:02 -0400397 pf = '%s-%s_%s-r1' % (chrome_pn, chrome_version, suffix)
398 new_ebuild_path = os.path.join(package_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
Alex Deymo075c2292014-09-04 18:31:50 -0700404 portage_util.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 Zeuthen665d3132014-08-25 15:27:02 -0400422 git.RunGit(package_dir, ['add', new_ebuild_path])
Chris Sosa9ba47752012-02-27 15:27:37 -0800423 if stable_candidate and not stable_candidate.IsSticky():
David Zeuthen665d3132014-08-25 15:27:02 -0400424 git.RunGit(package_dir, ['rm', stable_candidate.ebuild_path])
Chris Sosadad0d322011-01-31 16:37:33 -0800425
Alex Deymo075c2292014-09-04 18:31:50 -0700426 portage_util.EBuild.CommitChange(
David Zeuthen665d3132014-08-25 15:27:02 -0400427 _GIT_COMMIT_MESSAGE % {'chrome_pn': chrome_pn,
428 'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400429 'chrome_version': chrome_version},
David Zeuthen665d3132014-08-25 15:27:02 -0400430 package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800431
Chris Sosadad0d322011-01-31 16:37:33 -0800432 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
433
434
David James1b363582012-12-17 11:53:11 -0800435def main(_argv):
Chris Sosa0f295aa2011-10-21 14:10:28 -0700436 usage_options = '|'.join(constants.VALID_CHROME_REVISIONS)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700437 usage = '%s OPTIONS [%s]' % (__file__, usage_options)
Chris Sosadad0d322011-01-31 16:37:33 -0800438 parser = optparse.OptionParser(usage)
Yu-Ju Hong575b3662014-08-05 13:33:41 -0700439 parser.add_option('-b', '--boards', default=None)
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700440 parser.add_option('-c', '--chrome_url',
441 default=constants.CHROMIUM_GOB_URL)
David Jamesfb160012014-07-01 10:00:57 -0700442 parser.add_option('-f', '--force_version', default=None,
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700443 help='Chrome version or git revision hash to use')
Chris Sosadad0d322011-01-31 16:37:33 -0800444 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
445 'trunk', 'src'),
446 help='Path to the src directory')
447 parser.add_option('-t', '--tracking_branch', default='cros/master',
448 help='Branch we are tracking changes against')
449 (options, args) = parser.parse_args()
450
Ryan Cuic6e097d2011-06-16 12:23:14 -0700451 if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS:
452 parser.error('Commit requires arg set to one of %s.'
453 % constants.VALID_CHROME_REVISIONS)
Chris Sosadad0d322011-01-31 16:37:33 -0800454
David James9a5980e2014-07-16 09:37:00 -0700455 if options.force_version and args[0] not in (constants.CHROME_REV_SPEC,
456 constants.CHROME_REV_LATEST):
David Jamesfb160012014-07-01 10:00:57 -0700457 parser.error('--force_version is not compatible with the %r '
458 'option.' % (args[0],))
459
David Zeuthen665d3132014-08-25 15:27:02 -0400460 overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
461 chrome_package_dir = os.path.join(overlay_dir, constants.CHROME_CP)
Chris Sosadad0d322011-01-31 16:37:33 -0800462 chrome_rev = args[0]
463 version_to_uprev = None
464 commit_to_use = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800465 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800466
David Zeuthen665d3132014-08-25 15:27:02 -0400467 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(chrome_package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800468
Peter Mayo177500f2011-09-09 17:25:23 -0400469 if chrome_rev == constants.CHROME_REV_LOCAL:
470 if 'CHROME_ROOT' in os.environ:
471 chrome_root = os.environ['CHROME_ROOT']
472 else:
473 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
474
475 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
476 commit_to_use = 'Unknown'
David James1b363582012-12-17 11:53:11 -0800477 cros_build_lib.Info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400478 elif chrome_rev == constants.CHROME_REV_SPEC:
David Jamesfb160012014-07-01 10:00:57 -0700479 if '.' in options.force_version:
480 version_to_uprev = options.force_version
481 else:
482 commit_to_use = options.force_version
483 if '@' in commit_to_use:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700484 commit_to_use = commit_to_use.rpartition('@')[2]
David Jamesfb160012014-07-01 10:00:57 -0700485 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
486 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400487 elif chrome_rev == constants.CHROME_REV_TOT:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700488 commit_to_use = gob_util.GetTipOfTrunkRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400489 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
490 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700491 elif chrome_rev == constants.CHROME_REV_LATEST:
David James9a5980e2014-07-16 09:37:00 -0700492 if options.force_version:
493 if '.' not in options.force_version:
494 parser.error('%s only accepts released Chrome versions, not SVN or '
495 'Git revisions.' % (chrome_rev,))
496 version_to_uprev = options.force_version
497 else:
498 version_to_uprev = GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800499 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800500 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
501 sticky_version = sticky_ebuild.chrome_version
502 sticky_branch = sticky_version.rpartition('.')[0]
Yu-Ju Hong39806322014-06-24 16:46:32 -0700503 version_to_uprev = GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800504
505 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
506 sticky_branch)
507
508 if stable_candidate:
David James1b363582012-12-17 11:53:11 -0800509 cros_build_lib.Info('Stable candidate found %s' % stable_candidate)
Chris Sosadad0d322011-01-31 16:37:33 -0800510 else:
David James1b363582012-12-17 11:53:11 -0800511 cros_build_lib.Info('No stable candidate found.')
Chris Sosadad0d322011-01-31 16:37:33 -0800512
Chris Sosa8049f3b2011-05-02 20:09:28 -0700513 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David Zeuthen665d3132014-08-25 15:27:02 -0400514 existing_branch = git.GetCurrentBranch(chrome_package_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700515 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
David Zeuthen665d3132014-08-25 15:27:02 -0400516 tracking_branch,
517 chrome_package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800518 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700519
520 # In the case of uprevving overlays that have patches applied to them,
521 # include the patched changes in the stabilizing branch.
522 if existing_branch:
David Zeuthen665d3132014-08-25 15:27:02 -0400523 git.RunGit(chrome_package_dir, ['rebase', existing_branch])
David Jamesd6708c02012-03-22 10:49:15 -0700524
Chris Sosadad0d322011-01-31 16:37:33 -0800525 chrome_version_atom = MarkChromeEBuildAsStable(
David Zeuthen665d3132014-08-25 15:27:02 -0400526 stable_candidate, unstable_ebuild, 'chromeos-chrome', chrome_rev,
527 version_to_uprev, commit_to_use, chrome_package_dir)
Yu-Ju Hong078c9ec2014-08-06 18:25:16 -0700528 if chrome_version_atom:
529 if options.boards:
530 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
531 [chrome_version_atom])
David Zeuthen665d3132014-08-25 15:27:02 -0400532
533 # If we did rev Chrome, now is a good time to uprev other packages.
534 for other_ebuild in constants.OTHER_CHROME_PACKAGES:
535 other_ebuild_name = os.path.basename(other_ebuild)
536 other_package_dir = os.path.join(overlay_dir, other_ebuild)
537 (other_unstable_ebuild, other_stable_ebuilds) = FindChromeCandidates(
538 other_package_dir)
539 other_stable_candidate = FindChromeUprevCandidate(other_stable_ebuilds,
540 chrome_rev,
541 sticky_branch)
542 revved_atom = MarkChromeEBuildAsStable(other_stable_candidate,
543 other_unstable_ebuild,
544 other_ebuild_name,
545 chrome_rev, version_to_uprev,
546 commit_to_use, other_package_dir)
547 if revved_atom and options.boards:
548 cros_mark_as_stable.CleanStalePackages(options.boards.split(':'),
549 [revved_atom])
550
551 # Explicit print to communicate to caller.
552 if chrome_version_atom:
Mike Frysinger383367e2014-09-16 15:06:17 -0400553 print('CHROME_VERSION_ATOM=%s' % chrome_version_atom)