OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """ | |
7 Script to set v8's version file to the version given by the latest tag. | |
8 """ | |
9 | |
10 | |
11 import os | |
12 import re | |
13 import subprocess | |
14 import sys | |
15 | |
16 | |
17 CWD = os.path.abspath( | |
18 os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) | |
19 VERSION_CC = os.path.join(CWD, "src", "version.cc") | |
20 | |
21 def Main(): | |
tandrii_google
2015/01/05 14:46:09
nit: why capitalized?
| |
22 tag = subprocess.check_output( | |
23 "git describe --tags", | |
24 shell=True, | |
25 cwd=CWD, | |
26 ).strip() | |
27 assert tag | |
28 | |
29 # Check for commits not exactly matching a tag. Those are candidate builds | |
30 # for the next version. The output has the form | |
31 # <tag name>-<n commits>-<hash>. | |
32 if "-" in tag: | |
33 version = tag.split("-")[0] | |
34 candidate = "1" | |
35 else: | |
36 version = tag | |
37 candidate = "0" | |
38 version_levels = version.split(".") | |
39 | |
40 # Set default patch level if none is given. | |
41 if len(version_levels) == 3: | |
42 version_levels.append("0") | |
43 assert len(version_levels) == 4 | |
44 | |
45 major, minor, build, patch = version_levels | |
46 | |
47 # Increment build level for candidate builds. | |
48 if candidate == "1": | |
49 build = str(int(build) + 1) | |
50 patch = "0" | |
51 | |
52 # Modify version.cc with the new values. | |
53 with open(VERSION_CC, "r") as f: | |
tandrii_google
2015/01/05 14:46:09
yes, this "with" statement is important on Windows
| |
54 text = f.read() | |
55 def Sub(line, definition, substitute): | |
tandrii_google
2015/01/05 14:46:09
i wouldn't make this a function
| |
56 if line.startswith("#define %s" % definition): | |
57 return re.sub("\d+$", substitute, line) | |
58 return line | |
59 output = [] | |
60 for line in text.split("\n"): | |
61 for definition, substitute in ( | |
62 ("MAJOR_VERSION", major), | |
63 ("MINOR_VERSION", minor), | |
64 ("BUILD_NUMBER", build), | |
65 ("PATCH_LEVEL", patch), | |
66 ("IS_CANDIDATE_VERSION", candidate)): | |
67 line = Sub(line, definition, substitute) | |
68 output.append(line) | |
69 with open(VERSION_CC, "w") as f: | |
70 f.write("\n".join(output)) | |
71 | |
72 # Log what was done. | |
73 candidate_txt = " (candidate)" if candidate == "1" else "" | |
74 patch_txt = ".%s" % patch if patch != "0" else "" | |
75 version_txt = ("%s.%s.%s%s%s" % | |
76 (major, minor, build, patch_txt, candidate_txt)) | |
77 print "Modified version.cc. Set V8 version to %s" % version_txt | |
78 return 0 | |
79 | |
80 if __name__ == "__main__": | |
81 sys.exit(Main()) | |
OLD | NEW |