Revision: 20071
Author:   [email protected]
Date:     Wed Mar 19 13:10:41 2014 UTC
Log:      Retrieve current version from trunk branch in push-to-trunk.

- 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=
[email protected]

Review URL: https://codereview.chromium.org/203773013
http://code.google.com/p/v8/source/detail?r=20071

Modified:
 /branches/bleeding_edge/tools/push-to-trunk/git_recipes.py
 /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py
 /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py

=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/git_recipes.py Mon Mar 17 13:52:33 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/git_recipes.py Wed Mar 19 13:10:41 2014 UTC
@@ -63,10 +63,10 @@
     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):
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Mar 19 10:46:24 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Mar 19 13:10:41 2014 UTC
@@ -110,6 +110,43 @@
     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 @@
     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 @@
     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 @@
     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 @@
       Preparation,
       FreshBranch,
       DetectLastPush,
+      IncrementVersion,
       PrepareChangeLog,
       EditChangeLog,
-      IncrementVersion,
       CommitLocal,
       UploadStep,
       CommitRepository,
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Wed Mar 19 10:46:24 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Wed Mar 19 13:10:41 2014 UTC
@@ -294,13 +294,13 @@
     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 @@

   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 @@
     ])

     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 @@
 #"""

     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 @@
   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 @@

     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 @@

   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 @@
       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 @@
     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()

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to