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

Side by Side Diff: bin/cros_mark_chrome_as_stable.py

Issue 4798001: Add chrome revving module to crosutils (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Remove cros_mark_stable stuff Created 10 years, 1 month 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') | no next file » | 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/python2.4
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 import optparse
10 import os
11 import re
12 import sys
13 import urllib
14
15 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
16 import cros_mark_as_stable
17
18 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
19 from cros_build_lib import RunCommand, Info, Warning
20
21 BASE_CHROME_SVN_URL = 'http://src.chromium.org/svn'
Chris Masone 2010/11/18 02:23:07 This is only for the public source. That doesn't
22
23 # Command for which chrome ebuild to uprev.
24 TIP_OF_TRUNK, LATEST_RELEASE, STICKY = 'tot', 'latest_release', 'sticky_release'
25 CHROME_REV = [TIP_OF_TRUNK, LATEST_RELEASE, STICKY]
26
27 # Helper regex's for finding ebuilds.
28 _CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+'
29 _NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX
30
31 # Dir where all the action happens.
32 _CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay'
33 '/chromeos-base/chromeos-chrome')
34
35 # Different than cros_mark so devs don't have local collisions.
36 _STABLE_BRANCH_NAME = 'chrome_stabilizing_branch'
37
38 _GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version '
39 '%(chrome_version)s as stable.')
40
41
42 def _GetSvnUrl():
43 """Returns the path to the svn url for the given chrome branch."""
44 return os.path.join(BASE_CHROME_SVN_URL, 'trunk')
45
46
47 def _GetTipOfTrunkSvnRevision():
48 """Returns the current svn revision for the chrome tree."""
49 svn_url = _GetSvnUrl()
50 svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True)
51
52 revision_re = re.compile('^Revision:')
53 for line in svn_info.splitlines():
54 if revision_re.search(line):
55 return line.split(':')[1].strip()
Chris Masone 2010/11/18 02:23:07 I'm sad that we can't figure out a better way to d
Mandeep Singh Baines 2010/11/18 04:11:47 I've been archiving these emails for a while now b
56
57 raise Exception('Could not find revision information from %s' % svn_url)
58
59
60 def _GetTipOfTrunkVersion():
61 """Returns the current Chrome version."""
62 svn_url = _GetSvnUrl()
63 chrome_version_file = urllib.urlopen(os.path.join(svn_url, 'src', 'chrome',
64 'VERSION'))
65 chrome_version_info = chrome_version_file.read()
66 chrome_version_file.close()
67
68 # Sanity check.
69 if '404 Not Found' in chrome_version_info:
70 raise Exception('Url %s does not have version file.' % svn_url)
71
72 chrome_version_array = []
73
74 for line in chrome_version_info.splitlines():
75 chrome_version_array.append(line.rpartition('=')[2])
76
77 return '.'.join(chrome_version_array)
78
79
80 def _GetLatestRelease(branch=None):
81 """Gets the latest release version from the buildspec_url for the branch.
82
83 Args:
84 branch: If set, gets the latest release for branch, otherwise latest
85 release.
86 Returns:
87 Latest version string.
88 """
89 buildspec_url = 'http://src.chromium.org/svn/releases'
90 svn_ls = RunCommand(['svn', 'ls', buildspec_url], redirect_stdout=True)
91 sorted_ls = RunCommand(['sort', '--version-sort'], input=svn_ls,
92 redirect_stdout=True)
93 if branch:
94 chrome_version_re = re.compile('^%s\.\d+.*' % branch)
95 else:
96 chrome_version_re = re.compile('^[0-9]\..*')
97 for chrome_version in sorted_ls.splitlines():
98 if chrome_version_re.match(chrome_version):
99 current_version = chrome_version
100
101 return current_version.rstrip('/')
102
103
104 def _GetStickyVersion(stable_ebuilds):
105 """Discovers the sticky version from the current stable_ebuilds."""
106 sticky_ebuilds = []
107 non_sticky_re = re.compile(_NON_STICKY_REGEX)
108 for ebuild in stable_ebuilds:
109 if not non_sticky_re.match(ebuild.version):
110 sticky_ebuilds.append(ebuild)
111
112 if not sticky_ebuilds:
113 raise Exception('No sticky ebuilds found')
114 elif len(sticky_ebuilds) > 1:
115 Warning('More than one sticky ebuild found')
116
117 return cros_mark_as_stable.BestEBuild(sticky_ebuilds).chrome_version
118
119
120 class ChromeEBuild(cros_mark_as_stable.EBuild):
121 """Thin sub-class of EBuild that adds a chrome_version field."""
122 chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % (
123 _CHROME_VERSION_REGEX))
124 chrome_version = ''
125
126 def __init__(self, path):
127 cros_mark_as_stable.EBuild.__init__(self, path)
128 re_match = self.chrome_version_re.match(self.ebuild_path_no_revision)
129 if re_match:
130 self.chrome_version = re_match.group(1)
131
132
133 def FindChromeCandidates(overlay_dir):
134 """Return a tuple of chrome's unstable ebuild and stable ebuilds.
135
136 Args:
137 overlay_dir: The path to chrome's portage overlay dir.
138 Returns:
139 Tuple [unstable_ebuild, stable_ebuilds].
140 Raises:
141 Exception: if no unstable ebuild exists for Chrome.
142 """
143 stable_ebuilds = []
144 unstable_ebuild = None
145 for path in [
146 os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]:
147 if path.endswith('.ebuild'):
148 ebuild = ChromeEBuild(path)
149 if not ebuild.chrome_version:
150 Warning('Poorly formatted ebuild found at %s' % path)
151 else:
152 if not ebuild.is_stable:
153 unstable_ebuild = ebuild
154 else:
155 stable_ebuilds.append(ebuild)
156
157 # Apply some sanity checks.
158 if not unstable_ebuild:
159 raise Exception('Missing 9999 ebuild for %s' % overlay_dir)
160 if not stable_ebuilds:
161 Warning('Missing stable ebuild for %s' % overlay_dir)
162
163 return unstable_ebuild, stable_ebuilds
164
165
166 def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch):
167 """Finds the Chrome uprev candidate for the given chrome_rev.
168
169 Using the pre-flight logic, this means the stable ebuild you are uprevving
170 from. The difference here is that the version could be different and in
171 that case we want to find it to delete it.
172
173 Args:
174 stable_ebuilds: A list of stable ebuilds.
175 chrome_rev: The chrome_rev designating which candidate to find.
176 sticky_branch: The the branch that is currently sticky with Major/Minor
177 components. For example: 9.0.553
178 Returns:
179 Returns the EBuild, otherwise None if none found.
180 """
181 candidates = []
182 if chrome_rev == TIP_OF_TRUNK:
183 chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX)
184 for ebuild in stable_ebuilds:
185 if chrome_branch_re.search(ebuild.version):
186 candidates.append(ebuild)
187
188 elif chrome_rev == STICKY:
189 chrome_branch_re = re.compile('%s\.\d+.*_rc.*' % sticky_branch)
190 for ebuild in stable_ebuilds:
191 if chrome_branch_re.search(ebuild.version):
192 candidates.append(ebuild)
193
194 else:
195 chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX)
196 for ebuild in stable_ebuilds:
197 if chrome_branch_re.search(ebuild.version) and (
198 not ebuild.chrome_version.startswith(ebuild.chrome_version)):
199 candidates.append(ebuild)
200
201 if candidates:
202 return cros_mark_as_stable.BestEBuild(candidates)
203 else:
204 return None
205
206
207 def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
208 chrome_version, commit, overlay_dir):
209 """Uprevs the chrome ebuild specified by chrome_rev.
210
211 This is the main function that uprevs the chrome_rev from a stable candidate
212 to its new version.
213
214 Args:
215 stable_candidate: ebuild that corresponds to the stable ebuild we are
216 revving from. If None, builds the a new ebuild given the version
217 and logic for chrome_rev type with revision set to 1.
218 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome.
219 chrome_rev: one of CHROME_REV
220 TIP_OF_TRUNK - Requires commit value. Revs the ebuild for the TOT
221 version and uses the portage suffix of _alpha.
222 LATEST_RELEASE - This uses the portage suffix of _rc as they are release
223 candidates for the next sticky version.
224 STICKY - Revs the sticky version.
225 chrome_version: The \d.\d.\d.\d version of Chrome.
226 commit: Used with TIP_OF_TRUNK. The svn revision of chrome.
227 overlay_dir: Path to the chromeos-chrome package dir.
228 """
229 base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version)
230 # Case where we have the last stable candidate with same version just rev.
231 if stable_candidate and stable_candidate.chrome_version == chrome_version:
232 new_ebuild_path = '%s-r%d.ebuild' % (
233 stable_candidate.ebuild_path_no_revision,
234 stable_candidate.current_revision + 1)
235 else:
236 if chrome_rev == TIP_OF_TRUNK:
237 portage_suffix = '_alpha'
238 else:
239 portage_suffix = '_rc'
240
241 new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix)
242
243 cros_mark_as_stable.EBuildStableMarker.MarkAsStable(
244 unstable_ebuild.ebuild_path, new_ebuild_path, 'CROS_SVN_COMMIT', commit)
245 RunCommand(['git', 'add', new_ebuild_path])
246 if stable_candidate:
247 RunCommand(['git', 'rm', stable_candidate.ebuild_path])
248
249 cros_mark_as_stable.EBuildStableMarker.CommitChange(
250 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev,
251 'chrome_version': chrome_version})
252
253
254 def main(argv):
255 usage = '%s OPTIONS commit|clean|push'
256 parser = optparse.OptionParser(usage)
257 parser.add_option('-c', '--chrome_rev', default=None,
258 help='One of %s' % CHROME_REV)
259 parser.add_option('-s', '--srcroot', default='.',
260 help='Path to the src directory')
261 parser.add_option('-t', '--tracking_branch', default='cros/master',
262 help='Branch we are tracking changes against')
263 (options, argv) = parser.parse_args(argv)
264
265 if len(argv) != 2 or argv[1] not in (
266 cros_mark_as_stable.COMMAND_DICTIONARY.keys()):
267 parser.error('Arguments are invalid, see usage.')
268
269 command = argv[1]
270 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR %
271 {'srcroot': options.srcroot})
272
273 os.chdir(overlay_dir)
274 if command == 'clean':
275 cros_mark_as_stable.Clean(options.tracking_branch)
276 return
277 elif command == 'push':
278 cros_mark_as_stable.PushChange(_STABLE_BRANCH_NAME, options.tracking_branch)
279 return
280
281 if not options.chrome_rev or options.chrome_rev not in CHROME_REV:
282 parser.error('Commit requires type set to one of %s.' % CHROME_REV)
283
284 chrome_rev = options.chrome_rev
285 version_to_uprev = None
286 commit_to_use = None
287
288 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir)
289 sticky_version = _GetStickyVersion(stable_ebuilds)
290 sticky_branch = sticky_version.rpartition('.')[0]
291
292 if chrome_rev == TIP_OF_TRUNK:
293 version_to_uprev = _GetTipOfTrunkVersion()
294 commit_to_use = _GetTipOfTrunkSvnRevision()
295 elif chrome_rev == LATEST_RELEASE:
296 version_to_uprev = _GetLatestRelease()
297 else:
298 version_to_uprev = _GetLatestRelease(sticky_branch)
299
300 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev,
301 sticky_branch)
302 # There are some cases we don't need to do anything. Check for them.
303 if stable_candidate and (version_to_uprev == stable_candidate.chrome_version
304 and not commit_to_use):
305 Info('Found nothing to do for chrome_rev %s with version %s.' % (
306 chrome_rev, version_to_uprev))
307 else:
308 work_branch = cros_mark_as_stable.GitBranch(
309 _STABLE_BRANCH_NAME, options.tracking_branch)
310 work_branch.CreateBranch()
311 try:
312 MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev,
313 version_to_uprev, commit_to_use, overlay_dir)
314 except:
315 work_branch.Delete()
316 raise
317
318
319 if __name__ == '__main__':
320 main(sys.argv)
OLDNEW
« no previous file with comments | « bin/cros_mark_chrome_as_stable ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698