OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """This module uprevs Chrome for cbuildbot. | 7 """This module uprevs Chrome for cbuildbot. |
8 | 8 |
9 After calling, it prints outs CHROME_VERSION_ATOM=(version atom string). A | 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 | 10 caller could then use this atom with emerge to build the newly uprevved version |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 chrome_version_re = re.compile('^%s\.\d+.*' % branch) | 102 chrome_version_re = re.compile('^%s\.\d+.*' % branch) |
103 else: | 103 else: |
104 chrome_version_re = re.compile('^[0-9]\..*') | 104 chrome_version_re = re.compile('^[0-9]\..*') |
105 for chrome_version in sorted_ls.splitlines(): | 105 for chrome_version in sorted_ls.splitlines(): |
106 if chrome_version_re.match(chrome_version): | 106 if chrome_version_re.match(chrome_version): |
107 current_version = chrome_version | 107 current_version = chrome_version |
108 | 108 |
109 return current_version.rstrip('/') | 109 return current_version.rstrip('/') |
110 | 110 |
111 | 111 |
112 def _GetStickyVersion(stable_ebuilds): | 112 def _GetStickyEBuild(stable_ebuilds): |
113 """Discovers the sticky version from the current stable_ebuilds.""" | 113 """Returns the sticky ebuild.""" |
114 sticky_ebuilds = [] | 114 sticky_ebuilds = [] |
115 non_sticky_re = re.compile(_NON_STICKY_REGEX) | 115 non_sticky_re = re.compile(_NON_STICKY_REGEX) |
116 for ebuild in stable_ebuilds: | 116 for ebuild in stable_ebuilds: |
117 if not non_sticky_re.match(ebuild.version): | 117 if not non_sticky_re.match(ebuild.version): |
118 sticky_ebuilds.append(ebuild) | 118 sticky_ebuilds.append(ebuild) |
119 | 119 |
120 if not sticky_ebuilds: | 120 if not sticky_ebuilds: |
121 raise Exception('No sticky ebuilds found') | 121 raise Exception('No sticky ebuilds found') |
122 elif len(sticky_ebuilds) > 1: | 122 elif len(sticky_ebuilds) > 1: |
123 Warning('More than one sticky ebuild found') | 123 Warning('More than one sticky ebuild found') |
124 | 124 |
125 return cros_mark_as_stable.BestEBuild(sticky_ebuilds).chrome_version | 125 return cros_mark_as_stable.BestEBuild(sticky_ebuilds) |
126 | 126 |
127 | 127 |
128 class ChromeEBuild(cros_mark_as_stable.EBuild): | 128 class ChromeEBuild(cros_mark_as_stable.EBuild): |
129 """Thin sub-class of EBuild that adds a chrome_version field.""" | 129 """Thin sub-class of EBuild that adds a chrome_version field.""" |
130 chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % ( | 130 chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % ( |
131 _CHROME_VERSION_REGEX)) | 131 _CHROME_VERSION_REGEX)) |
132 chrome_version = '' | 132 chrome_version = '' |
133 | 133 |
134 def __init__(self, path): | 134 def __init__(self, path): |
135 cros_mark_as_stable.EBuild.__init__(self, path) | 135 cros_mark_as_stable.EBuild.__init__(self, path) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 Returns the EBuild, otherwise None if none found. | 196 Returns the EBuild, otherwise None if none found. |
197 """ | 197 """ |
198 candidates = [] | 198 candidates = [] |
199 if chrome_rev == TIP_OF_TRUNK: | 199 if chrome_rev == TIP_OF_TRUNK: |
200 chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX) | 200 chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX) |
201 for ebuild in stable_ebuilds: | 201 for ebuild in stable_ebuilds: |
202 if chrome_branch_re.search(ebuild.version): | 202 if chrome_branch_re.search(ebuild.version): |
203 candidates.append(ebuild) | 203 candidates.append(ebuild) |
204 | 204 |
205 elif chrome_rev == STICKY: | 205 elif chrome_rev == STICKY: |
206 chrome_branch_re = re.compile('%s\.\d+.*_rc.*' % sticky_branch) | 206 chrome_branch_re = re.compile('%s\..*' % sticky_branch) |
207 for ebuild in stable_ebuilds: | 207 for ebuild in stable_ebuilds: |
208 if chrome_branch_re.search(ebuild.version): | 208 if chrome_branch_re.search(ebuild.version): |
209 candidates.append(ebuild) | 209 candidates.append(ebuild) |
210 | 210 |
211 else: | 211 else: |
212 chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX) | 212 chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX) |
213 for ebuild in stable_ebuilds: | 213 for ebuild in stable_ebuilds: |
214 if chrome_branch_re.search(ebuild.version) and ( | 214 if chrome_branch_re.search(ebuild.version) and ( |
215 not ebuild.chrome_version.startswith(sticky_branch)): | 215 not ebuild.chrome_version.startswith(sticky_branch)): |
216 candidates.append(ebuild) | 216 candidates.append(ebuild) |
217 | 217 |
218 if candidates: | 218 if candidates: |
219 return cros_mark_as_stable.BestEBuild(candidates) | 219 return cros_mark_as_stable.BestEBuild(candidates) |
220 else: | 220 else: |
221 return None | 221 return None |
222 | 222 |
223 | 223 |
224 def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev, | 224 def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev, |
225 chrome_version, commit, overlay_dir): | 225 chrome_version, commit, overlay_dir, |
| 226 sticky_ebuild): |
226 """Uprevs the chrome ebuild specified by chrome_rev. | 227 """Uprevs the chrome ebuild specified by chrome_rev. |
227 | 228 |
228 This is the main function that uprevs the chrome_rev from a stable candidate | 229 This is the main function that uprevs the chrome_rev from a stable candidate |
229 to its new version. | 230 to its new version. |
230 | 231 |
231 Args: | 232 Args: |
232 stable_candidate: ebuild that corresponds to the stable ebuild we are | 233 stable_candidate: ebuild that corresponds to the stable ebuild we are |
233 revving from. If None, builds the a new ebuild given the version | 234 revving from. If None, builds the a new ebuild given the version |
234 and logic for chrome_rev type with revision set to 1. | 235 and logic for chrome_rev type with revision set to 1. |
235 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome. | 236 unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome. |
236 chrome_rev: one of CHROME_REV | 237 chrome_rev: one of CHROME_REV |
237 TIP_OF_TRUNK - Requires commit value. Revs the ebuild for the TOT | 238 TIP_OF_TRUNK - Requires commit value. Revs the ebuild for the TOT |
238 version and uses the portage suffix of _alpha. | 239 version and uses the portage suffix of _alpha. |
239 LATEST_RELEASE - This uses the portage suffix of _rc as they are release | 240 LATEST_RELEASE - This uses the portage suffix of _rc as they are release |
240 candidates for the next sticky version. | 241 candidates for the next sticky version. |
241 STICKY - Revs the sticky version. | 242 STICKY - Revs the sticky version. |
242 chrome_version: The \d.\d.\d.\d version of Chrome. | 243 chrome_version: The \d.\d.\d.\d version of Chrome. |
243 commit: Used with TIP_OF_TRUNK. The svn revision of chrome. | 244 commit: Used with TIP_OF_TRUNK. The svn revision of chrome. |
244 overlay_dir: Path to the chromeos-chrome package dir. | 245 overlay_dir: Path to the chromeos-chrome package dir. |
| 246 sticky_ebuild: EBuild class for the sticky ebuild. |
245 Returns: | 247 Returns: |
246 Full portage version atom (including rc's, etc) that was revved. | 248 Full portage version atom (including rc's, etc) that was revved. |
247 """ | 249 """ |
248 base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version) | 250 base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version) |
249 # Case where we have the last stable candidate with same version just rev. | 251 # Case where we have the last stable candidate with same version just rev. |
250 if stable_candidate and stable_candidate.chrome_version == chrome_version: | 252 if stable_candidate and stable_candidate.chrome_version == chrome_version: |
251 new_ebuild_path = '%s-r%d.ebuild' % ( | 253 new_ebuild_path = '%s-r%d.ebuild' % ( |
252 stable_candidate.ebuild_path_no_revision, | 254 stable_candidate.ebuild_path_no_revision, |
253 stable_candidate.current_revision + 1) | 255 stable_candidate.current_revision + 1) |
254 else: | 256 else: |
255 if chrome_rev == TIP_OF_TRUNK: | 257 if chrome_rev == TIP_OF_TRUNK: |
256 portage_suffix = '_alpha' | 258 portage_suffix = '_alpha' |
257 else: | 259 else: |
258 portage_suffix = '_rc' | 260 portage_suffix = '_rc' |
259 | 261 |
260 new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix) | 262 new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix) |
261 | 263 |
262 cros_mark_as_stable.EBuildStableMarker.MarkAsStable( | 264 cros_mark_as_stable.EBuildStableMarker.MarkAsStable( |
263 unstable_ebuild.ebuild_path, new_ebuild_path, 'CROS_SVN_COMMIT', commit) | 265 unstable_ebuild.ebuild_path, new_ebuild_path, 'CROS_SVN_COMMIT', commit, |
| 266 make_stable=False) |
| 267 new_ebuild = ChromeEBuild(new_ebuild_path) |
| 268 if stable_candidate and ( |
| 269 stable_candidate.chrome_version == new_ebuild.chrome_version): |
| 270 if 0 == RunCommand(['diff', '-Bu', stable_candidate.ebuild_path, |
| 271 new_ebuild_path], |
| 272 redirect_stderr=True, |
| 273 redirect_stdout=True, |
| 274 exit_code=True): |
| 275 os.unlink(new_ebuild_path) |
| 276 return None |
| 277 |
264 RunCommand(['git', 'add', new_ebuild_path]) | 278 RunCommand(['git', 'add', new_ebuild_path]) |
265 if stable_candidate: | 279 if stable_candidate and stable_candidate != sticky_ebuild: |
266 RunCommand(['git', 'rm', stable_candidate.ebuild_path]) | 280 RunCommand(['git', 'rm', stable_candidate.ebuild_path]) |
267 | 281 |
268 cros_mark_as_stable.EBuildStableMarker.CommitChange( | 282 cros_mark_as_stable.EBuildStableMarker.CommitChange( |
269 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev, | 283 _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev, |
270 'chrome_version': chrome_version}) | 284 'chrome_version': chrome_version}) |
271 | 285 |
272 new_ebuild = ChromeEBuild(new_ebuild_path) | 286 new_ebuild = ChromeEBuild(new_ebuild_path) |
273 return '%s-%s' % (new_ebuild.package, new_ebuild.version) | 287 return '%s-%s' % (new_ebuild.package, new_ebuild.version) |
274 | 288 |
275 | 289 |
(...skipping 10 matching lines...) Expand all Loading... |
286 if len(args) != 1 or args[0] not in CHROME_REV: | 300 if len(args) != 1 or args[0] not in CHROME_REV: |
287 parser.error('Commit requires arg set to one of %s.' % CHROME_REV) | 301 parser.error('Commit requires arg set to one of %s.' % CHROME_REV) |
288 | 302 |
289 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR % | 303 overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR % |
290 {'srcroot': options.srcroot}) | 304 {'srcroot': options.srcroot}) |
291 chrome_rev = args[0] | 305 chrome_rev = args[0] |
292 version_to_uprev = None | 306 version_to_uprev = None |
293 commit_to_use = None | 307 commit_to_use = None |
294 | 308 |
295 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir) | 309 (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir) |
296 sticky_version = _GetStickyVersion(stable_ebuilds) | 310 sticky_ebuild = _GetStickyEBuild(stable_ebuilds) |
| 311 sticky_version = sticky_ebuild.chrome_version |
297 sticky_branch = sticky_version.rpartition('.')[0] | 312 sticky_branch = sticky_version.rpartition('.')[0] |
298 | 313 |
299 | |
300 if chrome_rev == TIP_OF_TRUNK: | 314 if chrome_rev == TIP_OF_TRUNK: |
301 version_to_uprev = _GetTipOfTrunkVersion() | 315 version_to_uprev = _GetTipOfTrunkVersion() |
302 commit_to_use = _GetTipOfTrunkSvnRevision() | 316 commit_to_use = _GetTipOfTrunkSvnRevision() |
303 elif chrome_rev == LATEST_RELEASE: | 317 elif chrome_rev == LATEST_RELEASE: |
304 version_to_uprev = _GetLatestRelease() | 318 version_to_uprev = _GetLatestRelease() |
305 else: | 319 else: |
306 version_to_uprev = _GetLatestRelease(sticky_branch) | 320 version_to_uprev = _GetLatestRelease(sticky_branch) |
307 | 321 |
308 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev, | 322 stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev, |
309 sticky_branch) | 323 sticky_branch) |
310 # There are some cases we don't need to do anything. Check for them. | 324 |
311 if stable_candidate and (version_to_uprev == stable_candidate.chrome_version | 325 os.chdir(overlay_dir) |
312 and not commit_to_use): | 326 work_branch = cros_mark_as_stable.GitBranch( |
313 Info('Found nothing to do for chrome_rev %s with version %s.' % ( | 327 cros_mark_as_stable.STABLE_BRANCH_NAME, options.tracking_branch) |
314 chrome_rev, version_to_uprev)) | 328 work_branch.CreateBranch() |
315 else: | 329 try: |
316 os.chdir(overlay_dir) | 330 chrome_version_atom = MarkChromeEBuildAsStable( |
317 work_branch = cros_mark_as_stable.GitBranch( | 331 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev, |
318 cros_mark_as_stable.STABLE_BRANCH_NAME, options.tracking_branch) | 332 commit_to_use, overlay_dir, sticky_ebuild) |
319 work_branch.CreateBranch() | 333 # Explicit print to communicate to caller. |
320 try: | 334 if chrome_version_atom: |
321 chrome_version_atom = MarkChromeEBuildAsStable( | |
322 stable_candidate, unstable_ebuild, chrome_rev, version_to_uprev, | |
323 commit_to_use, overlay_dir) | |
324 # Explicit print to communicate to caller. | |
325 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom | 335 print 'CHROME_VERSION_ATOM=%s' % chrome_version_atom |
326 except: | 336 else: |
327 work_branch.Delete() | 337 work_branch.Delete() |
328 raise | 338 except: |
| 339 work_branch.Delete() |
| 340 raise |
329 | 341 |
330 | 342 |
331 if __name__ == '__main__': | 343 if __name__ == '__main__': |
332 main() | 344 main() |
OLD | NEW |