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

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

Issue 524503002: [NaCl SDK] Fix a bug in build_version.ChromeVersion() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes 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 | « no previous file | native_client_sdk/src/build_tools/tests/build_version_test.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 91e1381bd49a031fa12ba8bf613033958dd8a84e..cb9448834e5f7267d1ea2d0b88dfb25fb8a1190b 100644
--- a/native_client_sdk/src/build_tools/build_version.py
+++ b/native_client_sdk/src/build_tools/build_version.py
@@ -30,7 +30,7 @@ def ChromeVersion():
'''
info = FetchVersionInfo()
if info.url == 'git':
- _, ref, revision = ParseCommitPosition(info)
+ _, ref, revision = ParseCommitPosition(info.revision)
if ref == 'refs/heads/master':
return 'trunk.%s' % revision
return ChromeVersionNoTrunk()
@@ -93,8 +93,7 @@ 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),
+ '''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
@@ -112,47 +111,45 @@ 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 exists.
'''
- Return the "commit-position" of the Chromium git repo. This should be
- equivalent to the SVN revision if one eixsts.
+ SEARCH_LIMIT = 100
+ for i in xrange(SEARCH_LIMIT):
+ cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i]
+ proc = lastchange.RunGitCommand(directory, cmd)
+ if not proc:
+ break
- 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()):
- 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))
+ if not (proc.returncode == 0 and output):
+ break
+
+ lines = output.splitlines()
+
+ # First line is the hash.
+ hsh = lines[0]
+ if not re.match(r'[0-9a-fA-F]+', hsh):
+ break
+
+ for line in reversed(lines):
+ if line.startswith('Cr-Commit-Position:'):
+ pos = line.rsplit()[-1].strip()
+ return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos))
+
+ raise Exception('Unable to fetch a Git Commit Position.')
+
def ParseCommitPosition(commit_position):
- '''
- Parse a Chrome commit position into its components.
+ '''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)
+ m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position)
if m:
return m.groups()
return None
« no previous file with comments | « no previous file | native_client_sdk/src/build_tools/tests/build_version_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698