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

Side by Side Diff: tools/push-to-trunk/generate_version.py

Issue 843913009: Reland Auto-generate v8 version based on 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 | « tools/gyp/v8.gyp ('k') | no next file » | 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
9 The script can be run in two modes:
10 1) As a gclient hook with the option --hook.
11 The script will write a temporary version file into the checkout.
12 2) During compilation as an action.
13 The script will write version.cc in the output folder based on the
14 tag info. In case of a failure it will fall back to the temporary file
15 from the hook call.
16
17 In most cases, 2) will succeed and the temporary information from 1) won't
18 be used. In case the checkout is copied somewhere and the git context is
19 lost (e.g. on the android_aosp builder), the temporary file from 1) is
20 required.
8 """ 21 """
9 22
10 23
24 import optparse
11 import os 25 import os
12 import re 26 import re
13 import subprocess 27 import subprocess
14 import sys 28 import sys
15 29
16 30
17 CWD = os.path.abspath( 31 CWD = os.path.abspath(
18 os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) 32 os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
19 VERSION_CC = os.path.join(CWD, "src", "version.cc") 33 VERSION_CC = os.path.join(CWD, "src", "version.cc")
34 TMP_VERSION_CC = os.path.join(CWD, ".version.cc")
20 35
21 def main(): 36
37 def generate_version_file():
22 tag = subprocess.check_output( 38 tag = subprocess.check_output(
23 "git describe --tags", 39 "git describe --tags",
24 shell=True, 40 shell=True,
25 cwd=CWD, 41 cwd=CWD,
26 ).strip() 42 ).strip()
27 assert tag 43 assert tag
28 44
29 # Check for commits not exactly matching a tag. Those are candidate builds 45 # Check for commits not exactly matching a tag. Those are candidate builds
30 # for the next version. The output has the form 46 # for the next version. The output has the form
31 # <tag name>-<n commits>-<hash>. 47 # <tag name>-<n commits>-<hash>.
(...skipping 11 matching lines...) Expand all
43 assert len(version_levels) == 4 59 assert len(version_levels) == 4
44 60
45 major, minor, build, patch = version_levels 61 major, minor, build, patch = version_levels
46 62
47 # Increment build level for candidate builds. 63 # Increment build level for candidate builds.
48 if candidate == "1": 64 if candidate == "1":
49 build = str(int(build) + 1) 65 build = str(int(build) + 1)
50 patch = "0" 66 patch = "0"
51 67
52 # Modify version.cc with the new values. 68 # Modify version.cc with the new values.
69 output = []
53 with open(VERSION_CC, "r") as f: 70 with open(VERSION_CC, "r") as f:
54 text = f.read() 71 for line in f:
55 output = [] 72 for definition, substitute in (
56 for line in text.split("\n"): 73 ("MAJOR_VERSION", major),
57 for definition, substitute in ( 74 ("MINOR_VERSION", minor),
58 ("MAJOR_VERSION", major), 75 ("BUILD_NUMBER", build),
59 ("MINOR_VERSION", minor), 76 ("PATCH_LEVEL", patch),
60 ("BUILD_NUMBER", build), 77 ("IS_CANDIDATE_VERSION", candidate)):
61 ("PATCH_LEVEL", patch), 78 if line.startswith("#define %s" % definition):
62 ("IS_CANDIDATE_VERSION", candidate)): 79 line = re.sub("\d+$", substitute, line)
63 if line.startswith("#define %s" % definition): 80 output.append(line)
64 line = re.sub("\d+$", substitute, line) 81 # Log what was calculated.
65 output.append(line)
66 with open(VERSION_CC, "w") as f:
67 f.write("\n".join(output))
68
69 # Log what was done.
70 candidate_txt = " (candidate)" if candidate == "1" else "" 82 candidate_txt = " (candidate)" if candidate == "1" else ""
71 patch_txt = ".%s" % patch if patch != "0" else "" 83 patch_txt = ".%s" % patch if patch != "0" else ""
72 version_txt = ("%s.%s.%s%s%s" % 84 version_txt = ("%s.%s.%s%s%s" %
73 (major, minor, build, patch_txt, candidate_txt)) 85 (major, minor, build, patch_txt, candidate_txt))
74 print "Modified version.cc. Set V8 version to %s" % version_txt 86 print "Modifying version.cc. Set V8 version to %s" % version_txt
87 return "".join(output)
88
89
90 def delete_tmp_version_file():
91 # Make sure a subsequent call to this script doesn't use an outdated
92 # version file.
93 if os.path.exists(TMP_VERSION_CC):
94 os.remove(TMP_VERSION_CC)
95
96
97 def main():
98 parser = optparse.OptionParser()
99 parser.add_option("--hook",
100 help="Run as a gclient hook",
101 default=False, action="store_true")
102 (options, args) = parser.parse_args()
103
104 if options.hook:
105 version_out = TMP_VERSION_CC
106 else:
107 if len(args) != 1:
108 print "Error: Specify the output file path for version.cc"
109 return 1
110 version_out = args[0]
111
112 assert os.path.exists(os.path.dirname(version_out))
113
114 try:
115 version_file_content = generate_version_file()
116 except Exception as e:
117 # Allow exceptions when run during compilation. E.g. there might be no git
118 # context availabe. When run as a gclient hook, generation must succeed.
119 if options.hook:
120 delete_tmp_version_file()
121 raise e
122 # Assume the script already ran as a hook.
123 print "No git context available. Using V8 version from hook."
124 assert os.path.exists(TMP_VERSION_CC)
125 with open(TMP_VERSION_CC, "r") as f:
126 version_file_content = f.read()
127
128 delete_tmp_version_file()
129 with open(version_out, "w") as f:
130 f.write(version_file_content)
75 return 0 131 return 0
76 132
77 if __name__ == "__main__": 133 if __name__ == "__main__":
78 sys.exit(main()) 134 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698