Commit 5193d537 authored by evan@chromium.org's avatar evan@chromium.org

webkit: expose webkit branch and revision number in about pages

- Change lastchange.py to work in other directories and to
  provide SVN URL.
- Use lastchange.py in place where we generate WebKit versioning
  info.
- Include branch@revision string in glue API.

BUG=41264
TEST=compiles

Review URL: http://codereview.chromium.org/6354014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72245 0039d316-1c4b-4281-b951-d872f2087c98
parent 0a318c63
......@@ -9,46 +9,71 @@ lastchange.py -- Chromium revision fetching utility.
import optparse
import os
import re
import subprocess
import sys
class VersionInfo(object):
def __init__(self, url, root, revision):
self.url = url
self.root = root
self.revision = revision
def FetchSVNRevision(command):
def FetchSVNRevision(command, directory):
"""
Fetch the Subversion revision for the local tree.
Fetch the Subversion branch and revision for the a given directory
by running the given command (e.g. "svn info").
Errors are swallowed.
Returns:
a VersionInfo object or None on error.
"""
try:
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=directory,
shell=(sys.platform=='win32'))
except OSError:
# command is apparently either not installed or not executable.
return None
if proc:
svn_re = re.compile('^Revision:\s+(\d+)', re.M)
match = svn_re.search(proc.stdout.read())
if match:
return match.group(1)
return None
if not proc:
return None
attrs = {}
for line in proc.stdout:
line = line.strip()
if not line:
continue
key, val = line.split(': ', 1)
attrs[key] = val
try:
url = attrs['URL']
root = attrs['Repository Root']
revision = attrs['Revision']
except KeyError:
return None
return VersionInfo(url, root, revision)
def FetchChange(default_lastchange):
def FetchVersionInfo(default_lastchange, directory=None):
"""
Returns the last change, from some appropriate revision control system.
Returns the last change (in the form of a branch, revision tuple),
from some appropriate revision control system.
"""
change = FetchSVNRevision(['svn', 'info'])
if not change and sys.platform in ('linux2',):
change = FetchSVNRevision(['git', 'svn', 'info'])
if not change:
version_info = FetchSVNRevision(['svn', 'info'], directory)
if not version_info and sys.platform in ('linux2',):
version_info = FetchSVNRevision(['git', 'svn', 'info'], directory)
if not version_info:
if default_lastchange and os.path.exists(default_lastchange):
change = open(default_lastchange, 'r').read().strip()
revision = open(default_lastchange, 'r').read().strip()
version_info = VersionInfo(None, None, revision)
else:
change = '0'
return change
version_info = VersionInfo('', '', '0')
return version_info
def WriteIfChanged(file_name, contents):
......@@ -90,12 +115,12 @@ def main(argv=None):
parser.print_help()
sys.exit(2)
change = FetchChange(opts.default_lastchange)
version_info = FetchVersionInfo(opts.default_lastchange)
if opts.revision_only:
print change
print version_info.revision
else:
contents = "LASTCHANGE=%s\n" % change
contents = "LASTCHANGE=%s\n" % version_info.revision
if out_file:
WriteIfChanged(out_file, contents)
else:
......
......@@ -12,6 +12,9 @@ import os
import re
import sys
sys.path.insert(0, '../../build/util')
import lastchange
def ReadVersionFile(fname):
'''Reads the Webkit Version.xcconfig file looking for MAJOR_VERSION and
MINOR_VERSION. This function doesn't attempt to support the full syntax
......@@ -37,11 +40,43 @@ def ReadVersionFile(fname):
assert(major >= 0 and minor >= 0)
return (major, minor)
def EmitVersionHeader(version_file, output_dir):
def GetWebKitRevision(webkit_dir, version_file):
"""Get the WebKit revision, in the form 'trunk@1234'."""
# "svn info" tells us what we want, but third_party/WebKit does *not*
# point at the upstream repo. So instead we run svn info on the directory
# containing the versioning file (which is some subdirectory of WebKit),
# then strip that path back off of the resulting URL.
version_file_dir = os.path.dirname(version_file)
version_info = lastchange.FetchVersionInfo(
default_lastchange=None,
directory=os.path.join(webkit_dir, version_file_dir))
# Now compute the real WebKit URL by stripping off the version file
# directory from the URL we get out of version_info.
# Further, we want to strip off the "http://svn..." from the left.
# This is the root URL from the repository.
assert version_info.url.startswith(version_info.root)
assert version_info.url.endswith(version_file_dir)
webkit_url = version_info.url[len(version_info.root):-len(version_file_dir)]
webkit_url = webkit_url.strip('/')
return "%s@%s" % (webkit_url, version_info.revision)
def EmitVersionHeader(webkit_dir, version_file, output_dir):
'''Given webkit's version file, emit a header file that we can use from
within webkit_glue.cc.
'''
(major, minor) = ReadVersionFile(version_file)
# See .gypi file for discussion of this workaround for the version file.
assert version_file[0] == '/'
version_file = version_file[1:]
major, minor = ReadVersionFile(os.path.join(webkit_dir, version_file))
webkit_revision = GetWebKitRevision(webkit_dir, version_file)
fname = os.path.join(output_dir, "webkit_version.h")
f = open(fname, 'wb')
template = """// webkit_version.h
......@@ -49,12 +84,13 @@ def EmitVersionHeader(version_file, output_dir):
#define WEBKIT_VERSION_MAJOR %d
#define WEBKIT_VERSION_MINOR %d
""" % (version_file, major, minor)
#define WEBKIT_SVN_REVISION "%s"
""" % (version_file, major, minor, webkit_revision)
f.write(template)
f.close()
def main():
EmitVersionHeader(sys.argv[1], sys.argv[2])
EmitVersionHeader(*sys.argv[1:])
if __name__ == "__main__":
......
......@@ -22,8 +22,14 @@ namespace webkit_glue {
std::string GetProductVersion();
std::string GetWebKitVersion() {
return base::StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR,
WEBKIT_VERSION_MINOR);
return base::StringPrintf("%d.%d (%s)",
WEBKIT_VERSION_MAJOR,
WEBKIT_VERSION_MINOR,
WEBKIT_SVN_REVISION);
}
std::string GetWebKitRevision() {
return WEBKIT_SVN_REVISION;
}
std::string BuildOSCpuInfo() {
......
......@@ -19,7 +19,7 @@ void BuildUserAgent(bool mimic_windows, std::string* result);
// Builds a User-agent compatible string that describes the OS and CPU type.
std::string BuildOSCpuInfo();
// Returns the WebKit version (major.minor).
// Returns the WebKit version, in the form "major.minor (branch@revision)".
std::string GetWebKitVersion();
} // namespace webkit_glue
......
......@@ -120,13 +120,23 @@
{
'action_name': 'webkit_version',
'inputs': [
'../build/webkit_version.py',
'<(webkit_src_dir)/Source/WebCore/Configurations/Version.xcconfig',
'<(script)',
'<(webkit_src_dir)<(version_file)',
'../../build/util/lastchange.py', # Used by the script.
],
'outputs': [
'<(INTERMEDIATE_DIR)/webkit_version.h',
],
'action': ['python', '<@(_inputs)', '<(INTERMEDIATE_DIR)'],
'action': ['python', '<(script)', '<(webkit_src_dir)',
'<(version_file)', '<(INTERMEDIATE_DIR)'],
'variables': {
'script': '../build/webkit_version.py',
# version_file is a relative path from |webkit_src_dir| to
# the version file. But gyp will eat the variable unless
# it looks like an absolute path, so write it like one and
# then use it carefully above.
'version_file': '/Source/WebCore/Configurations/Version.xcconfig',
},
},
],
'include_dirs': [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment