Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """This module uprevs Chrome for cbuildbot. |
| 8 | |
| 9 | After calling, it prints outs CHROME_VERSION_ATOM=(version atom string). A |
| 10 | caller could then use this atom with emerge to build the newly uprevved version |
| 11 | of Chrome e.g. |
| 12 | |
| 13 | ./cros_mark_chrome_as_stable tot |
| 14 | Returns chrome-base/chromeos-chrome-8.0.552.0_alpha_r1 |
| 15 | |
| 16 | emerge-x86-generic =chrome-base/chromeos-chrome-8.0.552.0_alpha_r1 |
| 17 | """ |
| 18 | |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 19 | import filecmp |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 20 | import optparse |
| 21 | import os |
| 22 | import re |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 23 | import sys |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 24 | import time |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 25 | |
Mike Frysinger | 6cb624a | 2012-05-24 18:17:38 -0400 | [diff] [blame] | 26 | from chromite.buildbot import constants |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 27 | from chromite.buildbot import portage_utilities |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 28 | from chromite.lib import cros_build_lib |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 29 | from chromite.lib import gclient |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 30 | from chromite.lib import git |
Mike Frysinger | 6cb624a | 2012-05-24 18:17:38 -0400 | [diff] [blame] | 31 | from chromite.scripts import cros_mark_as_stable |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 32 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 33 | # Helper regex's for finding ebuilds. |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 34 | _CHROME_VERSION_REGEX = r'\d+\.\d+\.\d+\.\d+' |
| 35 | _NON_STICKY_REGEX = r'%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 36 | |
| 37 | # Dir where all the action happens. |
David James | 629febb | 2012-11-25 13:07:34 -0800 | [diff] [blame] | 38 | _CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay/' + |
| 39 | constants.CHROME_CP) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 40 | |
| 41 | _GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version ' |
| 42 | '%(chrome_version)s as stable.') |
| 43 | |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 44 | # URLs that print lists of chrome revisions between two versions of the browser. |
| 45 | _CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?' |
| 46 | 'old_version=%(old)s&new_version=%(new)s') |
Chris Sosa | dd611df | 2012-02-03 15:26:23 -0800 | [diff] [blame] | 47 | |
| 48 | # Only print links when we rev these types. |
| 49 | _REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST, |
| 50 | constants.CHROME_REV_STICKY] |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 51 | |
| 52 | _CHROME_SVN_TAG = 'CROS_SVN_COMMIT' |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 53 | |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 54 | |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 55 | def _GetSvnUrl(base_url): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 56 | """Returns the path to the svn url for the given chrome branch.""" |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 57 | return os.path.join(base_url, 'trunk') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 58 | |
| 59 | |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 60 | def _GetVersionContents(chrome_version_info): |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 61 | """Returns the current Chromium version, from the contents of a VERSION file. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 62 | |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 63 | Args: |
| 64 | chrome_version_info: The contents of a chromium VERSION file. |
| 65 | """ |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 66 | chrome_version_array = [] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 67 | for line in chrome_version_info.splitlines(): |
| 68 | chrome_version_array.append(line.rpartition('=')[2]) |
| 69 | |
| 70 | return '.'.join(chrome_version_array) |
| 71 | |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 72 | def _GetSpecificVersionUrl(base_url, revision, time_to_wait=600): |
| 73 | """Returns the Chromium version, from a repository URL and version. |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 74 | |
| 75 | Args: |
| 76 | base_url: URL for the root of the chromium checkout. |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 77 | 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 Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 80 | """ |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 81 | svn_url = os.path.join(_GetSvnUrl(base_url), 'src', 'chrome', 'VERSION') |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 82 | 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 Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 89 | repo_version = gclient.GetTipOfTrunkSvnRevision(base_url) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 90 | while revision > repo_version: |
| 91 | if time.time() - start > time_to_wait: |
| 92 | raise Exception('Timeout Exceeeded') |
| 93 | |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 94 | msg = 'Repository only has version %s, looking for %s. Sleeping...' |
| 95 | cros_build_lib.Info(msg, repo_version, revision) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 96 | time.sleep(30) |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 97 | repo_version = gclient.GetTipOfTrunkSvnRevision(base_url) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 98 | |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 99 | chrome_version_info = cros_build_lib.RunCommand( |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 100 | ['svn', 'cat', '-r', revision, svn_url], |
| 101 | redirect_stdout=True, |
| 102 | error_message='Could not read version file at %s revision %s.' % |
J. Richard Barnette | d422f62 | 2011-11-17 09:39:46 -0800 | [diff] [blame] | 103 | (svn_url, revision)).output |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 104 | |
| 105 | return _GetVersionContents(chrome_version_info) |
| 106 | |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 107 | |
| 108 | def _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 Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 115 | chrome_version_info = cros_build_lib.RunCommand( |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 116 | ['cat', version_file], |
| 117 | redirect_stdout=True, |
J. Richard Barnette | d422f62 | 2011-11-17 09:39:46 -0800 | [diff] [blame] | 118 | error_message='Could not read version file at %s.' % version_file).output |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 119 | |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 120 | return _GetVersionContents(chrome_version_info) |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 121 | |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 122 | |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 123 | def _GetLatestRelease(base_url, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 124 | """Gets the latest release version from the buildspec_url for the branch. |
| 125 | |
| 126 | Args: |
| 127 | branch: If set, gets the latest release for branch, otherwise latest |
| 128 | release. |
| 129 | Returns: |
| 130 | Latest version string. |
| 131 | """ |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 132 | buildspec_url = os.path.join(base_url, 'releases') |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 133 | 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 Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 138 | if branch: |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 139 | chrome_version_re = re.compile(r'^%s\.\d+.*' % branch) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 140 | else: |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 141 | chrome_version_re = re.compile(r'^[0-9]+\..*') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 142 | |
Peter Mayo | ad8173d | 2011-11-08 16:18:23 -0500 | [diff] [blame] | 143 | for chrome_version in sorted_ls.splitlines(): |
J. Richard Barnette | d422f62 | 2011-11-17 09:39:46 -0800 | [diff] [blame] | 144 | if chrome_version_re.match(chrome_version): |
| 145 | deps_url = os.path.join(buildspec_url, chrome_version, 'DEPS') |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 146 | deps_check = cros_build_lib.RunCommand(['svn', 'ls', deps_url], |
| 147 | error_code_ok=True, |
| 148 | redirect_stdout=True).output |
J. Richard Barnette | d422f62 | 2011-11-17 09:39:46 -0800 | [diff] [blame] | 149 | if deps_check == 'DEPS\n': |
| 150 | return chrome_version.rstrip('/') |
Peter Mayo | ad8173d | 2011-11-08 16:18:23 -0500 | [diff] [blame] | 151 | |
| 152 | return None |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 153 | |
| 154 | |
| 155 | def _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 James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 166 | cros_build_lib.Warning('More than one sticky ebuild found') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 167 | |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 168 | return portage_utilities.BestEBuild(sticky_ebuilds) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 169 | |
| 170 | |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 171 | class ChromeEBuild(portage_utilities.EBuild): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 172 | """Thin sub-class of EBuild that adds a chrome_version field.""" |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 173 | chrome_version_re = re.compile(r'.*%s-(%s|9999).*' % ( |
David James | 629febb | 2012-11-25 13:07:34 -0800 | [diff] [blame] | 174 | constants.CHROME_PN, _CHROME_VERSION_REGEX)) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 175 | chrome_version = '' |
| 176 | |
| 177 | def __init__(self, path): |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 178 | portage_utilities.EBuild.__init__(self, path) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 179 | 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 Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 183 | def __str__(self): |
| 184 | return self.ebuild_path |
| 185 | |
| 186 | |
| 187 | def 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. |
| 192 | Returns: |
| 193 | Tuple [unstable_ebuild, stable_ebuilds]. |
| 194 | Raises: |
| 195 | Exception: if no unstable ebuild exists for Chrome. |
| 196 | """ |
| 197 | stable_ebuilds = [] |
| 198 | unstable_ebuilds = [] |
| 199 | for path in [ |
| 200 | os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]: |
| 201 | if path.endswith('.ebuild'): |
| 202 | ebuild = ChromeEBuild(path) |
| 203 | if not ebuild.chrome_version: |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 204 | cros_build_lib.Warning('Poorly formatted ebuild found at %s' % path) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 205 | else: |
| 206 | if '9999' in ebuild.version: |
| 207 | unstable_ebuilds.append(ebuild) |
| 208 | else: |
| 209 | stable_ebuilds.append(ebuild) |
| 210 | |
| 211 | # Apply some sanity checks. |
| 212 | if not unstable_ebuilds: |
| 213 | raise Exception('Missing 9999 ebuild for %s' % overlay_dir) |
| 214 | if not stable_ebuilds: |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 215 | cros_build_lib.Warning('Missing stable ebuild for %s' % overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 216 | |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 217 | return portage_utilities.BestEBuild(unstable_ebuilds), stable_ebuilds |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 218 | |
| 219 | |
| 220 | def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch): |
| 221 | """Finds the Chrome uprev candidate for the given chrome_rev. |
| 222 | |
| 223 | Using the pre-flight logic, this means the stable ebuild you are uprevving |
| 224 | from. The difference here is that the version could be different and in |
| 225 | that case we want to find it to delete it. |
| 226 | |
| 227 | Args: |
| 228 | stable_ebuilds: A list of stable ebuilds. |
| 229 | chrome_rev: The chrome_rev designating which candidate to find. |
| 230 | sticky_branch: The the branch that is currently sticky with Major/Minor |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 231 | components. For example: 9.0.553. Can be None but not if chrome_rev |
| 232 | is CHROME_REV_STICKY. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 233 | Returns: |
| 234 | Returns the EBuild, otherwise None if none found. |
| 235 | """ |
| 236 | candidates = [] |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 237 | if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT, |
| 238 | constants.CHROME_REV_SPEC]: |
| 239 | # These are labelled alpha, for historic reasons, |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 240 | # not just for the fun of confusion. |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 241 | chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 242 | for ebuild in stable_ebuilds: |
| 243 | if chrome_branch_re.search(ebuild.version): |
| 244 | candidates.append(ebuild) |
| 245 | |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 246 | elif chrome_rev == constants.CHROME_REV_STICKY: |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 247 | assert sticky_branch is not None |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 248 | chrome_branch_re = re.compile(r'%s\..*' % sticky_branch) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 249 | for ebuild in stable_ebuilds: |
| 250 | if chrome_branch_re.search(ebuild.version): |
| 251 | candidates.append(ebuild) |
| 252 | |
| 253 | else: |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 254 | chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 255 | for ebuild in stable_ebuilds: |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 256 | if chrome_branch_re.search(ebuild.version): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 257 | candidates.append(ebuild) |
| 258 | |
| 259 | if candidates: |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 260 | return portage_utilities.BestEBuild(candidates) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 261 | else: |
| 262 | return None |
| 263 | |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 264 | def _AnnotateAndPrint(text, url): |
| 265 | """Add buildbot trappings to print <a href='url'>text</a> in the waterfall. |
| 266 | |
| 267 | Args: |
| 268 | text: Anchor text for the link |
| 269 | url: the URL to which to link |
| 270 | """ |
Don Garrett | e60de90 | 2011-10-17 18:52:05 -0700 | [diff] [blame] | 271 | print >> sys.stderr, '\n@@@STEP_LINK@%(text)s@%(url)s@@@' % { 'text': text, |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 272 | 'url': url } |
| 273 | |
| 274 | def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version): |
| 275 | """Return appropriately formatted link to revision info, given versions |
| 276 | |
| 277 | Given two chrome version strings (e.g. 9.0.533.0), generate a link to a |
| 278 | page that prints the Chromium revisions between those two versions. |
| 279 | |
| 280 | Args: |
| 281 | old_chrome_version: version to diff from |
| 282 | chrome_version: version to which to diff |
| 283 | Returns: |
| 284 | The desired URL. |
| 285 | """ |
| 286 | return _CHROME_VERSION_URL % { 'old': old_chrome_version, |
| 287 | 'new': chrome_version } |
| 288 | |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 289 | def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev): |
| 290 | """Returns a link to the list of revisions between two Chromium versions |
| 291 | |
| 292 | Given two ChromeEBuilds and the kind of rev we're doing, generate a |
| 293 | link to a page that prints the Chromium changes between those two |
| 294 | revisions, inclusive. |
| 295 | |
| 296 | Args: |
| 297 | old_chrome: ebuild for the version to diff from |
| 298 | new_chrome: ebuild for the version to which to diff |
| 299 | chrome_rev: one of constants.VALID_CHROME_REVISIONS |
| 300 | Returns: |
| 301 | The desired URL. |
| 302 | """ |
Chris Sosa | dd611df | 2012-02-03 15:26:23 -0800 | [diff] [blame] | 303 | assert chrome_rev in _REV_TYPES_FOR_LINKS |
| 304 | return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version, |
| 305 | new_chrome.chrome_version) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 306 | |
| 307 | def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev, |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 308 | chrome_version, commit, overlay_dir): |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 309 | r"""Uprevs the chrome ebuild specified by chrome_rev. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 310 | |
| 311 | This is the main function that uprevs the chrome_rev from a stable candidate |
| 312 | to its new version. |
| 313 | |
| 314 | Args: |
| 315 | stable_candidate: ebuild that corresponds to the stable ebuild we are |
| 316 | revving from. If None, builds the a new ebuild given the version |
| 317 | and logic for chrome_rev type with revision set to 1. |
| 318 | unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome. |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 319 | chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 320 | constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for |
| 321 | the specified version and uses the portage suffix of _alpha. |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 322 | constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for |
| 323 | the TOT version and uses the portage suffix of _alpha. |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 324 | constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for |
| 325 | the local version and uses the portage suffix of _alpha. |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 326 | constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they |
| 327 | are release candidates for the next sticky version. |
| 328 | constants.CHROME_REV_STICKY - Revs the sticky version. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 329 | chrome_version: The \d.\d.\d.\d version of Chrome. |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 330 | commit: Used with constants.CHROME_REV_TOT. The svn revision of chrome. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 331 | overlay_dir: Path to the chromeos-chrome package dir. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 332 | Returns: |
| 333 | Full portage version atom (including rc's, etc) that was revved. |
| 334 | """ |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 335 | def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild): |
| 336 | """Returns True if the new ebuild is redundant. |
| 337 | |
| 338 | This is True if there if the current stable ebuild is the exact same copy |
David James | 89608f9 | 2012-11-03 14:14:12 -0700 | [diff] [blame] | 339 | of the new one. |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 340 | """ |
| 341 | if not stable_ebuild: |
| 342 | return False |
| 343 | |
| 344 | if stable_candidate.chrome_version == new_ebuild.chrome_version: |
David James | 89608f9 | 2012-11-03 14:14:12 -0700 | [diff] [blame] | 345 | return filecmp.cmp( |
| 346 | new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False) |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 347 | |
David James | 629febb | 2012-11-25 13:07:34 -0800 | [diff] [blame] | 348 | # Mark latest release and sticky branches as stable. |
| 349 | mark_stable = chrome_rev not in [constants.CHROME_REV_TOT, |
| 350 | constants.CHROME_REV_SPEC, |
| 351 | constants.CHROME_REV_LOCAL] |
| 352 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 353 | # Case where we have the last stable candidate with same version just rev. |
| 354 | if stable_candidate and stable_candidate.chrome_version == chrome_version: |
| 355 | new_ebuild_path = '%s-r%d.ebuild' % ( |
| 356 | stable_candidate.ebuild_path_no_revision, |
| 357 | stable_candidate.current_revision + 1) |
| 358 | else: |
David James | 629febb | 2012-11-25 13:07:34 -0800 | [diff] [blame] | 359 | suffix = 'rc' if mark_stable else 'alpha' |
| 360 | pf = '%s-%s_%s-r1' % (constants.CHROME_PN, chrome_version, suffix) |
| 361 | new_ebuild_path = os.path.join(overlay_dir, '%s.ebuild' % pf) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 362 | |
David James | a679255 | 2012-04-03 10:05:35 -0700 | [diff] [blame] | 363 | chrome_variables = dict() |
| 364 | if commit: |
| 365 | chrome_variables[_CHROME_SVN_TAG] = commit |
| 366 | |
J. Richard Barnette | 0cfc505 | 2011-11-28 14:31:39 -0800 | [diff] [blame] | 367 | portage_utilities.EBuild.MarkAsStable( |
David James | 065b201 | 2012-04-01 14:51:11 -0700 | [diff] [blame] | 368 | unstable_ebuild.ebuild_path, new_ebuild_path, |
David James | a679255 | 2012-04-03 10:05:35 -0700 | [diff] [blame] | 369 | chrome_variables, make_stable=mark_stable) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 370 | new_ebuild = ChromeEBuild(new_ebuild_path) |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 371 | |
| 372 | # Determine whether this is ebuild is redundant. |
| 373 | if IsTheNewEBuildRedundant(new_ebuild, stable_candidate): |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 374 | msg = 'Previous ebuild with same version found and ebuild is redundant.' |
| 375 | cros_build_lib.Info(msg) |
Chris Sosa | 8be3913 | 2011-04-14 12:09:24 -0700 | [diff] [blame] | 376 | os.unlink(new_ebuild_path) |
| 377 | return None |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 378 | |
Chris Sosa | dd611df | 2012-02-03 15:26:23 -0800 | [diff] [blame] | 379 | if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS: |
Chris Masone | 592cab5 | 2011-08-02 14:05:48 -0700 | [diff] [blame] | 380 | _AnnotateAndPrint('Chromium revisions', |
| 381 | GetChromeRevisionListLink(stable_candidate, |
| 382 | new_ebuild, |
| 383 | chrome_rev)) |
| 384 | |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 385 | cros_build_lib.RunCommand(['git', 'add', new_ebuild_path], cwd=overlay_dir) |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 386 | if stable_candidate and not stable_candidate.IsSticky(): |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 387 | cros_build_lib.RunCommand(['git', 'rm', stable_candidate.ebuild_path], |
| 388 | cwd=overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 389 | |
J. Richard Barnette | 0cfc505 | 2011-11-28 14:31:39 -0800 | [diff] [blame] | 390 | portage_utilities.EBuild.CommitChange( |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 391 | _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev, |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 392 | 'chrome_version': chrome_version}, |
| 393 | overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 394 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 395 | return '%s-%s' % (new_ebuild.package, new_ebuild.version) |
| 396 | |
| 397 | |
Chris Sosa | d53f8fd | 2011-10-21 15:15:19 -0700 | [diff] [blame] | 398 | def ParseMaxRevision(revision_list): |
| 399 | """Returns the max revision from a list of url@revision string.""" |
David James | 7c352bc | 2013-03-15 14:19:57 -0700 | [diff] [blame^] | 400 | revision_re = re.compile(r'.*@(\d+)') |
Chris Sosa | d53f8fd | 2011-10-21 15:15:19 -0700 | [diff] [blame] | 401 | |
| 402 | def RevisionKey(revision): |
| 403 | return revision_re.match(revision).group(1) |
| 404 | |
| 405 | max_revision = max(revision_list.split(), key=RevisionKey) |
| 406 | return max_revision.rpartition('@')[2] |
| 407 | |
| 408 | |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 409 | def main(_argv): |
Chris Sosa | 0f295aa | 2011-10-21 14:10:28 -0700 | [diff] [blame] | 410 | usage_options = '|'.join(constants.VALID_CHROME_REVISIONS) |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 411 | usage = '%s OPTIONS [%s]' % (__file__, usage_options) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 412 | parser = optparse.OptionParser(usage) |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 413 | parser.add_option('-b', '--boards', default='x86-generic') |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 414 | parser.add_option('-c', '--chrome_url', default=gclient.GetBaseURLs()[0]) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 415 | parser.add_option('-f', '--force_revision', default=None) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 416 | parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'], |
| 417 | 'trunk', 'src'), |
| 418 | help='Path to the src directory') |
| 419 | parser.add_option('-t', '--tracking_branch', default='cros/master', |
| 420 | help='Branch we are tracking changes against') |
| 421 | (options, args) = parser.parse_args() |
| 422 | |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 423 | if len(args) != 1 or args[0] not in constants.VALID_CHROME_REVISIONS: |
| 424 | parser.error('Commit requires arg set to one of %s.' |
| 425 | % constants.VALID_CHROME_REVISIONS) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 426 | |
| 427 | overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR % |
| 428 | {'srcroot': options.srcroot}) |
| 429 | chrome_rev = args[0] |
| 430 | version_to_uprev = None |
| 431 | commit_to_use = None |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 432 | sticky_branch = None |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 433 | |
| 434 | (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 435 | |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 436 | if chrome_rev == constants.CHROME_REV_LOCAL: |
| 437 | if 'CHROME_ROOT' in os.environ: |
| 438 | chrome_root = os.environ['CHROME_ROOT'] |
| 439 | else: |
| 440 | chrome_root = os.path.join(os.environ['HOME'], 'chrome_root') |
| 441 | |
| 442 | version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root) |
| 443 | commit_to_use = 'Unknown' |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 444 | cros_build_lib.Info('Using local source, versioning is untrustworthy.') |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 445 | elif chrome_rev == constants.CHROME_REV_SPEC: |
| 446 | commit_to_use = options.force_revision |
Chris Sosa | d53f8fd | 2011-10-21 15:15:19 -0700 | [diff] [blame] | 447 | if '@' in commit_to_use: commit_to_use = ParseMaxRevision(commit_to_use) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 448 | version_to_uprev = _GetSpecificVersionUrl(options.chrome_url, |
| 449 | commit_to_use) |
Peter Mayo | 177500f | 2011-09-09 17:25:23 -0400 | [diff] [blame] | 450 | elif chrome_rev == constants.CHROME_REV_TOT: |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 451 | commit_to_use = gclient.GetTipOfTrunkSvnRevision(options.chrome_url) |
petermayo@chromium.org | 163b337 | 2011-09-12 02:06:05 -0400 | [diff] [blame] | 452 | version_to_uprev = _GetSpecificVersionUrl(options.chrome_url, |
| 453 | commit_to_use) |
Ryan Cui | c6e097d | 2011-06-16 12:23:14 -0700 | [diff] [blame] | 454 | elif chrome_rev == constants.CHROME_REV_LATEST: |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 455 | version_to_uprev = _GetLatestRelease(options.chrome_url) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 456 | else: |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 457 | sticky_ebuild = _GetStickyEBuild(stable_ebuilds) |
| 458 | sticky_version = sticky_ebuild.chrome_version |
| 459 | sticky_branch = sticky_version.rpartition('.')[0] |
Peter Mayo | f65b841 | 2011-08-26 01:22:21 -0400 | [diff] [blame] | 460 | version_to_uprev = _GetLatestRelease(options.chrome_url, sticky_branch) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 461 | |
| 462 | stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev, |
| 463 | sticky_branch) |
| 464 | |
| 465 | if stable_candidate: |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 466 | cros_build_lib.Info('Stable candidate found %s' % stable_candidate) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 467 | else: |
David James | 1b36358 | 2012-12-17 11:53:11 -0800 | [diff] [blame] | 468 | cros_build_lib.Info('No stable candidate found.') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 469 | |
Chris Sosa | 8049f3b | 2011-05-02 20:09:28 -0700 | [diff] [blame] | 470 | tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch) |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 471 | existing_branch = git.GetCurrentBranch(overlay_dir) |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 472 | work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH, |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 473 | tracking_branch, overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 474 | work_branch.CreateBranch() |
David James | d6708c0 | 2012-03-22 10:49:15 -0700 | [diff] [blame] | 475 | |
| 476 | # In the case of uprevving overlays that have patches applied to them, |
| 477 | # include the patched changes in the stabilizing branch. |
| 478 | if existing_branch: |
ChromeOS Developer | 03118eb | 2013-02-12 14:27:09 -0800 | [diff] [blame] | 479 | cros_build_lib.RunCommand(['git', 'rebase', existing_branch], |
| 480 | cwd=overlay_dir) |
David James | d6708c0 | 2012-03-22 10:49:15 -0700 | [diff] [blame] | 481 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 482 | chrome_version_atom = MarkChromeEBuildAsStable( |
| 483 | stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev, |
Chris Sosa | 9ba4775 | 2012-02-27 15:27:37 -0800 | [diff] [blame] | 484 | commit_to_use, overlay_dir) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 485 | # Explicit print to communicate to caller. |
| 486 | if chrome_version_atom: |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 487 | cros_mark_as_stable.CleanStalePackages(options.boards.split(':'), |
| 488 | [chrome_version_atom]) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 489 | print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom |