Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 '''Emits a webkit_version.h header file with |
| 7 MINOR_VERSION, emitting them into a webkit_version.h header file as | |
| 8 WEBKIT_MAJOR_VERSION and WEBKIT_MINOR_VERSION macros. | 7 WEBKIT_MAJOR_VERSION and WEBKIT_MINOR_VERSION macros. |
| 9 ''' | 8 ''' |
| 10 | 9 |
| 11 import os | 10 import os |
| 12 import re | 11 import re |
| 13 import sys | 12 import sys |
| 14 | 13 |
| 15 # Get the full path of the current script which would be something like | 14 # Get the full path of the current script which would be something like |
| 16 # src/webkit/build/webkit_version.py and navigate backwards twice to strip the | 15 # src/webkit/build/webkit_version.py and navigate backwards twice to strip the |
| 17 # last two path components to get to the srcroot. | 16 # last two path components to get to the srcroot. |
| 18 # This is to ensure that the script can load the lastchange module by updating | 17 # This is to ensure that the script can load the lastchange module by updating |
| 19 # the sys.path variable with the desired location. | 18 # the sys.path variable with the desired location. |
| 20 path = os.path.dirname(os.path.realpath(__file__)) | 19 path = os.path.dirname(os.path.realpath(__file__)) |
| 21 path = os.path.dirname(os.path.dirname(path)) | 20 path = os.path.dirname(os.path.dirname(path)) |
| 22 path = os.path.join(path, 'build', 'util') | 21 path = os.path.join(path, 'build', 'util') |
| 23 | 22 |
| 24 sys.path.insert(0, path) | 23 sys.path.insert(0, path) |
| 25 import lastchange | 24 import lastchange |
| 26 | 25 |
| 27 def ReadVersionFile(fname): | |
| 28 '''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and | |
| 29 MINOR_VERSION. This function doesn't attempt to support the full syntax | |
| 30 of xcconfig files.''' | |
| 31 re_major = re.compile('MAJOR_VERSION\s*=\s*(\d+).*') | |
| 32 re_minor = re.compile('MINOR_VERSION\s*=\s*(\d+).*') | |
| 33 major = -1 | |
| 34 minor = -1 | |
| 35 f = open(fname, 'rb') | |
| 36 line = "not empty" | |
| 37 while line and not (major >= 0 and minor >= 0): | |
| 38 line = f.readline() | |
| 39 if major == -1: | |
| 40 match = re_major.match(line) | |
| 41 if match: | |
| 42 major = int(match.group(1)) | |
| 43 continue | |
| 44 if minor == -1: | |
| 45 match = re_minor.match(line) | |
| 46 if match: | |
| 47 minor = int(match.group(1)) | |
| 48 continue | |
| 49 assert(major >= 0 and minor >= 0) | |
| 50 return (major, minor) | |
| 51 | 26 |
| 52 | 27 def GetWebKitRevision(webkit_src_dir): |
| 53 def GetWebKitRevision(webkit_dir, version_file): | |
| 54 """Get the WebKit revision, in the form 'trunk@1234'.""" | 28 """Get the WebKit revision, in the form 'trunk@1234'.""" |
| 55 | 29 |
| 56 # "svn info" tells us what we want, but third_party/WebKit does *not* | |
| 57 # point at the upstream repo. So instead we run svn info on the directory | |
| 58 # containing the versioning file (which is some subdirectory of WebKit). | |
| 59 version_file_dir = os.path.dirname(version_file) | |
| 60 version_info = lastchange.FetchVersionInfo( | 30 version_info = lastchange.FetchVersionInfo( |
| 61 default_lastchange=None, | 31 default_lastchange=None, |
| 62 directory=os.path.join(webkit_dir, version_file_dir), | 32 directory=webkit_src_dir, |
| 63 directory_regex_prior_to_src_url='webkit') | 33 directory_regex_prior_to_src_url='webkit') |
| 64 | 34 |
| 65 if version_info.url == None: | 35 if version_info.url == None: |
| 66 version_info.url = 'Unknown URL' | 36 version_info.url = 'Unknown URL' |
| 67 version_info.url = version_info.url.strip('/') | 37 version_info.url = version_info.url.strip('/') |
| 68 | 38 |
| 69 if version_info.revision == None: | 39 if version_info.revision == None: |
| 70 version_info.revision = '0' | 40 version_info.revision = '0' |
| 71 | 41 |
| 72 return "%s@%s" % (version_info.url, version_info.revision) | 42 return "%s@%s" % (version_info.url, version_info.revision) |
| 73 | 43 |
| 74 | 44 |
| 75 def EmitVersionHeader(webkit_dir, version_file, output_dir): | 45 def EmitVersionHeader(webkit_src_dir, output_dir): |
| 76 '''Given webkit's version file, emit a header file that we can use from | 46 '''Emit a header file that we can use from within webkit_glue.cc.''' |
| 77 within webkit_glue.cc. | |
| 78 ''' | |
| 79 | 47 |
| 80 # See .gypi file for discussion of this workaround for the version file. | 48 # These are hard-coded from when we forked Blink. Presumably these |
| 81 assert version_file[0] == '/' | 49 # would be better in a header somewhere. |
|
darin (slow to review)
2013/04/17 04:53:49
yes, it'd be good to get rid of all of this build-
| |
| 82 version_file = version_file[1:] | 50 major, minor = (537, 36) |
| 83 | 51 webkit_revision = GetWebKitRevision(webkit_src_dir) |
| 84 major, minor = ReadVersionFile(os.path.join(webkit_dir, version_file)) | |
| 85 | |
| 86 webkit_revision = GetWebKitRevision(webkit_dir, version_file) | |
| 87 | 52 |
| 88 fname = os.path.join(output_dir, "webkit_version.h") | 53 fname = os.path.join(output_dir, "webkit_version.h") |
| 89 f = open(fname, 'wb') | 54 f = open(fname, 'wb') |
| 90 template = """// webkit_version.h | 55 template = """// webkit_version.h |
| 91 // generated from %s | 56 // generated from %s |
| 92 | 57 |
| 93 #define WEBKIT_VERSION_MAJOR %d | 58 #define WEBKIT_VERSION_MAJOR %d |
| 94 #define WEBKIT_VERSION_MINOR %d | 59 #define WEBKIT_VERSION_MINOR %d |
| 95 #define WEBKIT_SVN_REVISION "%s" | 60 #define WEBKIT_SVN_REVISION "%s" |
| 96 """ % (version_file, major, minor, webkit_revision) | 61 """ % (webkit_src_dir, major, minor, webkit_revision) |
| 97 f.write(template) | 62 f.write(template) |
| 98 f.close() | 63 f.close() |
| 99 return 0 | 64 return 0 |
| 100 | 65 |
| 101 | 66 |
| 102 def main(): | 67 def main(): |
| 103 return EmitVersionHeader(*sys.argv[1:]) | 68 return EmitVersionHeader(*sys.argv[1:]) |
| 104 | 69 |
| 105 | 70 |
| 106 if __name__ == "__main__": | 71 if __name__ == "__main__": |
| 107 sys.exit(main()) | 72 sys.exit(main()) |
| OLD | NEW |