Reviewers: Jakob, tandrii(chromium),

Message:
PTAL

Description:
Make version generation robust to other user-defined tags.

BUG=chromium:446166
LOG=n

Please review this at https://codereview.chromium.org/865153003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+45, -18 lines):
  M build/generate_version.py
  M src/version.cc


Index: build/generate_version.py
diff --git a/build/generate_version.py b/build/generate_version.py
index 3f113782068e833935e3d932f1beafd91b70e6c6..930e4857fb7defa4739450353e7049c2f9879845 100755
--- a/build/generate_version.py
+++ b/build/generate_version.py
@@ -26,6 +26,9 @@ CWD = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 VERSION_CC = os.path.join(CWD, "src", "version.cc")
 VERSION_GEN_CC = os.path.join(CWD, "src", "version_gen.cc")

+VERSION_RE_RAW = r"^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<build>\d+)"
+VERSION_RE = re.compile(VERSION_RE_RAW + r"$")
+VERSION_WITH_PATCH_RE = re.compile(VERSION_RE_RAW + r"\.(?P<patch>\d+)$")

 def generate_version_file():
   # Make sure the tags are fetched from cached git repos.
@@ -54,17 +57,33 @@ def generate_version_file():
   else:
     version = tag
     candidate = "0"
-  version_levels = version.split(".")

-  # Set default patch level if none is given.
-  if len(version_levels) == 3:
-    version_levels.append("0")
-  assert len(version_levels) == 4
-
-  major, minor, build, patch = version_levels
+  match = VERSION_RE.match(version)
+  match_patch = VERSION_WITH_PATCH_RE.match(version)
+  if match:
+    # Simple version e.g. "3.30.5".
+    major = match.group("major")
+    minor = match.group("minor")
+    build = match.group("build")
+    patch = "0"
+    invalid = "0"
+  elif match_patch:
+    # Version with patch level e.g. "3.30.5.2".
+    major = match.group("major")
+    minor = match.group("minor")
+    build = match.group("build")
+    patch = match.group("patch")
+    invalid = "0"
+  else:
+    # A tag was found that's not a version string.
+    major = "0"
+    minor = "0"
+    build = "0"
+    patch = "0"
+    invalid = "1"

   # Increment build level for candidate builds.
-  if candidate == "1":
+  if candidate == "1" and invalid != "1":
     build = str(int(build) + 1)
     patch = "0"

@@ -77,16 +96,18 @@ def generate_version_file():
           ("MINOR_VERSION", minor),
           ("BUILD_NUMBER", build),
           ("PATCH_LEVEL", patch),
-          ("IS_CANDIDATE_VERSION", candidate)):
+          ("IS_CANDIDATE_VERSION", candidate),
+          ("IS_INVALID_VERSION", invalid)):
         if line.startswith("#define %s" % definition):
           line =  re.sub("\d+$", substitute, line)
       output.append(line)

   # Prepare log message.
-  candidate_txt = " (candidate)" if candidate == "1" else ""
+  suffix_txt = " (candidate)" if candidate == "1" else ""
+  suffix_txt = " (invalid)" if invalid == "1" else suffix_txt
   patch_txt = ".%s" % patch if patch != "0" else ""
   version_txt = ("%s.%s.%s%s%s" %
-                 (major, minor, build, patch_txt, candidate_txt))
+                 (major, minor, build, patch_txt, suffix_txt))
log_message = "Modifying version_gen.cc. Set V8 version to %s" % version_txt
   return "".join(output), log_message

Index: src/version.cc
diff --git a/src/version.cc b/src/version.cc
index d7c937c7aac7e18835fbbcde311ca6889e4b2b9d..300f1731fd8ef3cd4e147762cc465d4ee5498464 100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -17,15 +17,22 @@
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 1

+// Used to mark a version built from a bad tag.
+#define IS_INVALID_VERSION 0
+
 // Define SONAME to have the build system put a specific SONAME into the
 // shared library instead the generic SONAME generated from the V8 version
 // number. This define is mainly used by the build system script.
 #define SONAME            ""

+#if IS_INVALID_VERSION
+#define SUFFIX_STRING " (invalid)"
+#else
 #if IS_CANDIDATE_VERSION
-#define CANDIDATE_STRING " (candidate)"
+#define SUFFIX_STRING " (candidate)"
 #else
-#define CANDIDATE_STRING ""
+#define SUFFIX_STRING ""
+#endif
 #endif

 #define SX(x) #x
@@ -33,12 +40,11 @@

 #if PATCH_LEVEL > 0
#define VERSION_STRING \ - S(MAJOR_VERSION) "." S(MINOR_VERSION) "." S(BUILD_NUMBER) "." \
-        S(PATCH_LEVEL) CANDIDATE_STRING
+ S(MAJOR_VERSION) "." S(MINOR_VERSION) "." S(BUILD_NUMBER) "." S(PATCH_LEVEL) \
+      SUFFIX_STRING
 #else
-#define VERSION_STRING \ - S(MAJOR_VERSION) "." S(MINOR_VERSION) "." S(BUILD_NUMBER) \
-        CANDIDATE_STRING
+#define VERSION_STRING \
+  S(MAJOR_VERSION) "." S(MINOR_VERSION) "." S(BUILD_NUMBER) SUFFIX_STRING
 #endif

 namespace v8 {


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