Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: build/generate_version.py

Issue 865153003: Make version generation robust to other user-defined tags. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/version.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 the V8 project authors. All rights reserved. 2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Script to set v8's version file to the version given by the latest tag. 7 Script to set v8's version file to the version given by the latest tag.
8 8
9 The script is intended to be run as a gclient hook. The script will write a 9 The script is intended to be run as a gclient hook. The script will write a
10 generated version file into the checkout. 10 generated version file into the checkout.
11 11
12 On build systems where no git is available and where the version information 12 On build systems where no git is available and where the version information
13 is not necessary, the version generation can be bypassed with the option 13 is not necessary, the version generation can be bypassed with the option
14 --skip. 14 --skip.
15 """ 15 """
16 16
17 17
18 import optparse 18 import optparse
19 import os 19 import os
20 import re 20 import re
21 import subprocess 21 import subprocess
22 import sys 22 import sys
23 23
24 24
25 CWD = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 25 CWD = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
26 VERSION_CC = os.path.join(CWD, "src", "version.cc") 26 VERSION_CC = os.path.join(CWD, "src", "version.cc")
27 VERSION_GEN_CC = os.path.join(CWD, "src", "version_gen.cc") 27 VERSION_GEN_CC = os.path.join(CWD, "src", "version_gen.cc")
28 28
29 VERSION_RE_RAW = r"^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<build>\d+)"
30 VERSION_RE = re.compile(VERSION_RE_RAW + r"$")
31 VERSION_WITH_PATCH_RE = re.compile(VERSION_RE_RAW + r"\.(?P<patch>\d+)$")
29 32
30 def generate_version_file(): 33 def generate_version_file():
31 # Make sure the tags are fetched from cached git repos. 34 # Make sure the tags are fetched from cached git repos.
32 url = subprocess.check_output( 35 url = subprocess.check_output(
33 "git config --get remote.origin.url", 36 "git config --get remote.origin.url",
34 shell=True, 37 shell=True,
35 cwd=CWD).strip() 38 cwd=CWD).strip()
36 if not url.startswith("http"): 39 if not url.startswith("http"):
37 subprocess.check_output( 40 subprocess.check_output(
38 "git fetch origin +refs/tags/*:refs/tags/*", 41 "git fetch origin +refs/tags/*:refs/tags/*",
39 shell=True, 42 shell=True,
40 cwd=CWD) 43 cwd=CWD)
41 tag = subprocess.check_output( 44 tag = subprocess.check_output(
42 "git describe --tags", 45 "git describe --tags",
43 shell=True, 46 shell=True,
44 cwd=CWD, 47 cwd=CWD,
45 ).strip() 48 ).strip()
46 assert tag 49 assert tag
47 50
48 # Check for commits not exactly matching a tag. Those are candidate builds 51 # Check for commits not exactly matching a tag. Those are candidate builds
49 # for the next version. The output has the form 52 # for the next version. The output has the form
50 # <tag name>-<n commits>-<hash>. 53 # <tag name>-<n commits>-<hash>.
51 if "-" in tag: 54 if "-" in tag:
52 version = tag.split("-")[0] 55 version = tag.split("-")[0]
53 candidate = "1" 56 candidate = "1"
54 else: 57 else:
55 version = tag 58 version = tag
56 candidate = "0" 59 candidate = "0"
57 version_levels = version.split(".")
58 60
59 # Set default patch level if none is given. 61 match = VERSION_RE.match(version)
60 if len(version_levels) == 3: 62 match_patch = VERSION_WITH_PATCH_RE.match(version)
61 version_levels.append("0") 63 if match:
62 assert len(version_levels) == 4 64 # Simple version e.g. "3.30.5".
63 65 major = match.group("major")
64 major, minor, build, patch = version_levels 66 minor = match.group("minor")
67 build = match.group("build")
68 patch = "0"
69 invalid = "0"
70 elif match_patch:
71 # Version with patch level e.g. "3.30.5.2".
72 major = match.group("major")
73 minor = match.group("minor")
74 build = match.group("build")
75 patch = match.group("patch")
76 invalid = "0"
77 else:
78 # A tag was found that's not a version string.
79 major = "0"
80 minor = "0"
81 build = "0"
82 patch = "0"
83 invalid = "1"
65 84
66 # Increment build level for candidate builds. 85 # Increment build level for candidate builds.
67 if candidate == "1": 86 if candidate == "1" and invalid != "1":
68 build = str(int(build) + 1) 87 build = str(int(build) + 1)
69 patch = "0" 88 patch = "0"
70 89
71 # Modify version_gen.cc with the new values. 90 # Modify version_gen.cc with the new values.
72 output = [] 91 output = []
73 with open(VERSION_CC, "r") as f: 92 with open(VERSION_CC, "r") as f:
74 for line in f: 93 for line in f:
75 for definition, substitute in ( 94 for definition, substitute in (
76 ("MAJOR_VERSION", major), 95 ("MAJOR_VERSION", major),
77 ("MINOR_VERSION", minor), 96 ("MINOR_VERSION", minor),
78 ("BUILD_NUMBER", build), 97 ("BUILD_NUMBER", build),
79 ("PATCH_LEVEL", patch), 98 ("PATCH_LEVEL", patch),
80 ("IS_CANDIDATE_VERSION", candidate)): 99 ("IS_CANDIDATE_VERSION", candidate),
100 ("IS_INVALID_VERSION", invalid)):
81 if line.startswith("#define %s" % definition): 101 if line.startswith("#define %s" % definition):
82 line = re.sub("\d+$", substitute, line) 102 line = re.sub("\d+$", substitute, line)
83 output.append(line) 103 output.append(line)
84 104
85 # Prepare log message. 105 # Prepare log message.
86 candidate_txt = " (candidate)" if candidate == "1" else "" 106 suffix_txt = " (candidate)" if candidate == "1" else ""
107 suffix_txt = " (invalid)" if invalid == "1" else suffix_txt
87 patch_txt = ".%s" % patch if patch != "0" else "" 108 patch_txt = ".%s" % patch if patch != "0" else ""
88 version_txt = ("%s.%s.%s%s%s" % 109 version_txt = ("%s.%s.%s%s%s" %
89 (major, minor, build, patch_txt, candidate_txt)) 110 (major, minor, build, patch_txt, suffix_txt))
90 log_message = "Modifying version_gen.cc. Set V8 version to %s" % version_txt 111 log_message = "Modifying version_gen.cc. Set V8 version to %s" % version_txt
91 return "".join(output), log_message 112 return "".join(output), log_message
92 113
93 114
94 def bypass_version_file(): 115 def bypass_version_file():
95 with open(VERSION_CC, "r") as f: 116 with open(VERSION_CC, "r") as f:
96 return f.read(), "Bypassing V8 version creation." 117 return f.read(), "Bypassing V8 version creation."
97 118
98 119
99 def main(): 120 def main():
(...skipping 19 matching lines...) Expand all
119 with open(VERSION_GEN_CC, "w") as f: 140 with open(VERSION_GEN_CC, "w") as f:
120 f.write(version_file_content) 141 f.write(version_file_content)
121 # Log what was calculated. 142 # Log what was calculated.
122 print log_message 143 print log_message
123 144
124 return 0 145 return 0
125 146
126 147
127 if __name__ == "__main__": 148 if __name__ == "__main__":
128 sys.exit(main()) 149 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | src/version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698