diff options
author | haraken@google.com <haraken@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-30 05:34:48 +0000 |
---|---|---|
committer | haraken@google.com <haraken@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-30 05:34:48 +0000 |
commit | 118a31109b6cb562b06bbddf3bdf704a08e98a67 (patch) | |
tree | 7d99cb73997bca056a04f11e950881af7749ed89 | |
parent | f680f9152557ecfca133bdcc87bc943f65342e9b (diff) | |
download | chromium_src-118a31109b6cb562b06bbddf3bdf704a08e98a67.zip chromium_src-118a31109b6cb562b06bbddf3bdf704a08e98a67.tar.gz chromium_src-118a31109b6cb562b06bbddf3bdf704a08e98a67.tar.bz2 |
Unify the version string to be displayed on "About Chromium" dialog. (5/6)
- Fetch Subversion URL and the revision from 'git log' even if git-svn is not available.
- Remove VersionInfo.root, since nobody is using it.
- Allow a user to specify the directory name just prior to the svn src URL.
FYI: We decided to split the changes of issue 7104106 (http://codereview.chromium.org/7104106/) into the following steps. This is the fifth step of them:
(1) Add CreateVersionString() to chrome_version_info.*, update the GTK+ code to use it. (reviewer: erg, tony)
(2) Update the mac code to use CreateVersionString(). Update About.xib. (reviewer: mark)
(3) Update the views code to use CreateVersionString(). This can happen at the same time as (2). (reviewer: davemoore, tony)
(4) Update version.bat to use lastchange.py. (reviewer: evan)
(5) Make changes to lastchange.py and webkit_version.py. (reviewer: evan, mark)
(6) Update tweak_info_plist to use lastchange.py. (reviewer: mark)
BUG=37186
TEST=Observe that "About Chromium" dialog shows the version string like "14.0.787.0 (Developer Build 88242 Windows" on Windows and Linux.
Review URL: http://codereview.chromium.org/7493073
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94828 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | build/util/lastchange.py | 172 | ||||
-rwxr-xr-x | webkit/build/webkit_version.py | 27 |
2 files changed, 80 insertions, 119 deletions
diff --git a/build/util/lastchange.py b/build/util/lastchange.py index 4d7a1fe..870bf07 100755 --- a/build/util/lastchange.py +++ b/build/util/lastchange.py @@ -13,21 +13,22 @@ import os import subprocess import sys +_GIT_SVN_ID_REGEX = re.compile(r'.*git-svn-id:\s*([^@]*)@([0-9]+)', re.DOTALL) + class VersionInfo(object): - def __init__(self, url, root, revision): + def __init__(self, url, revision): self.url = url - self.root = root self.revision = revision -def FetchSVNRevision(directory): +def FetchSVNRevision(directory, svn_url_regex): """ Fetch the Subversion branch and revision for a given directory. Errors are swallowed. Returns: - a VersionInfo object or None on error. + A VersionInfo object or None on error. """ try: proc = subprocess.Popen(['svn', 'info'], @@ -50,13 +51,16 @@ def FetchSVNRevision(directory): attrs[key] = val try: - url = attrs['URL'] - root = attrs['Repository Root'] + match = svn_url_regex.search(attrs['URL']) + if match: + url = match.group(2) + else: + url = '' revision = attrs['Revision'] except KeyError: return None - return VersionInfo(url, root, revision) + return VersionInfo(url, revision) def RunGitCommand(directory, command): @@ -66,7 +70,7 @@ def RunGitCommand(directory, command): Errors are swallowed. Returns: - process object or None. + A process object or None. """ command = ['git'] + command # Force shell usage under cygwin & win32. This is a workaround for @@ -92,140 +96,101 @@ def FetchGitRevision(directory): Errors are swallowed. Returns: - a VersionInfo object or None on error. + A VersionInfo object or None on error. """ proc = RunGitCommand(directory, ['rev-parse', 'HEAD']) if proc: output = proc.communicate()[0].strip() if proc.returncode == 0 and output: - return VersionInfo('git', 'git', output[:7]) + return VersionInfo('git', output[:7]) return None -def IsGitSVN(directory): - """ - Checks whether git-svn has been set up. - - Errors are swallowed. - - Returns: - whether git-svn has been set up. - """ - # To test whether git-svn has been set up, query the config for any - # svn-related configuration. This command exits with an error code - # if there aren't any matches, so ignore its output. - proc = RunGitCommand(directory, ['config', '--get-regexp', '^svn']) - if proc: - return (proc.wait() == 0) - return False - - -def FetchGitSVNURL(directory): - """ - Fetch URL of SVN repository bound to git. - - Errors are swallowed. - - Returns: - SVN URL. - """ - if IsGitSVN(directory): - proc = RunGitCommand(directory, ['svn', 'info', '--url']) - if proc: - output = proc.communicate()[0].strip() - if proc.returncode == 0: - match = re.search(r'^\w+://.*$', output, re.M) - if match: - return match.group(0) - return '' - - -def FetchGitSVNRoot(directory): +def FetchGitSVNURLAndRevision(directory, svn_url_regex): """ - Fetch root of SVN repository bound to git. + Fetch the Subversion URL and revision through Git. Errors are swallowed. Returns: - SVN root repository. + A tuple containing the Subversion URL and revision. """ - if IsGitSVN(directory): - git_command = ['config', '--get-regexp', '^svn-remote.svn.url$'] - proc = RunGitCommand(directory, git_command) - if proc: - output = proc.communicate()[0].strip() - if proc.returncode == 0: - # Zero return code implies presence of requested configuration variable. - # Its value is second (last) field of output. - match = re.search(r'\S+$', output) - if match: - return match.group(0) - return '' - - -def LookupGitSVNRevision(directory, depth): - """ - Fetch the Git-SVN identifier for the local tree. - Parses first |depth| commit messages. - - Errors are swallowed. - """ - if not IsGitSVN(directory): - return None - git_re = re.compile(r'^\s*git-svn-id:\s+(\S+)@(\d+)') - proc = RunGitCommand(directory, ['log', '-' + str(depth)]) + proc = RunGitCommand(directory, ['log', '-1', + '--grep=git-svn-id', '--format=%b']) if proc: - for line in proc.stdout: - match = git_re.match(line) + output = proc.communicate()[0].strip() + if proc.returncode == 0 and output: + # Extract the latest SVN revision and the SVN URL. + # The target line is the last "git-svn-id: ..." line like this: + # git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85528 0039d316.... + match = _GIT_SVN_ID_REGEX.search(output) if match: - id = match.group(2) - if id: - proc.stdout.close() # Cut pipe for fast exit. - return id - return None + revision = match.group(2) + url_match = svn_url_regex.search(match.group(1)) + if url_match: + url = url_match.group(2) + else: + url = '' + return url, revision + return None, None def IsGitSVNDirty(directory): """ - Checks whether our git-svn tree contains clean trunk or some branch. + Checks whether our git-svn tree contains clean trunk or any local changes. Errors are swallowed. """ - # For git branches the last commit message is either - # some local commit or a merge. - return LookupGitSVNRevision(directory, 1) is None + proc = RunGitCommand(directory, ['log', '-1']) + if proc: + output = proc.communicate()[0].strip() + if proc.returncode == 0 and output: + # Extract the latest SVN revision and the SVN URL. + # The target line is the last "git-svn-id: ..." line like this: + # git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85528 0039d316.... + match = _GIT_SVN_ID_REGEX.search(output) + if match: + # Check if there are any local uncommitted changes. + proc = RunGitCommand(directory, ['checkout']) + if proc: + output = proc.communicate()[0].strip() + if proc.returncode == 0 and not output: + return False + return True -def FetchGitSVNRevision(directory): +def FetchGitSVNRevision(directory, svn_url_regex): """ Fetch the Git-SVN identifier for the local tree. Errors are swallowed. """ - # We assume that at least first 999 commit messages contain svn evidence. - revision = LookupGitSVNRevision(directory, 999) - if not revision: - return None - if IsGitSVNDirty(directory): - revision = revision + '-dirty' - url = FetchGitSVNURL(directory) - root = FetchGitSVNRoot(directory) - return VersionInfo(url, root, revision) + url, revision = FetchGitSVNURLAndRevision(directory, svn_url_regex) + if url and revision: + if IsGitSVNDirty(directory): + revision = revision + '-dirty' + return VersionInfo(url, revision) + return None -def FetchVersionInfo(default_lastchange, directory=None): +def FetchVersionInfo(default_lastchange, directory=None, + directory_regex_prior_to_src_url='chrome|svn'): """ Returns the last change (in the form of a branch, revision tuple), from some appropriate revision control system. """ - version_info = (FetchSVNRevision(directory) or - FetchGitSVNRevision(directory) or FetchGitRevision(directory)) + svn_url_regex = re.compile( + r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') + + version_info = (FetchSVNRevision(directory, svn_url_regex) or + FetchGitSVNRevision(directory, svn_url_regex) or + FetchGitRevision(directory)) if not version_info: if default_lastchange and os.path.exists(default_lastchange): revision = open(default_lastchange, 'r').read().strip() - version_info = VersionInfo(None, None, revision) + version_info = VersionInfo(None, revision) else: - version_info = VersionInfo('unknown', '', '0') + version_info = VersionInfo(None, None) return version_info @@ -270,6 +235,9 @@ def main(argv=None): version_info = FetchVersionInfo(opts.default_lastchange) + if version_info.revision == None: + version_info.revision = '0' + if opts.revision_only: print version_info.revision else: diff --git a/webkit/build/webkit_version.py b/webkit/build/webkit_version.py index c365b18..7fdf9b32 100755 --- a/webkit/build/webkit_version.py +++ b/webkit/build/webkit_version.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -58,22 +58,17 @@ def GetWebKitRevision(webkit_dir, version_file): version_file_dir = os.path.dirname(version_file) version_info = lastchange.FetchVersionInfo( default_lastchange=None, - directory=os.path.join(webkit_dir, version_file_dir)) + directory=os.path.join(webkit_dir, version_file_dir), + directory_regex_prior_to_src_url='webkit') - if (version_info.url.startswith(version_info.root) and - version_info.url.endswith(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. - webkit_url = version_info.url[len(version_info.root):-len(version_file_dir)] - webkit_url = webkit_url.strip('/') - else: - # The data isn't as we expect: perhaps they're using git without svn? - # Just dump the output directly. - webkit_url = version_info.url + if version_info.url == None: + version_info.url = 'Unknown URL' + version_info.url = version_info.url.strip('/') - return "%s@%s" % (webkit_url, version_info.revision) + if version_info.revision == None: + version_info.revision = '0' + + return "%s@%s" % (version_info.url, version_info.revision) def EmitVersionHeader(webkit_dir, version_file, output_dir): @@ -107,5 +102,3 @@ def main(): if __name__ == "__main__": main() - - |