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

Side by Side Diff: build/generate_version.py

Issue 830093003: Partially reland Auto-generate v8 version based on tags. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review 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 | « Makefile ('k') | tools/push-to-trunk/generate_version.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 The script is intended to be run as a gclient hook. The script will write a
10 generated version file into the checkout.
11
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
14 --skip.
15 """
16
17
18 import optparse
19 import os
20 import re
21 import subprocess
22 import sys
23
24
25 CWD = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
26 VERSION_CC = os.path.join(CWD, "src", "version.cc")
27 VERSION_GEN_CC = os.path.join(CWD, "src", "version_gen.cc")
28
29
30 def generate_version_file():
31 tag = subprocess.check_output(
32 "git describe --tags",
33 shell=True,
34 cwd=CWD,
35 ).strip()
36 assert tag
37
38 # Check for commits not exactly matching a tag. Those are candidate builds
39 # for the next version. The output has the form
40 # <tag name>-<n commits>-<hash>.
41 if "-" in tag:
42 version = tag.split("-")[0]
43 candidate = "1"
44 else:
45 version = tag
46 candidate = "0"
47 version_levels = version.split(".")
48
49 # Set default patch level if none is given.
50 if len(version_levels) == 3:
51 version_levels.append("0")
52 assert len(version_levels) == 4
53
54 major, minor, build, patch = version_levels
55
56 # Increment build level for candidate builds.
57 if candidate == "1":
58 build = str(int(build) + 1)
59 patch = "0"
60
61 # Modify version_gen.cc with the new values.
62 output = []
63 with open(VERSION_CC, "r") as f:
64 for line in f:
65 for definition, substitute in (
66 ("MAJOR_VERSION", major),
67 ("MINOR_VERSION", minor),
68 ("BUILD_NUMBER", build),
69 ("PATCH_LEVEL", patch),
70 ("IS_CANDIDATE_VERSION", candidate)):
71 if line.startswith("#define %s" % definition):
72 line = re.sub("\d+$", substitute, line)
73 output.append(line)
74
75 # Prepare log message.
76 candidate_txt = " (candidate)" if candidate == "1" else ""
77 patch_txt = ".%s" % patch if patch != "0" else ""
78 version_txt = ("%s.%s.%s%s%s" %
79 (major, minor, build, patch_txt, candidate_txt))
80 log_message = "Modifying version_gen.cc. Set V8 version to %s" % version_txt
81 return "".join(output), log_message
82
83
84 def bypass_version_file():
85 with open(VERSION_CC, "r") as f:
86 return f.read(), "Bypassing V8 version creation."
87
88
89 def main():
90 parser = optparse.OptionParser()
91 parser.add_option("--skip",
92 help="Use raw version.cc file (disables version "
93 "generation and uses a dummy version).",
94 default=False, action="store_true")
95 (options, args) = parser.parse_args()
96
97 if options.skip:
98 version_file_content, log_message = bypass_version_file()
99 else:
100 version_file_content, log_message = generate_version_file()
101
102 old_content = ""
103 if os.path.exists(VERSION_GEN_CC):
104 with open(VERSION_GEN_CC, "r") as f:
105 old_content = f.read()
106
107 # Only generate version file if content has changed.
108 if old_content != version_file_content:
109 with open(VERSION_GEN_CC, "w") as f:
110 f.write(version_file_content)
111 # Log what was calculated.
112 print log_message
113
114 return 0
115
116
117 if __name__ == "__main__":
118 sys.exit(main())
OLDNEW
« no previous file with comments | « Makefile ('k') | tools/push-to-trunk/generate_version.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698