OLD | NEW |
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 EmitVersionHeader(version_file, output_dir): |
41 '''Given webkit's version file, emit a header file that we can use from | 44 '''Given webkit's version file, emit a header file that we can use from |
42 within webkit_glue.cc. | 45 within webkit_glue.cc. |
43 ''' | 46 ''' |
| 47 |
44 (major, minor) = ReadVersionFile(version_file) | 48 (major, minor) = ReadVersionFile(version_file) |
| 49 (svn_url, svn_revision) = lastchange.FetchChange( |
| 50 default_lastchange=None, |
| 51 directory=os.path.dirname(version_file)) |
| 52 |
45 fname = os.path.join(output_dir, "webkit_version.h") | 53 fname = os.path.join(output_dir, "webkit_version.h") |
46 f = open(fname, 'wb') | 54 f = open(fname, 'wb') |
47 template = """// webkit_version.h | 55 template = """// webkit_version.h |
48 // generated from %s | 56 // generated from %s |
49 | 57 |
50 #define WEBKIT_VERSION_MAJOR %d | 58 #define WEBKIT_VERSION_MAJOR %d |
51 #define WEBKIT_VERSION_MINOR %d | 59 #define WEBKIT_VERSION_MINOR %d |
52 """ % (version_file, major, minor) | 60 #define WEBKIT_SVN_REVISION "%s@%s" |
| 61 """ % (version_file, major, minor, svn_url, svn_revision) |
53 f.write(template) | 62 f.write(template) |
54 f.close() | 63 f.close() |
55 | 64 |
56 def main(): | 65 def main(): |
57 EmitVersionHeader(sys.argv[1], sys.argv[2]) | 66 EmitVersionHeader(sys.argv[1], sys.argv[2]) |
58 | 67 |
59 | 68 |
60 if __name__ == "__main__": | 69 if __name__ == "__main__": |
61 main() | 70 main() |
62 | 71 |
63 | 72 |
OLD | NEW |