Retrieve current version from trunk branch in push-to-trunk.
authormachenbach@chromium.org <machenbach@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 19 Mar 2014 13:10:41 +0000 (13:10 +0000)
committermachenbach@chromium.org <machenbach@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 19 Mar 2014 13:10:41 +0000 (13:10 +0000)
- This moves retrieving and incrementing the version before creating the change log
- Before the prepare push commit will be deprecated (follow up CL), the script deals with 3 build levels. X: the current build level on the last trunk push. X + 1: the build level for this trunk push. X + 2: the build level of the new version file on bleeding edge (to be deprecated).

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/203773013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20071 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

tools/push-to-trunk/git_recipes.py
tools/push-to-trunk/push_to_trunk.py
tools/push-to-trunk/test_scripts.py

index 7d9c402..8e84d45 100644 (file)
@@ -63,10 +63,10 @@ class GitRecipesMixin(object):
     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):
index fe45610..9d17a45 100755 (executable)
@@ -110,6 +110,43 @@ class DetectLastPush(Step):
     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."
 
@@ -132,14 +169,8 @@ class PrepareChangeLog(Step):
     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"])
@@ -191,35 +222,14 @@ class EditChangeLog(Step):
     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.
@@ -329,11 +339,11 @@ class SetVersion(Step):
     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"):
@@ -529,9 +539,9 @@ class PushToTrunk(ScriptsBase):
       Preparation,
       FreshBranch,
       DetectLastPush,
+      IncrementVersion,
       PrepareChangeLog,
       EditChangeLog,
-      IncrementVersion,
       CommitLocal,
       UploadStep,
       CommitRepository,
index 1208c52..d6fa5c9 100644 (file)
@@ -294,13 +294,13 @@ class ScriptTest(unittest.TestCase):
     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")
@@ -440,7 +440,7 @@ class ScriptTest(unittest.TestCase):
 
   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"])
@@ -499,6 +499,7 @@ class ScriptTest(unittest.TestCase):
     ])
 
     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])
@@ -530,10 +531,6 @@ class ScriptTest(unittest.TestCase):
 #"""
 
     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()
@@ -552,7 +549,11 @@ class ScriptTest(unittest.TestCase):
   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.
@@ -562,7 +563,7 @@ class ScriptTest(unittest.TestCase):
 
     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):
@@ -619,8 +620,12 @@ Performance and stability improvements on all platforms."""
 
   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]):
@@ -698,6 +703,8 @@ Performance and stability improvements on all platforms.""", commit)
       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"),
@@ -886,7 +893,7 @@ Performance and stability improvements on all platforms.""", commit)
     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()