Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: native_client_sdk/src/build_tools/build_version.py

Issue 495423010: [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ced1a2540d5cb0e85c113207a622edd069ef796c..91e1381bd49a031fa12ba8bf613033958dd8a84e 100644
--- a/native_client_sdk/src/build_tools/build_version.py
+++ b/native_client_sdk/src/build_tools/build_version.py
@@ -29,10 +29,11 @@ def ChromeVersion():
Chrome version string or trunk + svn rev.
'''
info = FetchVersionInfo()
- if info.url == 'refs/heads/master':
- return 'trunk.%s' % info.revision
- else:
- return ChromeVersionNoTrunk()
+ if info.url == 'git':
+ _, ref, revision = ParseCommitPosition(info)
+ if ref == 'refs/heads/master':
+ return 'trunk.%s' % revision
+ return ChromeVersionNoTrunk()
def ChromeVersionNoTrunk():
@@ -60,13 +61,24 @@ 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
+ 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 FetchVersionInfo().revision
+ version = FetchGitCommitPosition()
+ return ParseCommitPosition(version.revision)[2]
+
+
+def ChromeCommitPosition():
+ '''Return the full git sha and commit position.
+
+ Returns:
+ A value like:
+ 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238}
+ '''
+ return FetchGitCommitPosition().revision
def NaClRevision():
@@ -81,13 +93,13 @@ def NaClRevision():
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')(/.*)')
@@ -100,21 +112,47 @@ def FetchVersionInfo(directory=None,
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)
- """
+ '''
+ hsh = ''
+ proc = lastchange.RunGitCommand(directory, ['rev-parse', 'HEAD'])
+ if proc:
+ output = proc.communicate()[0].strip()
+ if proc.returncode == 0 and output:
+ hsh = output
+ if not hsh:
+ return None
+ pos = ''
proc = lastchange.RunGitCommand(directory,
['show', '-s', '--format=%B', 'HEAD'])
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:
- return lastchange.VersionInfo(match.group(1), match.group(2))
- return lastchange.VersionInfo(None, None)
+ if line.startswith('Cr-Commit-Position:'):
+ pos = line.rsplit()[-1].strip()
+ break
+ if not pos:
+ return lastchange.VersionInfo('git', hsh)
+ return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos))
+
+
+def ParseCommitPosition(commit_position):
+ '''
+ Parse a Chrome commit position into its components.
+
+ Given a commit position like:
+ 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238}
+ Returns:
+ ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238")
+ '''
+ m = re.match(r'([0-9a-fA-F]+)-([^@]+)@{#(\d+)}', commit_position)
+ if m:
+ return m.groups()
+ return None
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698