diff --git a/cros_mark_as_stable.py b/cros_mark_as_stable.py index 9a3ab5221c..56a589c682 100755 --- a/cros_mark_as_stable.py +++ b/cros_mark_as_stable.py @@ -93,8 +93,12 @@ def _BestEBuild(ebuilds): return winner -def _FindStableEBuilds(files): - """Return a list of stable ebuilds from specified list of files. +def _FindUprevCandidates(files): + """Return a list of uprev candidates from specified list of files. + + Usually an uprev candidate is a the stable ebuild in a cros_workon directory. + However, if no such stable ebuild exists (someone just checked in the 9999 + ebuild), this is the unstable ebuild. Args: files: List of files. @@ -131,7 +135,8 @@ def _FindStableEBuilds(files): if not unstable_ebuilds: Die('Missing 9999 ebuild in %s' % os.path.dirname(path)) if not stable_ebuilds: - Die('Missing stable ebuild in %s' % os.path.dirname(path)) + Warning('Missing stable ebuild in %s' % os.path.dirname(path)) + return unstable_ebuilds[0] if stable_ebuilds: return stable_ebuilds[0] @@ -153,7 +158,7 @@ def _BuildEBuildDictionary(overlays, all, packages): for package_dir, dirs, files in os.walk(overlay): # Add stable ebuilds to overlays[overlay]. paths = [os.path.join(package_dir, path) for path in files] - ebuild = _FindStableEBuilds(paths) + ebuild = _FindUprevCandidates(paths) # If the --all option isn't used, we only want to update packages that # are in packages. @@ -377,8 +382,8 @@ class _EBuild(object): else: # Has no revision so we stripped the version number instead. ebuild_no_version = ebuild_no_rev - ebuild_no_rev = ebuild_path.rpartition('.ebuild')[0] - rev_string = "0" + ebuild_no_rev = ebuild_path.rpartition('9999.ebuild')[0] + '0.0.1' + rev_string = '0' revision = int(rev_string) return (ebuild_no_rev, ebuild_no_version, revision) @@ -448,8 +453,10 @@ class EBuildStableMarker(object): _Print('Adding new stable ebuild to git') _SimpleRunCommand('git add %s' % new_ebuild_path) - _Print('Removing old ebuild from git') - _SimpleRunCommand('git rm %s' % old_ebuild_path) + if self._ebuild.is_stable: + _Print('Removing old ebuild from git') + _SimpleRunCommand('git rm %s' % old_ebuild_path) + return True def CommitChange(self, message): diff --git a/cros_mark_as_stable_unittest.py b/cros_mark_as_stable_unittest.py index 73985ae4d2..e7fd3317b2 100755 --- a/cros_mark_as_stable_unittest.py +++ b/cros_mark_as_stable_unittest.py @@ -125,7 +125,7 @@ class EBuildTest(mox.MoxTestBase): def testParseEBuildPathNoRevisionNumber(self): # Test with ebuild without revision number. no_rev, no_version, revision = cros_mark_as_stable._EBuild._ParseEBuildPath( - '/path/test_package-0.0.1.ebuild') + '/path/test_package-9999.ebuild') self.assertEquals(no_rev, '/path/test_package-0.0.1') self.assertEquals(no_version, '/path/test_package') self.assertEquals(revision, 0) @@ -139,6 +139,7 @@ class EBuildStableMarkerTest(mox.MoxTestBase): self.mox.StubOutWithMock(cros_mark_as_stable, 'RunCommand') self.mox.StubOutWithMock(os, 'unlink') self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable._EBuild) + self.m_ebuild.is_stable = True self.m_ebuild.package = 'test_package' self.m_ebuild.current_revision = 1 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1' @@ -281,13 +282,13 @@ class BuildEBuildDictionaryTest(mox.MoxTestBase): self.package_path = self.root + '/test_package-0.0.1.ebuild' paths = [[self.root, [], []]] cros_mark_as_stable.os.walk("/overlay").AndReturn(paths) - self.mox.StubOutWithMock(cros_mark_as_stable, '_FindStableEBuilds') + self.mox.StubOutWithMock(cros_mark_as_stable, '_FindUprevCandidates') def testWantedPackage(self): overlays = {"/overlay": []} package = _Package(self.package) - cros_mark_as_stable._FindStableEBuilds([]).AndReturn(package) + cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package) self.mox.ReplayAll() cros_mark_as_stable._BuildEBuildDictionary(overlays, False, [self.package]) self.mox.VerifyAll() @@ -297,7 +298,7 @@ class BuildEBuildDictionaryTest(mox.MoxTestBase): def testUnwantedPackage(self): overlays = {"/overlay": []} package = _Package(self.package) - cros_mark_as_stable._FindStableEBuilds([]).AndReturn(package) + cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package) self.mox.ReplayAll() cros_mark_as_stable._BuildEBuildDictionary(overlays, False, []) self.assertEquals(len(overlays), 1)