blob: d2b1996cac60b23fdecd709d02a4bc918d2fec13 [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
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070017import base64
Mike Frysingera94f1252019-09-12 02:39:28 -040018import distutils.version # pylint: disable=import-error,no-name-in-module
Chris Sosa8be39132011-04-14 12:09:24 -070019import filecmp
Chris McDonaldb55b7032021-06-17 16:41:32 -060020import logging
Chris Sosadad0d322011-01-31 16:37:33 -080021import os
22import re
Mike Frysingere852b072021-05-21 12:39:03 -040023import urllib.parse
Chris Sosadad0d322011-01-31 16:37:33 -080024
Chris McDonaldb55b7032021-06-17 16:41:32 -060025from chromite.cbuildbot import cbuildbot_alerts
Mike Frysingera13c04f2016-09-01 00:35:17 -040026from chromite.lib import commandline
Chris McDonaldb55b7032021-06-17 16:41:32 -060027from chromite.lib import constants
David James1b363582012-12-17 11:53:11 -080028from chromite.lib import cros_build_lib
David James97d95872012-11-16 15:09:56 -080029from chromite.lib import git
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070030from chromite.lib import gob_util
Alex Deymo075c2292014-09-04 18:31:50 -070031from chromite.lib import portage_util
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070032from chromite.lib import timeout_util
Mike Frysinger6cb624a2012-05-24 18:17:38 -040033from chromite.scripts import cros_mark_as_stable
Chris Sosadad0d322011-01-31 16:37:33 -080034
Mike Frysinger807d8282022-04-28 22:45:17 -040035
Chris Sosadad0d322011-01-31 16:37:33 -080036# Helper regex's for finding ebuilds.
David James7c352bc2013-03-15 14:19:57 -070037_CHROME_VERSION_REGEX = r'\d+\.\d+\.\d+\.\d+'
38_NON_STICKY_REGEX = r'%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
Chris Sosadad0d322011-01-31 16:37:33 -080039
40# Dir where all the action happens.
David Zeuthen665d3132014-08-25 15:27:02 -040041_OVERLAY_DIR = '%(srcroot)s/third_party/chromiumos-overlay/'
Chris Sosadad0d322011-01-31 16:37:33 -080042
David Zeuthen665d3132014-08-25 15:27:02 -040043_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for %(chrome_pn)s ebuild '
44 'with version %(chrome_version)s as stable.')
Chris Sosadad0d322011-01-31 16:37:33 -080045
Chris Masone592cab52011-08-02 14:05:48 -070046# URLs that print lists of chrome revisions between two versions of the browser.
47_CHROME_VERSION_URL = ('http://omahaproxy.appspot.com/changelog?'
48 'old_version=%(old)s&new_version=%(new)s')
Chris Sosadd611df2012-02-03 15:26:23 -080049
50# Only print links when we rev these types.
51_REV_TYPES_FOR_LINKS = [constants.CHROME_REV_LATEST,
52 constants.CHROME_REV_STICKY]
Chris Masone592cab52011-08-02 14:05:48 -070053
ChromeOS Developer03118eb2013-02-12 14:27:09 -080054
petermayo@chromium.org163b3372011-09-12 02:06:05 -040055def _GetVersionContents(chrome_version_info):
Peter Mayo177500f2011-09-09 17:25:23 -040056 """Returns the current Chromium version, from the contents of a VERSION file.
Chris Sosadad0d322011-01-31 16:37:33 -080057
Peter Mayo177500f2011-09-09 17:25:23 -040058 Args:
Mike Frysinger6f3c48e2015-05-06 02:38:51 -040059 chrome_version_info: The contents of a chromium VERSION file.
Peter Mayo177500f2011-09-09 17:25:23 -040060 """
Chris Sosadad0d322011-01-31 16:37:33 -080061 chrome_version_array = []
Chris Sosadad0d322011-01-31 16:37:33 -080062 for line in chrome_version_info.splitlines():
63 chrome_version_array.append(line.rpartition('=')[2])
64
65 return '.'.join(chrome_version_array)
66
Mike Frysingercc838832014-05-24 13:10:30 -040067
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070068def _GetSpecificVersionUrl(git_url, revision, time_to_wait=600):
petermayo@chromium.org163b3372011-09-12 02:06:05 -040069 """Returns the Chromium version, from a repository URL and version.
Peter Mayo177500f2011-09-09 17:25:23 -040070
71 Args:
Mike Frysinger6f3c48e2015-05-06 02:38:51 -040072 git_url: Repository URL for chromium.
73 revision: the git revision we want to use.
74 time_to_wait: the minimum period before abandoning our wait for the
75 desired revision to be present.
Peter Mayo177500f2011-09-09 17:25:23 -040076 """
Mike Frysinger3dcacee2019-08-23 17:09:11 -040077 parsed_url = urllib.parse.urlparse(git_url)
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070078 host = parsed_url[1]
79 path = parsed_url[2].rstrip('/') + (
80 '/+/%s/chrome/VERSION?format=text' % revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040081
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070082 # Allow for git repository replication lag with sleep/retry loop.
83 def _fetch():
Jack Rosenthal61e67832019-09-16 12:48:38 -060084 return gob_util.FetchUrl(host, path, ignore_404=True)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040085
Mike Frysingercc55c782014-12-03 22:32:08 -050086 def _wait_msg(_remaining):
Ralph Nathan03047282015-03-23 11:09:32 -070087 logging.info('Repository does not yet have revision %s. Sleeping...',
88 revision)
petermayo@chromium.org163b3372011-09-12 02:06:05 -040089
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070090 content = timeout_util.WaitForSuccess(
91 retry_check=lambda x: not bool(x),
92 func=_fetch,
93 timeout=time_to_wait,
94 period=30,
95 side_effect_func=_wait_msg)
Jack Rosenthal61e67832019-09-16 12:48:38 -060096 return _GetVersionContents(base64.b64decode(content).decode('utf-8'))
petermayo@chromium.org163b3372011-09-12 02:06:05 -040097
Peter Mayo177500f2011-09-09 17:25:23 -040098
99def _GetTipOfTrunkVersionFile(root):
100 """Returns the current Chromium version, from a file in a checkout.
101
102 Args:
Mike Frysinger6f3c48e2015-05-06 02:38:51 -0400103 root: path to the root of the chromium checkout.
Peter Mayo177500f2011-09-09 17:25:23 -0400104 """
105 version_file = os.path.join(root, 'src', 'chrome', 'VERSION')
Mike Frysinger94a459c2019-09-29 23:43:05 -0400106 try:
107 chrome_version_info = cros_build_lib.run(
108 ['cat', version_file],
Mike Frysinger0282d222019-12-17 17:15:48 -0500109 stdout=True).stdout
Mike Frysinger94a459c2019-09-29 23:43:05 -0400110 except cros_build_lib.RunCommandError as e:
111 e.msg += '\nCould not read version file at %s.' % version_file
112 raise e
Peter Mayo177500f2011-09-09 17:25:23 -0400113
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400114 return _GetVersionContents(chrome_version_info)
Peter Mayo177500f2011-09-09 17:25:23 -0400115
ChromeOS Developer03118eb2013-02-12 14:27:09 -0800116
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700117def CheckIfChromeRightForOS(deps_content):
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700118 """Checks if DEPS is right for Chrome OS.
119
120 This function checks for a variable called 'buildspec_platforms' to
121 find out if its 'chromeos' or 'all'. If any of those values,
122 then it chooses that DEPS.
123
124 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700125 deps_content: Content of release buildspec DEPS file.
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700126
127 Returns:
128 True if DEPS is the right Chrome for Chrome OS.
129 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700130 platforms_search = re.search(r'buildspec_platforms.*\s.*\s', deps_content)
Dharani Govindancbbf69c2014-07-29 15:37:39 -0700131
132 if platforms_search:
133 platforms = platforms_search.group()
134 if 'chromeos' in platforms or 'all' in platforms:
135 return True
Dharani Govindan4beb94c2014-07-18 13:31:47 -0700136
137 return False
138
139
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700140def GetLatestRelease(git_url, branch=None):
141 """Gets the latest release version from the release tags in the repository.
Chris Sosadad0d322011-01-31 16:37:33 -0800142
143 Args:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700144 git_url: URL of git repository.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500145 branch: If set, gets the latest release for branch, otherwise latest
Chris Sosadad0d322011-01-31 16:37:33 -0800146 release.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500147
Chris Sosadad0d322011-01-31 16:37:33 -0800148 Returns:
149 Latest version string.
150 """
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700151 # TODO(szager): This only works for public release buildspecs in the chromium
152 # src repository. Internal buildspecs are tracked differently. At the time
153 # of writing, I can't find any callers that use this method to scan for
154 # internal buildspecs. But there may be something lurking...
155
Mike Frysinger3dcacee2019-08-23 17:09:11 -0400156 parsed_url = urllib.parse.urlparse(git_url)
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700157 path = parsed_url[2].rstrip('/') + '/+refs/tags?format=JSON'
158 j = gob_util.FetchUrlJson(parsed_url[1], path, ignore_404=False)
Chris Sosadad0d322011-01-31 16:37:33 -0800159 if branch:
David James7c352bc2013-03-15 14:19:57 -0700160 chrome_version_re = re.compile(r'^%s\.\d+.*' % branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800161 else:
David James7c352bc2013-03-15 14:19:57 -0700162 chrome_version_re = re.compile(r'^[0-9]+\..*')
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700163 matching_versions = [key for key in j.keys() if chrome_version_re.match(key)]
164 matching_versions.sort(key=distutils.version.LooseVersion)
165 for chrome_version in reversed(matching_versions):
166 path = parsed_url[2].rstrip() + (
167 '/+/refs/tags/%s/DEPS?format=text' % chrome_version)
Jack Rosenthal61e67832019-09-16 12:48:38 -0600168 content = gob_util.FetchUrl(parsed_url[1], path, ignore_404=False)
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700169 if content:
Jack Rosenthal61e67832019-09-16 12:48:38 -0600170 deps_content = base64.b64decode(content).decode('utf-8')
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700171 if CheckIfChromeRightForOS(deps_content):
172 return chrome_version
Peter Mayoad8173d2011-11-08 16:18:23 -0500173
174 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800175
176
177def _GetStickyEBuild(stable_ebuilds):
178 """Returns the sticky ebuild."""
179 sticky_ebuilds = []
180 non_sticky_re = re.compile(_NON_STICKY_REGEX)
181 for ebuild in stable_ebuilds:
182 if not non_sticky_re.match(ebuild.version):
183 sticky_ebuilds.append(ebuild)
184
185 if not sticky_ebuilds:
186 raise Exception('No sticky ebuilds found')
187 elif len(sticky_ebuilds) > 1:
Mike Frysinger6c2a6242019-03-20 20:37:24 -0400188 logging.warning('More than one sticky ebuild found:')
189 for ebuild in sticky_ebuilds:
190 logging.warning(' %s', ebuild.ebuild_path)
191 logging.warning('Make sure to *not* create xxx.0-r1.ebuilds')
Chris Sosadad0d322011-01-31 16:37:33 -0800192
Alex Deymo075c2292014-09-04 18:31:50 -0700193 return portage_util.BestEBuild(sticky_ebuilds)
Chris Sosadad0d322011-01-31 16:37:33 -0800194
195
Alex Deymo075c2292014-09-04 18:31:50 -0700196class ChromeEBuild(portage_util.EBuild):
Chris Sosadad0d322011-01-31 16:37:33 -0800197 """Thin sub-class of EBuild that adds a chrome_version field."""
David Zeuthen665d3132014-08-25 15:27:02 -0400198 chrome_version_re = re.compile(r'.*-(%s|9999).*' % (
199 _CHROME_VERSION_REGEX))
Chris Sosadad0d322011-01-31 16:37:33 -0800200 chrome_version = ''
201
202 def __init__(self, path):
Alex Deymo075c2292014-09-04 18:31:50 -0700203 portage_util.EBuild.__init__(self, path)
Chris Sosadad0d322011-01-31 16:37:33 -0800204 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
205 if re_match:
206 self.chrome_version = re_match.group(1)
207
Chris Sosadad0d322011-01-31 16:37:33 -0800208 def __str__(self):
209 return self.ebuild_path
210
211
David Zeuthen665d3132014-08-25 15:27:02 -0400212def FindChromeCandidates(package_dir):
Chris Sosadad0d322011-01-31 16:37:33 -0800213 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
214
215 Args:
David Zeuthen665d3132014-08-25 15:27:02 -0400216 package_dir: The path to where the package ebuild is stored.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500217
Chris Sosadad0d322011-01-31 16:37:33 -0800218 Returns:
219 Tuple [unstable_ebuild, stable_ebuilds].
Mike Frysinger1a736a82013-12-12 01:50:59 -0500220
Chris Sosadad0d322011-01-31 16:37:33 -0800221 Raises:
222 Exception: if no unstable ebuild exists for Chrome.
223 """
224 stable_ebuilds = []
225 unstable_ebuilds = []
226 for path in [
David Zeuthen665d3132014-08-25 15:27:02 -0400227 os.path.join(package_dir, entry) for entry in os.listdir(package_dir)]:
Chris Sosadad0d322011-01-31 16:37:33 -0800228 if path.endswith('.ebuild'):
229 ebuild = ChromeEBuild(path)
230 if not ebuild.chrome_version:
Lann Martinffb95162018-08-28 12:02:54 -0600231 logging.warning('Poorly formatted ebuild found at %s', path)
Chris Sosadad0d322011-01-31 16:37:33 -0800232 else:
233 if '9999' in ebuild.version:
234 unstable_ebuilds.append(ebuild)
235 else:
236 stable_ebuilds.append(ebuild)
237
Sloan Johnsonc59e9262022-06-10 20:51:53 +0000238 # Apply some confidence checks.
Chris Sosadad0d322011-01-31 16:37:33 -0800239 if not unstable_ebuilds:
David Zeuthen665d3132014-08-25 15:27:02 -0400240 raise Exception('Missing 9999 ebuild for %s' % package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800241 if not stable_ebuilds:
Lann Martinffb95162018-08-28 12:02:54 -0600242 logging.warning('Missing stable ebuild for %s', package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800243
Alex Deymo075c2292014-09-04 18:31:50 -0700244 return portage_util.BestEBuild(unstable_ebuilds), stable_ebuilds
Chris Sosadad0d322011-01-31 16:37:33 -0800245
246
247def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
248 """Finds the Chrome uprev candidate for the given chrome_rev.
249
250 Using the pre-flight logic, this means the stable ebuild you are uprevving
251 from. The difference here is that the version could be different and in
252 that case we want to find it to delete it.
253
254 Args:
255 stable_ebuilds: A list of stable ebuilds.
256 chrome_rev: The chrome_rev designating which candidate to find.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500257 sticky_branch: The the branch that is currently sticky with Major/Minor
Chris Sosa9ba47752012-02-27 15:27:37 -0800258 components. For example: 9.0.553. Can be None but not if chrome_rev
259 is CHROME_REV_STICKY.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500260
Chris Sosadad0d322011-01-31 16:37:33 -0800261 Returns:
Mike Frysinger1a736a82013-12-12 01:50:59 -0500262 The EBuild, otherwise None if none found.
Chris Sosadad0d322011-01-31 16:37:33 -0800263 """
264 candidates = []
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400265 if chrome_rev in [constants.CHROME_REV_LOCAL, constants.CHROME_REV_TOT,
266 constants.CHROME_REV_SPEC]:
267 # These are labelled alpha, for historic reasons,
Peter Mayo177500f2011-09-09 17:25:23 -0400268 # not just for the fun of confusion.
David James7c352bc2013-03-15 14:19:57 -0700269 chrome_branch_re = re.compile(r'%s.*_alpha.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800270 for ebuild in stable_ebuilds:
271 if chrome_branch_re.search(ebuild.version):
272 candidates.append(ebuild)
273
Ryan Cuic6e097d2011-06-16 12:23:14 -0700274 elif chrome_rev == constants.CHROME_REV_STICKY:
Chris Sosa9ba47752012-02-27 15:27:37 -0800275 assert sticky_branch is not None
David James7c352bc2013-03-15 14:19:57 -0700276 chrome_branch_re = re.compile(r'%s\..*' % sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800277 for ebuild in stable_ebuilds:
278 if chrome_branch_re.search(ebuild.version):
279 candidates.append(ebuild)
280
281 else:
David James7c352bc2013-03-15 14:19:57 -0700282 chrome_branch_re = re.compile(r'%s.*_rc.*' % _CHROME_VERSION_REGEX)
Chris Sosadad0d322011-01-31 16:37:33 -0800283 for ebuild in stable_ebuilds:
Chris Sosa9ba47752012-02-27 15:27:37 -0800284 if chrome_branch_re.search(ebuild.version):
Chris Sosadad0d322011-01-31 16:37:33 -0800285 candidates.append(ebuild)
286
287 if candidates:
Alex Deymo075c2292014-09-04 18:31:50 -0700288 return portage_util.BestEBuild(candidates)
Chris Sosadad0d322011-01-31 16:37:33 -0800289 else:
290 return None
291
Mike Frysingercc838832014-05-24 13:10:30 -0400292
Chris Masone592cab52011-08-02 14:05:48 -0700293def GetChromeRevisionLinkFromVersions(old_chrome_version, chrome_version):
294 """Return appropriately formatted link to revision info, given versions
295
296 Given two chrome version strings (e.g. 9.0.533.0), generate a link to a
297 page that prints the Chromium revisions between those two versions.
298
299 Args:
300 old_chrome_version: version to diff from
301 chrome_version: version to which to diff
Mike Frysinger1a736a82013-12-12 01:50:59 -0500302
Chris Masone592cab52011-08-02 14:05:48 -0700303 Returns:
304 The desired URL.
305 """
Mike Frysingerd6e2df02014-11-26 02:55:04 -0500306 return _CHROME_VERSION_URL % {'old': old_chrome_version,
307 'new': chrome_version}
Chris Masone592cab52011-08-02 14:05:48 -0700308
Mike Frysinger750c5f52014-09-16 16:16:57 -0400309
Chris Masone592cab52011-08-02 14:05:48 -0700310def GetChromeRevisionListLink(old_chrome, new_chrome, chrome_rev):
311 """Returns a link to the list of revisions between two Chromium versions
312
313 Given two ChromeEBuilds and the kind of rev we're doing, generate a
314 link to a page that prints the Chromium changes between those two
315 revisions, inclusive.
316
317 Args:
318 old_chrome: ebuild for the version to diff from
319 new_chrome: ebuild for the version to which to diff
320 chrome_rev: one of constants.VALID_CHROME_REVISIONS
Mike Frysinger1a736a82013-12-12 01:50:59 -0500321
Chris Masone592cab52011-08-02 14:05:48 -0700322 Returns:
323 The desired URL.
324 """
Chris Sosadd611df2012-02-03 15:26:23 -0800325 assert chrome_rev in _REV_TYPES_FOR_LINKS
326 return GetChromeRevisionLinkFromVersions(old_chrome.chrome_version,
327 new_chrome.chrome_version)
Chris Sosadad0d322011-01-31 16:37:33 -0800328
Mike Frysingercc838832014-05-24 13:10:30 -0400329
David Zeuthen665d3132014-08-25 15:27:02 -0400330def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_pn,
Mike Frysinger93ad2262018-08-30 18:42:14 -0400331 chrome_rev, chrome_version, package_dir):
David James7c352bc2013-03-15 14:19:57 -0700332 r"""Uprevs the chrome ebuild specified by chrome_rev.
Chris Sosadad0d322011-01-31 16:37:33 -0800333
334 This is the main function that uprevs the chrome_rev from a stable candidate
335 to its new version.
336
337 Args:
338 stable_candidate: ebuild that corresponds to the stable ebuild we are
339 revving from. If None, builds the a new ebuild given the version
340 and logic for chrome_rev type with revision set to 1.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500341 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
David Zeuthen665d3132014-08-25 15:27:02 -0400342 chrome_pn: package name.
Peter Mayo177500f2011-09-09 17:25:23 -0400343 chrome_rev: one of constants.VALID_CHROME_REVISIONS or LOCAL
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400344 constants.CHROME_REV_SPEC - Requires commit value. Revs the ebuild for
345 the specified version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700346 constants.CHROME_REV_TOT - Requires commit value. Revs the ebuild for
347 the TOT version and uses the portage suffix of _alpha.
Peter Mayo177500f2011-09-09 17:25:23 -0400348 constants.CHROME_REV_LOCAL - Requires a chrome_root. Revs the ebuild for
349 the local version and uses the portage suffix of _alpha.
Ryan Cuic6e097d2011-06-16 12:23:14 -0700350 constants.CHROME_REV_LATEST - This uses the portage suffix of _rc as they
351 are release candidates for the next sticky version.
352 constants.CHROME_REV_STICKY - Revs the sticky version.
Mike Frysingerad8c6ca2014-02-03 11:28:45 -0500353 chrome_version: The \d.\d.\d.\d version of Chrome.
David Zeuthen665d3132014-08-25 15:27:02 -0400354 package_dir: Path to the chromeos-chrome package dir.
Mike Frysinger1a736a82013-12-12 01:50:59 -0500355
Chris Sosadad0d322011-01-31 16:37:33 -0800356 Returns:
357 Full portage version atom (including rc's, etc) that was revved.
358 """
Chris Sosa8be39132011-04-14 12:09:24 -0700359 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
360 """Returns True if the new ebuild is redundant.
361
362 This is True if there if the current stable ebuild is the exact same copy
David James89608f92012-11-03 14:14:12 -0700363 of the new one.
Chris Sosa8be39132011-04-14 12:09:24 -0700364 """
365 if not stable_ebuild:
366 return False
367
368 if stable_candidate.chrome_version == new_ebuild.chrome_version:
David James89608f92012-11-03 14:14:12 -0700369 return filecmp.cmp(
370 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
Chris Sosa8be39132011-04-14 12:09:24 -0700371
David James629febb2012-11-25 13:07:34 -0800372 # Mark latest release and sticky branches as stable.
373 mark_stable = chrome_rev not in [constants.CHROME_REV_TOT,
374 constants.CHROME_REV_SPEC,
375 constants.CHROME_REV_LOCAL]
376
Chris Sosadad0d322011-01-31 16:37:33 -0800377 # Case where we have the last stable candidate with same version just rev.
378 if stable_candidate and stable_candidate.chrome_version == chrome_version:
379 new_ebuild_path = '%s-r%d.ebuild' % (
380 stable_candidate.ebuild_path_no_revision,
381 stable_candidate.current_revision + 1)
382 else:
David James629febb2012-11-25 13:07:34 -0800383 suffix = 'rc' if mark_stable else 'alpha'
David Zeuthen665d3132014-08-25 15:27:02 -0400384 pf = '%s-%s_%s-r1' % (chrome_pn, chrome_version, suffix)
385 new_ebuild_path = os.path.join(package_dir, '%s.ebuild' % pf)
Chris Sosadad0d322011-01-31 16:37:33 -0800386
Alex Deymo075c2292014-09-04 18:31:50 -0700387 portage_util.EBuild.MarkAsStable(
David James065b2012012-04-01 14:51:11 -0700388 unstable_ebuild.ebuild_path, new_ebuild_path,
Mike Frysinger93ad2262018-08-30 18:42:14 -0400389 {}, make_stable=mark_stable)
Chris Sosadad0d322011-01-31 16:37:33 -0800390 new_ebuild = ChromeEBuild(new_ebuild_path)
Chris Sosa8be39132011-04-14 12:09:24 -0700391
392 # Determine whether this is ebuild is redundant.
393 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
David James1b363582012-12-17 11:53:11 -0800394 msg = 'Previous ebuild with same version found and ebuild is redundant.'
Ralph Nathan03047282015-03-23 11:09:32 -0700395 logging.info(msg)
Chris Sosa8be39132011-04-14 12:09:24 -0700396 os.unlink(new_ebuild_path)
397 return None
Chris Sosadad0d322011-01-31 16:37:33 -0800398
Chris Sosadd611df2012-02-03 15:26:23 -0800399 if stable_candidate and chrome_rev in _REV_TYPES_FOR_LINKS:
Chris McDonaldb55b7032021-06-17 16:41:32 -0600400 cbuildbot_alerts.PrintBuildbotLink('Chromium revisions',
Sloan Johnsonc59e9262022-06-10 20:51:53 +0000401 GetChromeRevisionListLink(
402 stable_candidate, new_ebuild,
403 chrome_rev))
Chris Masone592cab52011-08-02 14:05:48 -0700404
David Zeuthen665d3132014-08-25 15:27:02 -0400405 git.RunGit(package_dir, ['add', new_ebuild_path])
Chris Sosa9ba47752012-02-27 15:27:37 -0800406 if stable_candidate and not stable_candidate.IsSticky():
David Zeuthen665d3132014-08-25 15:27:02 -0400407 git.RunGit(package_dir, ['rm', stable_candidate.ebuild_path])
Chris Sosadad0d322011-01-31 16:37:33 -0800408
Alex Deymo075c2292014-09-04 18:31:50 -0700409 portage_util.EBuild.CommitChange(
David Zeuthen665d3132014-08-25 15:27:02 -0400410 _GIT_COMMIT_MESSAGE % {'chrome_pn': chrome_pn,
411 'chrome_rev': chrome_rev,
Mike Frysinger2ebe3732012-05-08 17:04:12 -0400412 'chrome_version': chrome_version},
David Zeuthen665d3132014-08-25 15:27:02 -0400413 package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800414
Chris Sosadad0d322011-01-31 16:37:33 -0800415 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
416
417
Mike Frysingera13c04f2016-09-01 00:35:17 -0400418def GetParser():
419 """Return a command line parser."""
420 parser = commandline.ArgumentParser(description=__doc__)
421 parser.add_argument('-b', '--boards')
422 parser.add_argument('-c', '--chrome_url',
423 default=constants.CHROMIUM_GOB_URL)
424 parser.add_argument('-f', '--force_version',
425 help='Chrome version or git revision hash to use')
426 parser.add_argument('-s', '--srcroot',
427 default=os.path.join(os.environ['HOME'], 'trunk', 'src'),
428 help='Path to the src directory')
429 parser.add_argument('-t', '--tracking_branch', default='cros/master',
430 help='Branch we are tracking changes against')
431 parser.add_argument('revision', choices=constants.VALID_CHROME_REVISIONS)
432 return parser
Chris Sosadad0d322011-01-31 16:37:33 -0800433
Chris Sosadad0d322011-01-31 16:37:33 -0800434
Mike Frysingera13c04f2016-09-01 00:35:17 -0400435def main(argv):
436 parser = GetParser()
437 options = parser.parse_args(argv)
438 options.Freeze()
439 chrome_rev = options.revision
440
441 if options.force_version and chrome_rev not in (constants.CHROME_REV_SPEC,
442 constants.CHROME_REV_LATEST):
David Jamesfb160012014-07-01 10:00:57 -0700443 parser.error('--force_version is not compatible with the %r '
Mike Frysingera13c04f2016-09-01 00:35:17 -0400444 'option.' % (chrome_rev,))
David Jamesfb160012014-07-01 10:00:57 -0700445
David Zeuthen665d3132014-08-25 15:27:02 -0400446 overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
447 chrome_package_dir = os.path.join(overlay_dir, constants.CHROME_CP)
Chris Sosadad0d322011-01-31 16:37:33 -0800448 version_to_uprev = None
Chris Sosa9ba47752012-02-27 15:27:37 -0800449 sticky_branch = None
Chris Sosadad0d322011-01-31 16:37:33 -0800450
David Zeuthen665d3132014-08-25 15:27:02 -0400451 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(chrome_package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800452
Peter Mayo177500f2011-09-09 17:25:23 -0400453 if chrome_rev == constants.CHROME_REV_LOCAL:
454 if 'CHROME_ROOT' in os.environ:
455 chrome_root = os.environ['CHROME_ROOT']
456 else:
457 chrome_root = os.path.join(os.environ['HOME'], 'chrome_root')
458
459 version_to_uprev = _GetTipOfTrunkVersionFile(chrome_root)
Ralph Nathan03047282015-03-23 11:09:32 -0700460 logging.info('Using local source, versioning is untrustworthy.')
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400461 elif chrome_rev == constants.CHROME_REV_SPEC:
David Jamesfb160012014-07-01 10:00:57 -0700462 if '.' in options.force_version:
463 version_to_uprev = options.force_version
464 else:
465 commit_to_use = options.force_version
466 if '@' in commit_to_use:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700467 commit_to_use = commit_to_use.rpartition('@')[2]
David Jamesfb160012014-07-01 10:00:57 -0700468 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
469 commit_to_use)
Peter Mayo177500f2011-09-09 17:25:23 -0400470 elif chrome_rev == constants.CHROME_REV_TOT:
Stefan Zagerd49d9ff2014-08-15 21:33:37 -0700471 commit_to_use = gob_util.GetTipOfTrunkRevision(options.chrome_url)
petermayo@chromium.org163b3372011-09-12 02:06:05 -0400472 version_to_uprev = _GetSpecificVersionUrl(options.chrome_url,
473 commit_to_use)
Ryan Cuic6e097d2011-06-16 12:23:14 -0700474 elif chrome_rev == constants.CHROME_REV_LATEST:
David James9a5980e2014-07-16 09:37:00 -0700475 if options.force_version:
476 if '.' not in options.force_version:
477 parser.error('%s only accepts released Chrome versions, not SVN or '
478 'Git revisions.' % (chrome_rev,))
479 version_to_uprev = options.force_version
480 else:
481 version_to_uprev = GetLatestRelease(options.chrome_url)
Chris Sosadad0d322011-01-31 16:37:33 -0800482 else:
Chris Sosa9ba47752012-02-27 15:27:37 -0800483 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
484 sticky_version = sticky_ebuild.chrome_version
485 sticky_branch = sticky_version.rpartition('.')[0]
Yu-Ju Hong39806322014-06-24 16:46:32 -0700486 version_to_uprev = GetLatestRelease(options.chrome_url, sticky_branch)
Chris Sosadad0d322011-01-31 16:37:33 -0800487
488 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
489 sticky_branch)
490
491 if stable_candidate:
Lann Martinffb95162018-08-28 12:02:54 -0600492 logging.info('Stable candidate found %s', stable_candidate)
Chris Sosadad0d322011-01-31 16:37:33 -0800493 else:
Ralph Nathan03047282015-03-23 11:09:32 -0700494 logging.info('No stable candidate found.')
Chris Sosadad0d322011-01-31 16:37:33 -0800495
Chris Sosa8049f3b2011-05-02 20:09:28 -0700496 tracking_branch = 'remotes/m/%s' % os.path.basename(options.tracking_branch)
David Zeuthen665d3132014-08-25 15:27:02 -0400497 existing_branch = git.GetCurrentBranch(chrome_package_dir)
Ryan Cui05a31ba2011-05-31 17:47:37 -0700498 work_branch = cros_mark_as_stable.GitBranch(constants.STABLE_EBUILD_BRANCH,
David Zeuthen665d3132014-08-25 15:27:02 -0400499 tracking_branch,
500 chrome_package_dir)
Chris Sosadad0d322011-01-31 16:37:33 -0800501 work_branch.CreateBranch()
David Jamesd6708c02012-03-22 10:49:15 -0700502
503 # In the case of uprevving overlays that have patches applied to them,
504 # include the patched changes in the stabilizing branch.
505 if existing_branch:
David Zeuthen665d3132014-08-25 15:27:02 -0400506 git.RunGit(chrome_package_dir, ['rebase', existing_branch])
David Jamesd6708c02012-03-22 10:49:15 -0700507
Chris Sosadad0d322011-01-31 16:37:33 -0800508 chrome_version_atom = MarkChromeEBuildAsStable(
David Zeuthen665d3132014-08-25 15:27:02 -0400509 stable_candidate, unstable_ebuild, 'chromeos-chrome', chrome_rev,
Mike Frysinger93ad2262018-08-30 18:42:14 -0400510 version_to_uprev, chrome_package_dir)
Yu-Ju Hong078c9ec2014-08-06 18:25:16 -0700511 if chrome_version_atom:
512 if options.boards:
David James96c2c992015-07-14 10:21:50 -0700513 cros_mark_as_stable.CleanStalePackages(options.srcroot,
514 options.boards.split(':'),
Yu-Ju Hong078c9ec2014-08-06 18:25:16 -0700515 [chrome_version_atom])
David Zeuthen665d3132014-08-25 15:27:02 -0400516
517 # If we did rev Chrome, now is a good time to uprev other packages.
518 for other_ebuild in constants.OTHER_CHROME_PACKAGES:
519 other_ebuild_name = os.path.basename(other_ebuild)
520 other_package_dir = os.path.join(overlay_dir, other_ebuild)
521 (other_unstable_ebuild, other_stable_ebuilds) = FindChromeCandidates(
522 other_package_dir)
523 other_stable_candidate = FindChromeUprevCandidate(other_stable_ebuilds,
524 chrome_rev,
525 sticky_branch)
526 revved_atom = MarkChromeEBuildAsStable(other_stable_candidate,
527 other_unstable_ebuild,
528 other_ebuild_name,
529 chrome_rev, version_to_uprev,
Mike Frysinger93ad2262018-08-30 18:42:14 -0400530 other_package_dir)
David Zeuthen665d3132014-08-25 15:27:02 -0400531 if revved_atom and options.boards:
David James96c2c992015-07-14 10:21:50 -0700532 cros_mark_as_stable.CleanStalePackages(options.srcroot,
533 options.boards.split(':'),
David Zeuthen665d3132014-08-25 15:27:02 -0400534 [revved_atom])
535
536 # Explicit print to communicate to caller.
537 if chrome_version_atom:
Mike Frysinger383367e2014-09-16 15:06:17 -0400538 print('CHROME_VERSION_ATOM=%s' % chrome_version_atom)