| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 def _BestEBuild(ebuilds): | 86 def _BestEBuild(ebuilds): |
| 87 """Returns the newest EBuild from a list of EBuild objects.""" | 87 """Returns the newest EBuild from a list of EBuild objects.""" |
| 88 from portage.versions import vercmp | 88 from portage.versions import vercmp |
| 89 winner = ebuilds[0] | 89 winner = ebuilds[0] |
| 90 for ebuild in ebuilds[1:]: | 90 for ebuild in ebuilds[1:]: |
| 91 if vercmp(winner.version, ebuild.version) < 0: | 91 if vercmp(winner.version, ebuild.version) < 0: |
| 92 winner = ebuild | 92 winner = ebuild |
| 93 return winner | 93 return winner |
| 94 | 94 |
| 95 | 95 |
| 96 def _FindStableEBuilds(files): | 96 def _FindUprevCandidates(files): |
| 97 """Return a list of stable ebuilds from specified list of files. | 97 """Return a list of uprev candidates from specified list of files. |
| 98 |
| 99 Usually an uprev candidate is a the stable ebuild in a cros_workon directory. |
| 100 However, if no such stable ebuild exists (someone just checked in the 9999 |
| 101 ebuild), this is the unstable ebuild. |
| 98 | 102 |
| 99 Args: | 103 Args: |
| 100 files: List of files. | 104 files: List of files. |
| 101 """ | 105 """ |
| 102 workon_dir = False | 106 workon_dir = False |
| 103 stable_ebuilds = [] | 107 stable_ebuilds = [] |
| 104 unstable_ebuilds = [] | 108 unstable_ebuilds = [] |
| 105 for path in files: | 109 for path in files: |
| 106 if path.endswith('.ebuild') and not os.path.islink(path): | 110 if path.endswith('.ebuild') and not os.path.islink(path): |
| 107 ebuild = _EBuild(path) | 111 ebuild = _EBuild(path) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 124 # the older ebuilds will not get rev'd. | 128 # the older ebuilds will not get rev'd. |
| 125 # | 129 # |
| 126 # We make a special exception for x11-drivers/xf86-video-msm for legacy | 130 # We make a special exception for x11-drivers/xf86-video-msm for legacy |
| 127 # reasons. | 131 # reasons. |
| 128 if stable_ebuilds[0].package != 'x11-drivers/xf86-video-msm': | 132 if stable_ebuilds[0].package != 'x11-drivers/xf86-video-msm': |
| 129 Warning('Found multiple stable ebuilds in %s' % os.path.dirname(path)) | 133 Warning('Found multiple stable ebuilds in %s' % os.path.dirname(path)) |
| 130 | 134 |
| 131 if not unstable_ebuilds: | 135 if not unstable_ebuilds: |
| 132 Die('Missing 9999 ebuild in %s' % os.path.dirname(path)) | 136 Die('Missing 9999 ebuild in %s' % os.path.dirname(path)) |
| 133 if not stable_ebuilds: | 137 if not stable_ebuilds: |
| 134 Die('Missing stable ebuild in %s' % os.path.dirname(path)) | 138 Warning('Missing stable ebuild in %s' % os.path.dirname(path)) |
| 139 return unstable_ebuilds[0] |
| 135 | 140 |
| 136 if stable_ebuilds: | 141 if stable_ebuilds: |
| 137 return stable_ebuilds[0] | 142 return stable_ebuilds[0] |
| 138 else: | 143 else: |
| 139 return None | 144 return None |
| 140 | 145 |
| 141 | 146 |
| 142 def _BuildEBuildDictionary(overlays, all, packages): | 147 def _BuildEBuildDictionary(overlays, all, packages): |
| 143 """Build a dictionary of the ebuilds in the specified overlays. | 148 """Build a dictionary of the ebuilds in the specified overlays. |
| 144 | 149 |
| 145 overlays: A map which maps overlay directories to arrays of stable EBuilds | 150 overlays: A map which maps overlay directories to arrays of stable EBuilds |
| 146 inside said directories. | 151 inside said directories. |
| 147 all: Whether to include all ebuilds in the specified directories. If true, | 152 all: Whether to include all ebuilds in the specified directories. If true, |
| 148 then we gather all packages in the directories regardless of whether | 153 then we gather all packages in the directories regardless of whether |
| 149 they are in our set of packages. | 154 they are in our set of packages. |
| 150 packages: A set of the packages we want to gather. | 155 packages: A set of the packages we want to gather. |
| 151 """ | 156 """ |
| 152 for overlay in overlays: | 157 for overlay in overlays: |
| 153 for package_dir, dirs, files in os.walk(overlay): | 158 for package_dir, dirs, files in os.walk(overlay): |
| 154 # Add stable ebuilds to overlays[overlay]. | 159 # Add stable ebuilds to overlays[overlay]. |
| 155 paths = [os.path.join(package_dir, path) for path in files] | 160 paths = [os.path.join(package_dir, path) for path in files] |
| 156 ebuild = _FindStableEBuilds(paths) | 161 ebuild = _FindUprevCandidates(paths) |
| 157 | 162 |
| 158 # If the --all option isn't used, we only want to update packages that | 163 # If the --all option isn't used, we only want to update packages that |
| 159 # are in packages. | 164 # are in packages. |
| 160 if ebuild and (all or ebuild.package in packages): | 165 if ebuild and (all or ebuild.package in packages): |
| 161 overlays[overlay].append(ebuild) | 166 overlays[overlay].append(ebuild) |
| 162 | 167 |
| 163 | 168 |
| 164 def _CheckOnStabilizingBranch(): | 169 def _CheckOnStabilizingBranch(): |
| 165 """Returns true if the git branch is on the stabilizing branch.""" | 170 """Returns true if the git branch is on the stabilizing branch.""" |
| 166 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] | 171 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 (ebuild_no_rev, _, rev_string) = ebuild_path.rpartition('-') | 375 (ebuild_no_rev, _, rev_string) = ebuild_path.rpartition('-') |
| 371 | 376 |
| 372 # Verify the revision string starts with the revision character. | 377 # Verify the revision string starts with the revision character. |
| 373 if rev_string.startswith('r'): | 378 if rev_string.startswith('r'): |
| 374 # Get the ebuild name without the revision and version strings. | 379 # Get the ebuild name without the revision and version strings. |
| 375 ebuild_no_version = ebuild_no_rev.rpartition('-')[0] | 380 ebuild_no_version = ebuild_no_rev.rpartition('-')[0] |
| 376 rev_string = rev_string[1:].rpartition('.ebuild')[0] | 381 rev_string = rev_string[1:].rpartition('.ebuild')[0] |
| 377 else: | 382 else: |
| 378 # Has no revision so we stripped the version number instead. | 383 # Has no revision so we stripped the version number instead. |
| 379 ebuild_no_version = ebuild_no_rev | 384 ebuild_no_version = ebuild_no_rev |
| 380 ebuild_no_rev = ebuild_path.rpartition('.ebuild')[0] | 385 ebuild_no_rev = ebuild_path.rpartition('9999.ebuild')[0] + '0.0.1' |
| 381 rev_string = "0" | 386 rev_string = '0' |
| 382 revision = int(rev_string) | 387 revision = int(rev_string) |
| 383 return (ebuild_no_rev, ebuild_no_version, revision) | 388 return (ebuild_no_rev, ebuild_no_version, revision) |
| 384 | 389 |
| 385 | 390 |
| 386 class EBuildStableMarker(object): | 391 class EBuildStableMarker(object): |
| 387 """Class that revs the ebuild and commits locally or pushes the change.""" | 392 """Class that revs the ebuild and commits locally or pushes the change.""" |
| 388 | 393 |
| 389 def __init__(self, ebuild): | 394 def __init__(self, ebuild): |
| 390 self._ebuild = ebuild | 395 self._ebuild = ebuild |
| 391 | 396 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 old_ebuild_path = self._ebuild.ebuild_path | 446 old_ebuild_path = self._ebuild.ebuild_path |
| 442 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_ebuild_path] | 447 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_ebuild_path] |
| 443 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, | 448 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, |
| 444 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): | 449 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): |
| 445 os.unlink(new_ebuild_path) | 450 os.unlink(new_ebuild_path) |
| 446 return False | 451 return False |
| 447 else: | 452 else: |
| 448 _Print('Adding new stable ebuild to git') | 453 _Print('Adding new stable ebuild to git') |
| 449 _SimpleRunCommand('git add %s' % new_ebuild_path) | 454 _SimpleRunCommand('git add %s' % new_ebuild_path) |
| 450 | 455 |
| 451 _Print('Removing old ebuild from git') | 456 if self._ebuild.is_stable: |
| 452 _SimpleRunCommand('git rm %s' % old_ebuild_path) | 457 _Print('Removing old ebuild from git') |
| 458 _SimpleRunCommand('git rm %s' % old_ebuild_path) |
| 459 |
| 453 return True | 460 return True |
| 454 | 461 |
| 455 def CommitChange(self, message): | 462 def CommitChange(self, message): |
| 456 """Commits current changes in git locally. | 463 """Commits current changes in git locally. |
| 457 | 464 |
| 458 This method will take any changes from invocations to RevEBuild | 465 This method will take any changes from invocations to RevEBuild |
| 459 and commits them locally in the git repository that contains os.pwd. | 466 and commits them locally in the git repository that contains os.pwd. |
| 460 | 467 |
| 461 Args: | 468 Args: |
| 462 message: the commit string to write when committing to git. | 469 message: the commit string to write when committing to git. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 raise | 535 raise |
| 529 | 536 |
| 530 if revved_packages: | 537 if revved_packages: |
| 531 _CleanStalePackages(gflags.FLAGS.board, revved_packages) | 538 _CleanStalePackages(gflags.FLAGS.board, revved_packages) |
| 532 else: | 539 else: |
| 533 work_branch.Delete() | 540 work_branch.Delete() |
| 534 | 541 |
| 535 | 542 |
| 536 if __name__ == '__main__': | 543 if __name__ == '__main__': |
| 537 main(sys.argv) | 544 main(sys.argv) |
| OLD | NEW |