assert name
self.Git(MakeArgs(["checkout -f", name]))
- def GitCheckoutFile(self, name, branch):
+ def GitCheckoutFile(self, name, branch_or_hash):
assert name
- assert branch
- self.Git(MakeArgs(["checkout -f", branch, "--", name]))
+ assert branch_or_hash
+ self.Git(MakeArgs(["checkout -f", branch_or_hash, "--", name]))
@Strip
def GitCurrentBranch(self):
self["last_push_bleeding_edge"] = last_push_bleeding_edge
+class IncrementVersion(Step):
+ MESSAGE = "Increment version number."
+
+ def RunStep(self):
+ # Retrieve current version from last trunk push.
+ self.GitCheckoutFile(self.Config(VERSION_FILE), self["last_push_trunk"])
+ self.ReadAndPersistVersion()
+
+ if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will "
+ "fire up your EDITOR on %s so you can make arbitrary "
+ "changes. When you're done, save the file and exit your "
+ "EDITOR.)" % self.Config(VERSION_FILE))):
+ text = FileToText(self.Config(VERSION_FILE))
+ text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
+ r"\g<space>%s" % str(int(self["build"]) + 1),
+ text)
+ TextToFile(text, self.Config(VERSION_FILE))
+ else:
+ self.Editor(self.Config(VERSION_FILE))
+
+ # Variables prefixed with 'new_' contain the new version numbers for the
+ # ongoing trunk push.
+ self.ReadAndPersistVersion("new_")
+ self["version"] = "%s.%s.%s" % (self["new_major"],
+ self["new_minor"],
+ self["new_build"])
+
+ # TODO(machenbach): The following will be deprecated. Increment version
+ # numbers for version.cc on bleeding_edge (new build level on trunk + 1).
+ text = FileToText(self.Config(VERSION_FILE))
+ text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
+ r"\g<space>%s" % str(int(self["new_build"]) + 1),
+ text)
+ TextToFile(text, self.Config(VERSION_FILE))
+ self.ReadAndPersistVersion("new_be_")
+
+
class PrepareChangeLog(Step):
MESSAGE = "Prepare raw ChangeLog entry."
return body
def RunStep(self):
- # These version numbers are used again later for the trunk commit.
- self.ReadAndPersistVersion()
self["date"] = self.GetDate()
- self["version"] = "%s.%s.%s" % (self["major"],
- self["minor"],
- self["build"])
- output = "%s: Version %s\n\n" % (self["date"],
- self["version"])
+ output = "%s: Version %s\n\n" % (self["date"], self["version"])
TextToFile(output, self.Config(CHANGELOG_ENTRY_FILE))
commits = self.GitLog(format="%H",
git_hash="%s..HEAD" % self["last_push_bleeding_edge"])
TextToFile(changelog_entry, self.Config(CHANGELOG_ENTRY_FILE))
-class IncrementVersion(Step):
- MESSAGE = "Increment version number."
-
- def RunStep(self):
- new_build = str(int(self["build"]) + 1)
-
- if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will "
- "fire up your EDITOR on %s so you can make arbitrary "
- "changes. When you're done, save the file and exit your "
- "EDITOR.)" % self.Config(VERSION_FILE))):
- text = FileToText(self.Config(VERSION_FILE))
- text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
- r"\g<space>%s" % new_build,
- text)
- TextToFile(text, self.Config(VERSION_FILE))
- else:
- self.Editor(self.Config(VERSION_FILE))
-
- self.ReadAndPersistVersion("new_")
-
-
class CommitLocal(Step):
MESSAGE = "Commit to local branch."
def RunStep(self):
self["prep_commit_msg"] = ("Prepare push to trunk. "
- "Now working on version %s.%s.%s." % (self["new_major"],
- self["new_minor"],
- self["new_build"]))
+ "Now working on version %s.%s.%s." % (self["new_be_major"],
+ self["new_be_minor"],
+ self["new_be_build"]))
# Include optional TBR only in the git command. The persisted commit
# message is used for finding the commit again later.
output = ""
for line in FileToText(self.Config(VERSION_FILE)).splitlines():
if line.startswith("#define MAJOR_VERSION"):
- line = re.sub("\d+$", self["major"], line)
+ line = re.sub("\d+$", self["new_major"], line)
elif line.startswith("#define MINOR_VERSION"):
- line = re.sub("\d+$", self["minor"], line)
+ line = re.sub("\d+$", self["new_minor"], line)
elif line.startswith("#define BUILD_NUMBER"):
- line = re.sub("\d+$", self["build"], line)
+ line = re.sub("\d+$", self["new_build"], line)
elif line.startswith("#define PATCH_LEVEL"):
line = re.sub("\d+$", "0", line)
elif line.startswith("#define IS_CANDIDATE_VERSION"):
Preparation,
FreshBranch,
DetectLastPush,
+ IncrementVersion,
PrepareChangeLog,
EditChangeLog,
- IncrementVersion,
CommitLocal,
UploadStep,
CommitRepository,
self._tmp_files.append(name)
return name
- def WriteFakeVersionFile(self):
+ def WriteFakeVersionFile(self, build=4):
with open(TEST_CONFIG[VERSION_FILE], "w") as f:
f.write(" // Some line...\n")
f.write("\n")
f.write("#define MAJOR_VERSION 3\n")
f.write("#define MINOR_VERSION 22\n")
- f.write("#define BUILD_NUMBER 5\n")
+ f.write("#define BUILD_NUMBER %s\n" % build)
f.write("#define PATCH_LEVEL 0\n")
f.write(" // Some line...\n")
f.write("#define IS_CANDIDATE_VERSION 0\n")
def testReadAndPersistVersion(self):
TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
- self.WriteFakeVersionFile()
+ self.WriteFakeVersionFile(build=5)
step = self.MakeStep()
step.ReadAndPersistVersion()
self.assertEquals("3", step["major"])
])
self._state["last_push_bleeding_edge"] = "1234"
+ self._state["version"] = "3.22.5"
self.RunStep(PushToTrunk, PrepareChangeLog)
actual_cl = FileToText(TEST_CONFIG[CHANGELOG_ENTRY_FILE])
#"""
self.assertEquals(expected_cl, actual_cl)
- self.assertEquals("3", self._state["major"])
- self.assertEquals("22", self._state["minor"])
- self.assertEquals("5", self._state["build"])
- self.assertEquals("0", self._state["patch"])
def testEditChangeLog(self):
TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
def testIncrementVersion(self):
TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
self.WriteFakeVersionFile()
- self._state["build"] = "5"
+ self._state["last_push_trunk"] = "hash1"
+
+ self.ExpectGit([
+ Git("checkout -f hash1 -- %s" % TEST_CONFIG[VERSION_FILE], "")
+ ])
self.ExpectReadline([
RL("Y"), # Increment build number.
self.assertEquals("3", self._state["new_major"])
self.assertEquals("22", self._state["new_minor"])
- self.assertEquals("6", self._state["new_build"])
+ self.assertEquals("5", self._state["new_build"])
self.assertEquals("0", self._state["new_patch"])
def _TestSquashCommits(self, change_log, expected_msg):
def _PushToTrunk(self, force=False, manual=False):
TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+
+ # The version file on bleeding edge has build level 5, while the version
+ # file from trunk has build level 4.
TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
- self.WriteFakeVersionFile()
+ self.WriteFakeVersionFile(build=5)
+
TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
TEST_CONFIG[CHANGELOG_FILE] = self.MakeEmptyTempFile()
if not os.path.exists(TEST_CONFIG[CHROMIUM]):
Git("log -1 --format=%s hash2",
"Version 3.4.5 (based on bleeding_edge revision r1234)\n"),
Git("svn find-rev r1234", "hash3\n"),
+ Git("checkout -f hash2 -- %s" % TEST_CONFIG[VERSION_FILE], "",
+ cb=self.WriteFakeVersionFile),
Git("log --format=%H hash3..HEAD", "rev1\n"),
Git("log -1 --format=%s rev1", "Log text 1.\n"),
Git("log -1 --format=%B rev1", "Text\nLOG=YES\nBUG=v8:321\nText\n"),
TEST_CONFIG[ALREADY_MERGING_SENTINEL_FILE] = self.MakeEmptyTempFile()
TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile()
- self.WriteFakeVersionFile()
+ self.WriteFakeVersionFile(build=5)
os.environ["EDITOR"] = "vi"
extra_patch = self.MakeEmptyTempFile()