Chromium Code Reviews| 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 a given package's ebuild to the next revision.""" | 7 """This module uprevs a given package's ebuild to the next revision.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import fileinput | 10 import fileinput |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 _SimpleRunCommand(delete_cmd) | 312 _SimpleRunCommand(delete_cmd) |
| 313 | 313 |
| 314 | 314 |
| 315 class EBuild(object): | 315 class EBuild(object): |
| 316 """Wrapper class for information about an ebuild.""" | 316 """Wrapper class for information about an ebuild.""" |
| 317 | 317 |
| 318 def __init__(self, path): | 318 def __init__(self, path): |
| 319 """Sets up data about an ebuild from its path.""" | 319 """Sets up data about an ebuild from its path.""" |
| 320 from portage.versions import pkgsplit | 320 from portage.versions import pkgsplit |
| 321 unused_path, self.category, self.pkgname, filename = path.rsplit('/', 3) | 321 unused_path, self.category, self.pkgname, filename = path.rsplit('/', 3) |
| 322 unused_pkgname, version_no_rev, rev = pkgsplit( | 322 unused_pkgname, self.version_no_rev, rev = pkgsplit( |
| 323 filename.replace('.ebuild', '')) | 323 filename.replace('.ebuild', '')) |
| 324 | 324 |
| 325 self.ebuild_path_no_version = os.path.join( | 325 self.ebuild_path_no_version = os.path.join( |
| 326 os.path.dirname(path), self.pkgname) | 326 os.path.dirname(path), self.pkgname) |
| 327 self.ebuild_path_no_revision = '%s-%s' % (self.ebuild_path_no_version, | |
|
sosa
2010/12/09 19:09:04
No. This is used by cros_mark_chrome_as_stable.
| |
| 328 version_no_rev) | |
| 329 self.current_revision = int(rev.replace('r', '')) | 327 self.current_revision = int(rev.replace('r', '')) |
| 330 self.version = '%s-%s' % (version_no_rev, rev) | 328 self.version = '%s-%s' % (self.version_no_rev, rev) |
| 331 self.package = '%s/%s' % (self.category, self.pkgname) | 329 self.package = '%s/%s' % (self.category, self.pkgname) |
| 332 self.ebuild_path = path | 330 self.ebuild_path = path |
| 333 | 331 |
| 334 self.is_workon = False | 332 self.is_workon = False |
| 335 self.is_stable = False | 333 self.is_stable = False |
| 336 | 334 |
| 337 for line in fileinput.input(path): | 335 for line in fileinput.input(path): |
| 338 if line.startswith('inherit ') and 'cros-workon' in line: | 336 if line.startswith('inherit ') and 'cros-workon' in line: |
| 339 self.is_workon = True | 337 self.is_workon = True |
| 340 elif (line.startswith('KEYWORDS=') and '~' not in line and | 338 elif (line.startswith('KEYWORDS=') and '~' not in line and |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 commit_id: String corresponding to the commit hash of the developer | 440 commit_id: String corresponding to the commit hash of the developer |
| 443 package to rev. | 441 package to rev. |
| 444 redirect_file: Optional file to write the new ebuild. By default | 442 redirect_file: Optional file to write the new ebuild. By default |
| 445 it is written using the standard rev'ing logic. This file must be | 443 it is written using the standard rev'ing logic. This file must be |
| 446 opened and closed by the caller. | 444 opened and closed by the caller. |
| 447 | 445 |
| 448 Raises: | 446 Raises: |
| 449 OSError: Error occurred while creating a new ebuild. | 447 OSError: Error occurred while creating a new ebuild. |
| 450 IOError: Error occurred while writing to the new revved ebuild file. | 448 IOError: Error occurred while writing to the new revved ebuild file. |
| 451 Returns: | 449 Returns: |
| 452 True if the revved package is different than the old ebuild. | 450 If the revved package is different than the old ebuild, return the full |
| 451 revved package name, including the version number. Otherwise, return None. | |
| 453 """ | 452 """ |
| 454 if self._ebuild.is_stable: | 453 if self._ebuild.is_stable: |
| 455 new_stable_ebuild_path = '%s-r%d.ebuild' % ( | 454 stable_version_no_rev = self._ebuild.version_no_rev |
| 456 self._ebuild.ebuild_path_no_revision, | |
| 457 self._ebuild.current_revision + 1) | |
| 458 else: | 455 else: |
| 459 # If given unstable ebuild, use 0.0.1 rather than 9999. | 456 # If given unstable ebuild, use 0.0.1 rather than 9999. |
| 460 new_stable_ebuild_path = '%s-0.0.1-r%d.ebuild' % ( | 457 stable_version_no_rev = '0.0.1' |
|
sosa
2010/12/09 19:09:04
extra line
davidjames
2010/12/21 19:48:29
Looks like an artifact of rietveld -- there's no e
| |
| 461 self._ebuild.ebuild_path_no_version, | 458 new_version = '%s-r%d' % (stable_version_no_rev, |
| 462 self._ebuild.current_revision + 1) | 459 self._ebuild.current_revision + 1) |
| 460 new_stable_ebuild_path = '%s-%s.ebuild' % ( | |
| 461 self._ebuild.ebuild_path_no_version, new_version) | |
| 463 | 462 |
| 464 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path) | 463 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path) |
| 465 unstable_ebuild_path = ('%s-9999.ebuild' % | 464 unstable_ebuild_path = ('%s-9999.ebuild' % |
| 466 self._ebuild.ebuild_path_no_version) | 465 self._ebuild.ebuild_path_no_version) |
| 467 if not os.path.exists(unstable_ebuild_path): | 466 if not os.path.exists(unstable_ebuild_path): |
| 468 Die('Missing unstable ebuild: %s' % unstable_ebuild_path) | 467 Die('Missing unstable ebuild: %s' % unstable_ebuild_path) |
| 469 | 468 |
| 470 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path, | 469 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path, |
| 471 'CROS_WORKON_COMMIT', commit_id, redirect_file) | 470 'CROS_WORKON_COMMIT', commit_id, redirect_file) |
| 472 | 471 |
| 473 old_ebuild_path = self._ebuild.ebuild_path | 472 old_ebuild_path = self._ebuild.ebuild_path |
| 474 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path] | 473 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path] |
| 475 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, | 474 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, |
| 476 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): | 475 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): |
| 477 os.unlink(new_stable_ebuild_path) | 476 os.unlink(new_stable_ebuild_path) |
|
diandersAtChromium
2010/12/10 23:58:54
Leave in explicit return of None?
davidjames
2010/12/21 19:48:29
Done.
| |
| 478 return False | |
| 479 else: | 477 else: |
| 480 _Print('Adding new stable ebuild to git') | 478 _Print('Adding new stable ebuild to git') |
| 481 _SimpleRunCommand('git add %s' % new_stable_ebuild_path) | 479 _SimpleRunCommand('git add %s' % new_stable_ebuild_path) |
| 482 | 480 |
| 483 if self._ebuild.is_stable: | 481 if self._ebuild.is_stable: |
| 484 _Print('Removing old ebuild from git') | 482 _Print('Removing old ebuild from git') |
| 485 _SimpleRunCommand('git rm %s' % old_ebuild_path) | 483 _SimpleRunCommand('git rm %s' % old_ebuild_path) |
| 486 | 484 |
| 487 return True | 485 return '%s-%s' % (self._ebuild.package, new_version) |
| 488 | 486 |
| 489 @classmethod | 487 @classmethod |
| 490 def CommitChange(cls, message): | 488 def CommitChange(cls, message): |
| 491 """Commits current changes in git locally with given commit message. | 489 """Commits current changes in git locally with given commit message. |
| 492 | 490 |
| 493 Args: | 491 Args: |
| 494 message: the commit string to write when committing to git. | 492 message: the commit string to write when committing to git. |
| 495 | 493 |
| 496 Raises: | 494 Raises: |
| 497 OSError: Error occurred while committing. | 495 OSError: Error occurred while committing. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 if not work_branch.Exists(): | 547 if not work_branch.Exists(): |
| 550 Die('Unable to create stabilizing branch in %s' % overlay) | 548 Die('Unable to create stabilizing branch in %s' % overlay) |
| 551 | 549 |
| 552 # Contains the array of packages we actually revved. | 550 # Contains the array of packages we actually revved. |
| 553 revved_packages = [] | 551 revved_packages = [] |
| 554 for ebuild in ebuilds: | 552 for ebuild in ebuilds: |
| 555 try: | 553 try: |
| 556 _Print('Working on %s' % ebuild.package) | 554 _Print('Working on %s' % ebuild.package) |
| 557 worker = EBuildStableMarker(ebuild) | 555 worker = EBuildStableMarker(ebuild) |
| 558 commit_id = ebuild.GetCommitId() | 556 commit_id = ebuild.GetCommitId() |
| 559 if worker.RevWorkOnEBuild(commit_id): | 557 new_package = worker.RevWorkOnEBuild(commit_id) |
| 558 if new_package: | |
| 560 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) | 559 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) |
| 561 worker.CommitChange(message) | 560 worker.CommitChange(message) |
| 562 revved_packages.append(ebuild.package) | 561 revved_packages.append('=%s' % new_package) |
| 563 | 562 |
| 564 except (OSError, IOError): | 563 except (OSError, IOError): |
| 565 Warning('Cannot rev %s\n' % ebuild.package, | 564 Warning('Cannot rev %s\n' % ebuild.package, |
| 566 'Note you will have to go into %s ' | 565 'Note you will have to go into %s ' |
| 567 'and reset the git repo yourself.' % overlay) | 566 'and reset the git repo yourself.' % overlay) |
| 568 raise | 567 raise |
| 569 | 568 |
| 570 if revved_packages: | 569 if revved_packages: |
| 571 _CleanStalePackages(gflags.FLAGS.board, revved_packages) | 570 _CleanStalePackages(gflags.FLAGS.board, revved_packages) |
| 572 if gflags.FLAGS.drop_file: | 571 if gflags.FLAGS.drop_file: |
| 573 fh = open(gflags.FLAGS.drop_file, 'w') | 572 fh = open(gflags.FLAGS.drop_file, 'w') |
| 574 fh.write(' '.join(revved_packages)) | 573 fh.write(' '.join(revved_packages)) |
|
diandersAtChromium
2010/12/10 23:58:54
Won't this file now contain "=" before each packag
davidjames
2010/12/21 19:48:29
Great catch. Fixed -- I changed my patch so that r
| |
| 575 fh.close() | 574 fh.close() |
| 576 else: | 575 else: |
| 577 work_branch.Delete() | 576 work_branch.Delete() |
| 578 | 577 |
| 579 | 578 |
| 580 if __name__ == '__main__': | 579 if __name__ == '__main__': |
| 581 main(sys.argv) | 580 main(sys.argv) |
| OLD | NEW |