Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Side by Side Diff: bin/cros_mark_chrome_as_stable.py

Issue 6286040: Remove buildbot code that has been added to chromite. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Verify Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/cros_mark_chrome_as_stable ('k') | bin/cros_mark_chrome_as_stable_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
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
19 import optparse
20 import os
21 import re
22 import sys
23 import urllib
24
25 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
26 import cros_mark_as_stable
27
28 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
29 from cros_build_lib import RunCommand, Info, Warning
30
31 BASE_CHROME_SVN_URL = 'http://src.chromium.org/svn'
32
33 # Command for which chrome ebuild to uprev.
34 TIP_OF_TRUNK, LATEST_RELEASE, STICKY = 'tot', 'latest_release', 'stable_release'
35 CHROME_REV = [TIP_OF_TRUNK, LATEST_RELEASE, STICKY]
36
37 # Helper regex's for finding ebuilds.
38 _CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+'
39 _NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
40
41 # Dir where all the action happens.
42 _CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay'
43 '/chromeos-base/chromeos-chrome')
44
45 _GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
46 '%(chrome_version)s as stable.')
47
48
49 def _GetSvnUrl():
50 """Returns the path to the svn url for the given chrome branch."""
51 return os.path.join(BASE_CHROME_SVN_URL, 'trunk')
52
53
54 def _GetTipOfTrunkSvnRevision():
55 """Returns the current svn revision for the chrome tree."""
56 svn_url = _GetSvnUrl()
57 svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True)
58
59 revision_re = re.compile('^Revision:\s+(\d+).*')
60 for line in svn_info.splitlines():
61 match = revision_re.search(line)
62 if match:
63 svn_revision = match.group(1)
64 Info('Using SVN Revision %s' % svn_revision)
65 return svn_revision
66
67 raise Exception('Could not find revision information from %s' % svn_url)
68
69
70 def _GetTipOfTrunkVersion():
71 """Returns the current Chrome version."""
72 svn_url = _GetSvnUrl()
73 chrome_version_file = urllib.urlopen(os.path.join(svn_url, 'src', 'chrome',
74 'VERSION'))
75 chrome_version_info = chrome_version_file.read()
76 chrome_version_file.close()
77
78 # Sanity check.
79 if '404 Not Found' in chrome_version_info:
80 raise Exception('Url %s does not have version file.' % svn_url)
81
82 chrome_version_array = []
83
84 for line in chrome_version_info.splitlines():
85 chrome_version_array.append(line.rpartition('=')[2])
86
87 return '.'.join(chrome_version_array)
88
89
90 def _GetLatestRelease(branch=None):
91 """Gets the latest release version from the buildspec_url for the branch.
92
93 Args:
94 branch: If set, gets the latest release for branch, otherwise latest
95 release.
96 Returns:
97 Latest version string.
98 """
99 buildspec_url = 'http://src.chromium.org/svn/releases'
100 svn_ls = RunCommand(['svn', 'ls', buildspec_url], redirect_stdout=True)
101 sorted_ls = RunCommand(['sort', '--version-sort'], input=svn_ls,
102 redirect_stdout=True)
103 if branch:
104 chrome_version_re = re.compile('^%s\.\d+.*' % branch)
105 else:
106 chrome_version_re = re.compile('^[0-9]+\..*')
107 for chrome_version in sorted_ls.splitlines():
108 if chrome_version_re.match(chrome_version):
109 current_version = chrome_version
110
111 return current_version.rstrip('/')
112
113
114 def _GetStickyEBuild(stable_ebuilds):
115 """Returns the sticky ebuild."""
116 sticky_ebuilds = []
117 non_sticky_re = re.compile(_NON_STICKY_REGEX)
118 for ebuild in stable_ebuilds:
119 if not non_sticky_re.match(ebuild.version):
120 sticky_ebuilds.append(ebuild)
121
122 if not sticky_ebuilds:
123 raise Exception('No sticky ebuilds found')
124 elif len(sticky_ebuilds) > 1:
125 Warning('More than one sticky ebuild found')
126
127 return cros_mark_as_stable.BestEBuild(sticky_ebuilds)
128
129
130 class ChromeEBuild(cros_mark_as_stable.EBuild):
131 """Thin sub-class of EBuild that adds a chrome_version field."""
132 chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % (
133 _CHROME_VERSION_REGEX))
134 chrome_version = ''
135
136 def __init__(self, path):
137 cros_mark_as_stable.EBuild.__init__(self, path)
138 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
139 if re_match:
140 self.chrome_version = re_match.group(1)
141
142 def __cmp__(self, other):
143 """Use ebuild paths for comparison."""
144 if self.ebuild_path == other.ebuild_path:
145 return 0
146 elif self.ebuild_path > other.ebuild_path:
147 return 1
148 else:
149 return (-1)
150
151 def __str__(self):
152 return self.ebuild_path
153
154
155 def FindChromeCandidates(overlay_dir):
156 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
157
158 Args:
159 overlay_dir: The path to chrome's portage overlay dir.
160 Returns:
161 Tuple [unstable_ebuild, stable_ebuilds].
162 Raises:
163 Exception: if no unstable ebuild exists for Chrome.
164 """
165 stable_ebuilds = []
166 unstable_ebuilds = []
167 for path in [
168 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
169 if path.endswith('.ebuild'):
170 ebuild = ChromeEBuild(path)
171 if not ebuild.chrome_version:
172 Warning('Poorly formatted ebuild found at %s' % path)
173 else:
174 if '9999' in ebuild.version:
175 unstable_ebuilds.append(ebuild)
176 else:
177 stable_ebuilds.append(ebuild)
178
179 # Apply some sanity checks.
180 if not unstable_ebuilds:
181 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
182 if not stable_ebuilds:
183 Warning('Missing stable ebuild for %s' % overlay_dir)
184
185 return cros_mark_as_stable.BestEBuild(unstable_ebuilds), stable_ebuilds
186
187
188 def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
189 """Finds the Chrome uprev candidate for the given chrome_rev.
190
191 Using the pre-flight logic, this means the stable ebuild you are uprevving
192 from. The difference here is that the version could be different and in
193 that case we want to find it to delete it.
194
195 Args:
196 stable_ebuilds: A list of stable ebuilds.
197 chrome_rev: The chrome_rev designating which candidate to find.
198 sticky_branch: The the branch that is currently sticky with Major/Minor
199 components. For example: 9.0.553
200 Returns:
201 Returns the EBuild, otherwise None if none found.
202 """
203 candidates = []
204 if chrome_rev == TIP_OF_TRUNK:
205 chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX)
206 for ebuild in stable_ebuilds:
207 if chrome_branch_re.search(ebuild.version):
208 candidates.append(ebuild)
209
210 elif chrome_rev == STICKY:
211 chrome_branch_re = re.compile('%s\..*' % sticky_branch)
212 for ebuild in stable_ebuilds:
213 if chrome_branch_re.search(ebuild.version):
214 candidates.append(ebuild)
215
216 else:
217 chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX)
218 for ebuild in stable_ebuilds:
219 if chrome_branch_re.search(ebuild.version) and (
220 not ebuild.chrome_version.startswith(sticky_branch)):
221 candidates.append(ebuild)
222
223 if candidates:
224 return cros_mark_as_stable.BestEBuild(candidates)
225 else:
226 return None
227
228
229 def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
230 chrome_version, commit, overlay_dir,
231 sticky_ebuild):
232 """Uprevs the chrome ebuild specified by chrome_rev.
233
234 This is the main function that uprevs the chrome_rev from a stable candidate
235 to its new version.
236
237 Args:
238 stable_candidate: ebuild that corresponds to the stable ebuild we are
239 revving from. If None, builds the a new ebuild given the version
240 and logic for chrome_rev type with revision set to 1.
241 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
242 chrome_rev: one of CHROME_REV
243 TIP_OF_TRUNK - Requires commit value. Revs the ebuild for the TOT
244 version and uses the portage suffix of _alpha.
245 LATEST_RELEASE - This uses the portage suffix of _rc as they are release
246 candidates for the next sticky version.
247 STICKY - Revs the sticky version.
248 chrome_version: The \d.\d.\d.\d version of Chrome.
249 commit: Used with TIP_OF_TRUNK. The svn revision of chrome.
250 overlay_dir: Path to the chromeos-chrome package dir.
251 sticky_ebuild: EBuild class for the sticky ebuild.
252 Returns:
253 Full portage version atom (including rc's, etc) that was revved.
254 """
255 base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version)
256 # Case where we have the last stable candidate with same version just rev.
257 if stable_candidate and stable_candidate.chrome_version == chrome_version:
258 new_ebuild_path = '%s-r%d.ebuild' % (
259 stable_candidate.ebuild_path_no_revision,
260 stable_candidate.current_revision + 1)
261 else:
262 if chrome_rev == TIP_OF_TRUNK:
263 portage_suffix = '_alpha'
264 else:
265 portage_suffix = '_rc'
266
267 new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix)
268
269 # Mark latest release and sticky branches as stable.
270 mark_stable = chrome_rev != TIP_OF_TRUNK
271
272 cros_mark_as_stable.EBuildStableMarker.MarkAsStable(
273 unstable_ebuild.ebuild_path, new_ebuild_path, 'CROS_SVN_COMMIT', commit,
274 make_stable=mark_stable)
275 new_ebuild = ChromeEBuild(new_ebuild_path)
276 if stable_candidate and (
277 stable_candidate.chrome_version == new_ebuild.chrome_version):
278 if 0 == RunCommand(['diff', '-Bu', stable_candidate.ebuild_path,
279 new_ebuild_path],
280 redirect_stderr=True,
281 redirect_stdout=True,
282 exit_code=True):
283 Info('Previous ebuild with same version found and no 9999 changes found.'
284 ' Nothing to do.')
285 os.unlink(new_ebuild_path)
286 return None
287
288 RunCommand(['git', 'add', new_ebuild_path])
289 if stable_candidate and stable_candidate != sticky_ebuild:
290 RunCommand(['git', 'rm', stable_candidate.ebuild_path])
291
292 cros_mark_as_stable.EBuildStableMarker.CommitChange(
293 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
294 'chrome_version': chrome_version})
295
296 new_ebuild = ChromeEBuild(new_ebuild_path)
297 return '%s-%s' % (new_ebuild.package, new_ebuild.version)
298
299
300 def main():
301 usage = '%s OPTIONS [%s]' % (__file__, '|'.join(CHROME_REV))
302 parser = optparse.OptionParser(usage)
303 parser.add_option('-s', '--srcroot', default=os.path.join(os.environ['HOME'],
304 'trunk', 'src'),
305 help='Path to the src directory')
306 parser.add_option('-t', '--tracking_branch', default='cros/master',
307 help='Branch we are tracking changes against')
308 (options, args) = parser.parse_args()
309
310 if len(args) != 1 or args[0] not in CHROME_REV:
311 parser.error('Commit requires arg set to one of %s.' % CHROME_REV)
312
313 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
314 {'srcroot': options.srcroot})
315 chrome_rev = args[0]
316 version_to_uprev = None
317 commit_to_use = None
318
319 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
320 sticky_ebuild = _GetStickyEBuild(stable_ebuilds)
321 sticky_version = sticky_ebuild.chrome_version
322 sticky_branch = sticky_version.rpartition('.')[0]
323
324 if chrome_rev == TIP_OF_TRUNK:
325 version_to_uprev = _GetTipOfTrunkVersion()
326 commit_to_use = _GetTipOfTrunkSvnRevision()
327 elif chrome_rev == LATEST_RELEASE:
328 version_to_uprev = _GetLatestRelease()
329 # Don't rev on stable branch for latest_release.
330 if re.match('%s\.\d+' % sticky_branch, version_to_uprev):
331 Info('Latest release is sticky branch. Nothing to do.')
332 return
333 else:
334 version_to_uprev = _GetLatestRelease(sticky_branch)
335
336 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
337 sticky_branch)
338
339 if stable_candidate:
340 Info('Stable candidate found %s' % stable_candidate)
341 else:
342 Info('No stable candidate found.')
343
344 os.chdir(overlay_dir)
345 work_branch = cros_mark_as_stable.GitBranch(
346 cros_mark_as_stable.STABLE_BRANCH_NAME, options.tracking_branch)
347 work_branch.CreateBranch()
348 chrome_version_atom = MarkChromeEBuildAsStable(
349 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev,
350 commit_to_use, overlay_dir, sticky_ebuild)
351 # Explicit print to communicate to caller.
352 if chrome_version_atom:
353 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom
354
355
356 if __name__ == '__main__':
357 main()
OLDNEW
« no previous file with comments | « bin/cros_mark_chrome_as_stable ('k') | bin/cros_mark_chrome_as_stable_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698