Commit 9ae1c238 authored by machenbach's avatar machenbach Committed by Commit bot

Make version generation robust to other user-defined tags.

BUG=chromium:446166
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#26224}
parent 037c7397
......@@ -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
......
......@@ -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
S(MAJOR_VERSION) "." S(MINOR_VERSION) "." S(BUILD_NUMBER) SUFFIX_STRING
#endif
namespace v8 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment