Index: native_client_sdk/src/build_tools/build_version.py |
diff --git a/native_client_sdk/src/build_tools/build_version.py b/native_client_sdk/src/build_tools/build_version.py |
index 6e0aaa7421b3ec06a89fbe14925fcb59ec95c667..375c24a5fe8d0a04b7282d234dfdf1aa10c73e0b 100644 |
--- a/native_client_sdk/src/build_tools/build_version.py |
+++ b/native_client_sdk/src/build_tools/build_version.py |
@@ -6,6 +6,7 @@ |
""" |
import os |
+import re |
import sys |
# pylint: disable=E0602 |
@@ -27,7 +28,7 @@ def ChromeVersion(): |
Returns: |
Chrome version string or trunk + svn rev. |
''' |
- info = lastchange.FetchVersionInfo(None) |
+ info = FetchVersionInfo() |
if info.url.startswith('/trunk/'): |
return 'trunk.%s' % info.revision |
else: |
@@ -58,10 +59,15 @@ def ChromeMajorVersion(): |
def ChromeRevision(): |
'''Extract chrome revision from svn. |
+ Now that the Chrome source-of-truth is git, this will return the |
+ Cr-Commit-Position instead. fortunately, this value is equal to the SVN |
+ revision if one exists. |
+ |
Returns: |
The Chrome revision as a string. e.g. "12345" |
''' |
- return lastchange.FetchVersionInfo(None).revision |
+ return FetchVersionInfo().revision |
+ |
def NaClRevision(): |
'''Extract NaCl revision from svn. |
@@ -70,4 +76,48 @@ def NaClRevision(): |
The NaCl revision as a string. e.g. "12345" |
''' |
nacl_dir = os.path.join(SRC_DIR, 'native_client') |
- return lastchange.FetchVersionInfo(None, nacl_dir).revision |
+ return FetchVersionInfo(nacl_dir, 'native_client').revision |
+ |
+ |
+def FetchVersionInfo(directory=None, |
+ directory_regex_prior_to_src_url='chrome|blink|svn'): |
+ """ |
+ Returns the last change (in the form of a branch, revision tuple), |
+ from some appropriate revision control system. |
+ |
+ TODO(binji): This is copied from lastchange.py. Remove this function and use |
+ lastchange.py directly when the dust settles. (see crbug.com/406783) |
+ """ |
+ svn_url_regex = re.compile( |
+ r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') |
+ |
+ version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or |
+ lastchange.FetchGitSVNRevision(directory, svn_url_regex) or |
+ FetchGitCommitPosition(directory)) |
+ if not version_info: |
+ version_info = lastchange.VersionInfo(None, None) |
+ return version_info |
+ |
+ |
+def FetchGitCommitPosition(directory=None): |
+ """ |
+ Return the "commit-position" of the Chromium git repo. This should be |
+ equivalent to the SVN revision if one eixsts. |
+ |
+ This is a copy of the (recently reverted) change in lastchange.py. |
+ TODO(binji): Move this logic to lastchange.py when the dust settles. |
+ (see crbug.com/406783) |
+ """ |
+ proc = lastchange.RunGitCommand(directory, |
+ ['show', '-s', '--format=%B', 'HEAD']) |
+ pos = '' |
+ if proc: |
+ output = proc.communicate()[0] |
+ if proc.returncode == 0 and output: |
+ for line in reversed(output.splitlines()): |
+ match = re.search('Cr-Commit-Position: .*@{#(\d+)}', line) |
+ if match: |
+ pos = match.group(1) |
+ if not pos: |
+ return lastchange.VersionInfo(None, None) |
+ return lastchange.VersionInfo('git', pos) |