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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 # ======================= Global Helper Functions ======================== | 72 # ======================= Global Helper Functions ======================== |
| 73 | 73 |
| 74 | 74 |
| 75 def _Print(message): | 75 def _Print(message): |
| 76 """Verbose print function.""" | 76 """Verbose print function.""" |
| 77 if gflags.FLAGS.verbose: | 77 if gflags.FLAGS.verbose: |
| 78 Info(message) | 78 Info(message) |
| 79 | 79 |
| 80 | 80 |
| 81 def _CleanStalePackages(board, package_array): | 81 def _CleanStalePackages(board, package_atoms): |
| 82 """Cleans up stale package info from a previous build.""" | 82 """Cleans up stale package info from a previous build.""" |
| 83 Info('Cleaning up stale packages %s.' % package_array) | 83 Info('Cleaning up stale packages %s.' % package_atoms) |
| 84 unmerge_board_cmd = ['emerge-%s' % board, '--unmerge'] | 84 unmerge_board_cmd = ['emerge-%s' % board, '--unmerge'] |
| 85 unmerge_board_cmd.extend(package_array) | 85 unmerge_board_cmd.extend(package_atoms) |
| 86 RunCommand(unmerge_board_cmd) | 86 RunCommand(unmerge_board_cmd) |
| 87 | 87 |
| 88 unmerge_host_cmd = ['sudo', 'emerge', '--unmerge'] | 88 unmerge_host_cmd = ['sudo', 'emerge', '--unmerge'] |
| 89 unmerge_host_cmd.extend(package_array) | 89 unmerge_host_cmd.extend(package_atoms) |
| 90 RunCommand(unmerge_host_cmd) | 90 RunCommand(unmerge_host_cmd) |
| 91 | 91 |
| 92 RunCommand(['eclean-%s' % board, '-d', 'packages'], redirect_stderr=True) | 92 RunCommand(['eclean-%s' % board, '-d', 'packages'], redirect_stderr=True) |
| 93 RunCommand(['sudo', 'eclean', '-d', 'packages'], redirect_stderr=True) | 93 RunCommand(['sudo', 'eclean', '-d', 'packages'], redirect_stderr=True) |
| 94 | 94 |
| 95 | 95 |
| 96 def _FindUprevCandidates(files): | 96 def _FindUprevCandidates(files): |
| 97 """Return a list of uprev candidates from specified list of files. | 97 """Return a list of uprev candidates from specified list of files. |
| 98 | 98 |
| 99 Usually an uprev candidate is a the stable ebuild in a cros_workon directory. | 99 Usually an uprev candidate is a the stable ebuild in a cros_workon directory. |
| (...skipping 212 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, | 327 self.ebuild_path_no_revision = '%s-%s' % (self.ebuild_path_no_version, |
| 328 version_no_rev) | 328 self.version_no_rev) |
| 329 self.current_revision = int(rev.replace('r', '')) | 329 self.current_revision = int(rev.replace('r', '')) |
| 330 self.version = '%s-%s' % (version_no_rev, rev) | 330 self.version = '%s-%s' % (self.version_no_rev, rev) |
| 331 self.package = '%s/%s' % (self.category, self.pkgname) | 331 self.package = '%s/%s' % (self.category, self.pkgname) |
| 332 self.ebuild_path = path | 332 self.ebuild_path = path |
| 333 | 333 |
| 334 self.is_workon = False | 334 self.is_workon = False |
| 335 self.is_stable = False | 335 self.is_stable = False |
| 336 | 336 |
| 337 for line in fileinput.input(path): | 337 for line in fileinput.input(path): |
| 338 if line.startswith('inherit ') and 'cros-workon' in line: | 338 if line.startswith('inherit ') and 'cros-workon' in line: |
| 339 self.is_workon = True | 339 self.is_workon = True |
| 340 elif (line.startswith('KEYWORDS=') and '~' not in line and | 340 elif (line.startswith('KEYWORDS=') and '~' not in line and |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 commit_id: String corresponding to the commit hash of the developer | 447 commit_id: String corresponding to the commit hash of the developer |
| 448 package to rev. | 448 package to rev. |
| 449 redirect_file: Optional file to write the new ebuild. By default | 449 redirect_file: Optional file to write the new ebuild. By default |
| 450 it is written using the standard rev'ing logic. This file must be | 450 it is written using the standard rev'ing logic. This file must be |
| 451 opened and closed by the caller. | 451 opened and closed by the caller. |
| 452 | 452 |
| 453 Raises: | 453 Raises: |
| 454 OSError: Error occurred while creating a new ebuild. | 454 OSError: Error occurred while creating a new ebuild. |
| 455 IOError: Error occurred while writing to the new revved ebuild file. | 455 IOError: Error occurred while writing to the new revved ebuild file. |
| 456 Returns: | 456 Returns: |
| 457 True if the revved package is different than the old ebuild. | 457 If the revved package is different than the old ebuild, return the full |
| 458 revved package name, including the version number. Otherwise, return None. | |
| 458 """ | 459 """ |
| 459 if self._ebuild.is_stable: | 460 if self._ebuild.is_stable: |
| 460 new_stable_ebuild_path = '%s-r%d.ebuild' % ( | 461 stable_version_no_rev = self._ebuild.version_no_rev |
| 461 self._ebuild.ebuild_path_no_revision, | |
| 462 self._ebuild.current_revision + 1) | |
| 463 else: | 462 else: |
| 464 # If given unstable ebuild, use 0.0.1 rather than 9999. | 463 # If given unstable ebuild, use 0.0.1 rather than 9999. |
| 465 new_stable_ebuild_path = '%s-0.0.1-r%d.ebuild' % ( | 464 stable_version_no_rev = '0.0.1' |
|
sosa
2010/12/21 20:37:29
I'd prefer to see an extra line after the else cla
davidjames
2010/12/21 20:46:32
I get what you mean now. Done.
| |
| 466 self._ebuild.ebuild_path_no_version, | 465 new_version = '%s-r%d' % (stable_version_no_rev, |
| 467 self._ebuild.current_revision + 1) | 466 self._ebuild.current_revision + 1) |
| 467 new_stable_ebuild_path = '%s-%s.ebuild' % ( | |
| 468 self._ebuild.ebuild_path_no_version, new_version) | |
| 468 | 469 |
| 469 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path) | 470 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path) |
| 470 unstable_ebuild_path = ('%s-9999.ebuild' % | 471 unstable_ebuild_path = ('%s-9999.ebuild' % |
| 471 self._ebuild.ebuild_path_no_version) | 472 self._ebuild.ebuild_path_no_version) |
| 472 if not os.path.exists(unstable_ebuild_path): | 473 if not os.path.exists(unstable_ebuild_path): |
| 473 Die('Missing unstable ebuild: %s' % unstable_ebuild_path) | 474 Die('Missing unstable ebuild: %s' % unstable_ebuild_path) |
| 474 | 475 |
| 475 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path, | 476 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path, |
| 476 'CROS_WORKON_COMMIT', commit_id, redirect_file) | 477 'CROS_WORKON_COMMIT', commit_id, redirect_file) |
| 477 | 478 |
| 478 old_ebuild_path = self._ebuild.ebuild_path | 479 old_ebuild_path = self._ebuild.ebuild_path |
| 479 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path] | 480 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path] |
| 480 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, | 481 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, |
| 481 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): | 482 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): |
| 482 os.unlink(new_stable_ebuild_path) | 483 os.unlink(new_stable_ebuild_path) |
| 483 return False | 484 return None |
| 484 else: | 485 else: |
| 485 _Print('Adding new stable ebuild to git') | 486 _Print('Adding new stable ebuild to git') |
| 486 _SimpleRunCommand('git add %s' % new_stable_ebuild_path) | 487 _SimpleRunCommand('git add %s' % new_stable_ebuild_path) |
| 487 | 488 |
| 488 if self._ebuild.is_stable: | 489 if self._ebuild.is_stable: |
| 489 _Print('Removing old ebuild from git') | 490 _Print('Removing old ebuild from git') |
| 490 _SimpleRunCommand('git rm %s' % old_ebuild_path) | 491 _SimpleRunCommand('git rm %s' % old_ebuild_path) |
| 491 | 492 |
| 492 return True | 493 return '%s-%s' % (self._ebuild.package, new_version) |
| 493 | 494 |
| 494 @classmethod | 495 @classmethod |
| 495 def CommitChange(cls, message): | 496 def CommitChange(cls, message): |
| 496 """Commits current changes in git locally with given commit message. | 497 """Commits current changes in git locally with given commit message. |
| 497 | 498 |
| 498 Args: | 499 Args: |
| 499 message: the commit string to write when committing to git. | 500 message: the commit string to write when committing to git. |
| 500 | 501 |
| 501 Raises: | 502 Raises: |
| 502 OSError: Error occurred while committing. | 503 OSError: Error occurred while committing. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 elif command == 'push': | 550 elif command == 'push': |
| 550 PushChange(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) | 551 PushChange(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) |
| 551 elif command == 'commit' and ebuilds: | 552 elif command == 'commit' and ebuilds: |
| 552 work_branch = GitBranch(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) | 553 work_branch = GitBranch(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) |
| 553 work_branch.CreateBranch() | 554 work_branch.CreateBranch() |
| 554 if not work_branch.Exists(): | 555 if not work_branch.Exists(): |
| 555 Die('Unable to create stabilizing branch in %s' % overlay) | 556 Die('Unable to create stabilizing branch in %s' % overlay) |
| 556 | 557 |
| 557 # Contains the array of packages we actually revved. | 558 # Contains the array of packages we actually revved. |
| 558 revved_packages = [] | 559 revved_packages = [] |
| 560 revved_package_atoms = [] | |
|
sosa
2010/12/21 20:37:29
Optional nit: Maybe rename to new_atoms or new_rev
davidjames
2010/12/21 20:46:32
Done.
| |
| 559 for ebuild in ebuilds: | 561 for ebuild in ebuilds: |
| 560 try: | 562 try: |
| 561 _Print('Working on %s' % ebuild.package) | 563 _Print('Working on %s' % ebuild.package) |
| 562 worker = EBuildStableMarker(ebuild) | 564 worker = EBuildStableMarker(ebuild) |
| 563 commit_id = ebuild.GetCommitId() | 565 commit_id = ebuild.GetCommitId() |
| 564 if worker.RevWorkOnEBuild(commit_id): | 566 new_package = worker.RevWorkOnEBuild(commit_id) |
| 567 if new_package: | |
| 565 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) | 568 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) |
| 566 worker.CommitChange(message) | 569 worker.CommitChange(message) |
| 567 revved_packages.append(ebuild.package) | 570 revved_packages.append(ebuild.package) |
| 568 | 571 revved_package_atoms.append('=%s' % new_package) |
| 569 except (OSError, IOError): | 572 except (OSError, IOError): |
| 570 Warning('Cannot rev %s\n' % ebuild.package, | 573 Warning('Cannot rev %s\n' % ebuild.package, |
| 571 'Note you will have to go into %s ' | 574 'Note you will have to go into %s ' |
| 572 'and reset the git repo yourself.' % overlay) | 575 'and reset the git repo yourself.' % overlay) |
| 573 raise | 576 raise |
| 574 | 577 |
| 575 if revved_packages: | 578 if revved_packages: |
| 576 _CleanStalePackages(gflags.FLAGS.board, revved_packages) | 579 _CleanStalePackages(gflags.FLAGS.board, revved_package_atoms) |
| 577 if gflags.FLAGS.drop_file: | 580 if gflags.FLAGS.drop_file: |
| 578 fh = open(gflags.FLAGS.drop_file, 'w') | 581 fh = open(gflags.FLAGS.drop_file, 'w') |
| 579 fh.write(' '.join(revved_packages)) | 582 fh.write(' '.join(revved_packages)) |
| 580 fh.close() | 583 fh.close() |
| 581 else: | 584 else: |
| 582 work_branch.Delete() | 585 work_branch.Delete() |
| 583 | 586 |
| 584 | 587 |
| 585 if __name__ == '__main__': | 588 if __name__ == '__main__': |
| 586 main(sys.argv) | 589 main(sys.argv) |
| OLD | NEW |