CHANGELOG_FILE = "ChangeLog"
VERSION_FILE = os.path.join("src", "version.cc")
+VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:\.\d+)?$")
# V8 base directory.
V8_BASE = os.path.dirname(
def __getitem__(self, key):
# Convenience method to allow direct [] access on step classes for
# manipulating the backed state dict.
- return self._state[key]
+ return self._state.get(key)
def __setitem__(self, key, value):
# Convenience method to allow direct [] access on step classes for
except GitFailedException:
self.WaitForResolvingConflicts(patch_file)
+ def GetLatestVersion(self):
+ # Use cached version if available.
+ if self["latest_version"]:
+ return self["latest_version"]
+
+ # Make sure tags are fetched.
+ self.Git("fetch origin +refs/tags/*:refs/tags/*")
+ version_parts = sorted(filter(VERSION_RE.match, self.vc.GetTags()),
+ key=SortingKey, reverse=True)[0].split(".")
+ if len(version_parts) == 3:
+ version_parts.append("0")
+ self["latest_version"] = ".".join(version_parts)
+ return self["latest_version"]
+
def FindLastCandidatesPush(
self, parent_hash="", branch="", include_patches=False):
push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*"
self.InitialEnvironmentChecks(self.default_cwd)
self.CommonPrepare()
- # Make sure tags are fetched.
- self.Git("fetch origin +refs/tags/*:refs/tags/*")
-
if(self["current_branch"] == self.Config("CANDIDATESBRANCH")
or self["current_branch"] == self.Config("BRANCHNAME")):
print "Warning: Script started on branch %s" % self["current_branch"]
self["last_push_master"] = last_push_master
-class GetLatestVersion(Step):
- MESSAGE = "Get latest version from tags."
+class IncrementVersion(Step):
+ MESSAGE = "Increment version number."
def RunStep(self):
- versions = sorted(filter(VERSION_RE.match, self.vc.GetTags()),
- key=SortingKey, reverse=True)
- self.StoreVersion(versions[0], "latest_")
- self["latest_version"] = self.ArrayToVersion("latest_")
+ latest_version = self.GetLatestVersion()
# The version file on master can be used to bump up major/minor at
# branch time.
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
self.ReadAndPersistVersion("master_")
- self["master_version"] = self.ArrayToVersion("master_")
-
- if SortingKey(self["master_version"]) > SortingKey(self["latest_version"]):
- self["latest_version"] = self["master_version"]
- self.StoreVersion(self["latest_version"], "latest_")
-
- print "Determined latest version %s" % self["latest_version"]
+ master_version = self.ArrayToVersion("master_")
+ # Use the highest version from master or from tags to determine the new
+ # version.
+ authoritative_version = sorted(
+ [master_version, latest_version], key=SortingKey)[1]
+ self.StoreVersion(authoritative_version, "authoritative_")
-class IncrementVersion(Step):
- MESSAGE = "Increment version number."
-
- def RunStep(self):
# Variables prefixed with 'new_' contain the new version numbers for the
# ongoing candidates push.
- self["new_major"] = self["latest_major"]
- self["new_minor"] = self["latest_minor"]
- self["new_build"] = str(int(self["latest_build"]) + 1)
+ self["new_major"] = self["authoritative_major"]
+ self["new_minor"] = self["authoritative_minor"]
+ self["new_build"] = str(int(self["authoritative_build"]) + 1)
# Make sure patch level is 0 in a new push.
self["new_patch"] = "0"
self["new_minor"],
self["new_build"])
+ print ("Incremented version to %s" % self["version"])
+
class PrepareChangeLog(Step):
MESSAGE = "Prepare raw ChangeLog entry."
FreshBranch,
PreparePushRevision,
DetectLastPush,
- GetLatestVersion,
IncrementVersion,
PrepareChangeLog,
EditChangeLog,
# Version as tag: 3.22.4.0. Version on master: 3.22.6.
# Make sure that the latest version is 3.22.6.0.
- def testGetLatestVersion(self):
+ def testIncrementVersion(self):
self.Expect([
+ Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=lambda: self.WriteFakeVersionFile(22, 6)),
])
- self.RunStep(PushToCandidates, GetLatestVersion)
+ self.RunStep(PushToCandidates, IncrementVersion)
- self.assertEquals("3", self._state["latest_major"])
- self.assertEquals("22", self._state["latest_minor"])
- self.assertEquals("6", self._state["latest_build"])
- self.assertEquals("0", self._state["latest_patch"])
+ self.assertEquals("3", self._state["new_major"])
+ self.assertEquals("22", self._state["new_minor"])
+ self.assertEquals("7", self._state["new_build"])
+ self.assertEquals("0", self._state["new_patch"])
def _TestSquashCommits(self, change_log, expected_msg):
TEST_CONFIG["CHANGELOG_ENTRY_FILE"] = self.MakeEmptyTempFile()
Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"),
Cmd("git fetch", ""),
- Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git branch", " branch1\n* branch2\n"),
Cmd("git branch", " branch1\n* branch2\n"),
Cmd(("git new-branch %s --upstream origin/master" %
expectations += [
Cmd("git log -1 --format=%s hash2",
"Version 3.4.5 (based on abc3)\n"),
+ Cmd("git fetch origin +refs/tags/*:refs/tags/*", ""),
Cmd("git tag", self.TAGS),
Cmd("git checkout -f origin/master -- src/version.cc",
"", cb=self.WriteFakeVersionFile),