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

Side by Side Diff: webkit/build/webkit_version.py

Issue 6354014: webkit: expose webkit branch and revision number in about pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: strip Created 9 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2008 The Chromium 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 '''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and 6 '''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and
7 MINOR_VERSION, emitting them into a webkit_version.h header file as 7 MINOR_VERSION, emitting them into a webkit_version.h header file as
8 WEBKIT_MAJOR_VERSION and WEBKIT_MINOR_VERSION macros. 8 WEBKIT_MAJOR_VERSION and WEBKIT_MINOR_VERSION macros.
9 ''' 9 '''
10 10
11 import os 11 import os
12 import re 12 import re
13 import sys 13 import sys
14 14
15 sys.path.insert(0, '../../build/util')
16 import lastchange
17
15 def ReadVersionFile(fname): 18 def ReadVersionFile(fname):
16 '''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and 19 '''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and
17 MINOR_VERSION. This function doesn't attempt to support the full syntax 20 MINOR_VERSION. This function doesn't attempt to support the full syntax
18 of xcconfig files.''' 21 of xcconfig files.'''
19 re_major = re.compile('MAJOR_VERSION\s*=\s*(\d+).*') 22 re_major = re.compile('MAJOR_VERSION\s*=\s*(\d+).*')
20 re_minor = re.compile('MINOR_VERSION\s*=\s*(\d+).*') 23 re_minor = re.compile('MINOR_VERSION\s*=\s*(\d+).*')
21 major = -1 24 major = -1
22 minor = -1 25 minor = -1
23 f = open(fname, 'rb') 26 f = open(fname, 'rb')
24 line = "not empty" 27 line = "not empty"
25 while line and not (major >= 0 and minor >= 0): 28 while line and not (major >= 0 and minor >= 0):
26 line = f.readline() 29 line = f.readline()
27 if major == -1: 30 if major == -1:
28 match = re_major.match(line) 31 match = re_major.match(line)
29 if match: 32 if match:
30 major = int(match.group(1)) 33 major = int(match.group(1))
31 continue 34 continue
32 if minor == -1: 35 if minor == -1:
33 match = re_minor.match(line) 36 match = re_minor.match(line)
34 if match: 37 if match:
35 minor = int(match.group(1)) 38 minor = int(match.group(1))
36 continue 39 continue
37 assert(major >= 0 and minor >= 0) 40 assert(major >= 0 and minor >= 0)
38 return (major, minor) 41 return (major, minor)
39 42
40 def EmitVersionHeader(version_file, output_dir): 43 def GetWebKitRevision(webkit_dir, version_file):
44 """Get the WebKit revision, in the form 'trunk@1234'."""
45
46 # "svn info" tells us what we want, but third_party/WebKit does *not*
47 # point at the upstream repo. So instead we run svn info on the directory
48 # containing the versioning file (which is some subdirectory of WebKit),
49 # then strip that path back off of the resulting URL.
50 version_file_dir = os.path.dirname(version_file)
51 version_info = lastchange.FetchVersionInfo(
52 default_lastchange=None,
53 directory=os.path.join(webkit_dir, version_file_dir))
54
55 # Now compute the real WebKit URL by stripping off the version file
56 # directory from the URL we get out of version_info.
57 # Further, we want to strip off the "http://svn..." from the left.
58 # This is the root URL from the repository.
59 assert version_info.url.startswith(version_info.root)
60 assert version_info.url.endswith(version_file_dir)
61 webkit_url = version_info.url[len(version_info.root):-len(version_file_dir)]
62 if webkit_url.startswith('/'):
63 webkit_url = webkit_url[1:]
64 if webkit_url.endswith('/'):
65 webkit_url = webkit_url[:-1]
tony 2011/01/21 22:59:58 Nit: webkit_url = webkit_url.strip('/') (strip rem
66
67 return "%s@%s" % (webkit_url, version_info.revision)
68
69
70 def EmitVersionHeader(webkit_dir, version_file, output_dir):
41 '''Given webkit's version file, emit a header file that we can use from 71 '''Given webkit's version file, emit a header file that we can use from
42 within webkit_glue.cc. 72 within webkit_glue.cc.
43 ''' 73 '''
44 (major, minor) = ReadVersionFile(version_file) 74
75 # See .gypi file for discussion of this workaround for the version file.
76 assert version_file[0] == '/'
77 version_file = version_file[1:]
78
79 (major, minor) = ReadVersionFile(os.path.join(webkit_dir, version_file))
tony 2011/01/21 22:59:58 Nit: Drop the () on the left side
80
81 webkit_revision = GetWebKitRevision(webkit_dir, version_file)
82
45 fname = os.path.join(output_dir, "webkit_version.h") 83 fname = os.path.join(output_dir, "webkit_version.h")
46 f = open(fname, 'wb') 84 f = open(fname, 'wb')
47 template = """// webkit_version.h 85 template = """// webkit_version.h
48 // generated from %s 86 // generated from %s
49 87
50 #define WEBKIT_VERSION_MAJOR %d 88 #define WEBKIT_VERSION_MAJOR %d
51 #define WEBKIT_VERSION_MINOR %d 89 #define WEBKIT_VERSION_MINOR %d
52 """ % (version_file, major, minor) 90 #define WEBKIT_SVN_REVISION "%s"
91 """ % (version_file, major, minor, webkit_revision)
53 f.write(template) 92 f.write(template)
54 f.close() 93 f.close()
55 94
56 def main(): 95 def main():
57 EmitVersionHeader(sys.argv[1], sys.argv[2]) 96 EmitVersionHeader(*sys.argv[1:])
58 97
59 98
60 if __name__ == "__main__": 99 if __name__ == "__main__":
61 main() 100 main()
62 101
63 102
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698