Commit 6a8b61d6 authored by Ben Smith's avatar Ben Smith

[NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README.

BUG=none
R=bradnelson@google.com, bradnelson@chromium.org

Review URL: https://codereview.chromium.org/495423010

Cr-Commit-Position: refs/heads/master@{#292480}
parent c840fed4
...@@ -4,6 +4,7 @@ Welcome to the Native Client SDK ...@@ -4,6 +4,7 @@ Welcome to the Native Client SDK
Native Client Tools Bundle Native Client Tools Bundle
Version: ${VERSION} Version: ${VERSION}
Chrome Revision: ${CHROME_REVISION} Chrome Revision: ${CHROME_REVISION}
Chrome Commit Position: ${CHROME_COMMIT_POSITION}
Native Client Revision: ${NACL_REVISION} Native Client Revision: ${NACL_REVISION}
Build Date: ${DATE} Build Date: ${DATE}
......
...@@ -182,6 +182,8 @@ def BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, ...@@ -182,6 +182,8 @@ def BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision,
readme_text = open(os.path.join(SDK_SRC_DIR, 'README')).read() readme_text = open(os.path.join(SDK_SRC_DIR, 'README')).read()
readme_text = readme_text.replace('${VERSION}', pepper_ver) readme_text = readme_text.replace('${VERSION}', pepper_ver)
readme_text = readme_text.replace('${CHROME_REVISION}', chrome_revision) readme_text = readme_text.replace('${CHROME_REVISION}', chrome_revision)
readme_text = readme_text.replace('${CHROME_COMMIT_POSITION}',
build_version.ChromeCommitPosition())
readme_text = readme_text.replace('${NACL_REVISION}', nacl_revision) readme_text = readme_text.replace('${NACL_REVISION}', nacl_revision)
# Year/Month/Day Hour:Minute:Second # Year/Month/Day Hour:Minute:Second
......
...@@ -29,10 +29,11 @@ def ChromeVersion(): ...@@ -29,10 +29,11 @@ def ChromeVersion():
Chrome version string or trunk + svn rev. Chrome version string or trunk + svn rev.
''' '''
info = FetchVersionInfo() info = FetchVersionInfo()
if info.url == 'refs/heads/master': if info.url == 'git':
return 'trunk.%s' % info.revision _, ref, revision = ParseCommitPosition(info)
else: if ref == 'refs/heads/master':
return ChromeVersionNoTrunk() return 'trunk.%s' % revision
return ChromeVersionNoTrunk()
def ChromeVersionNoTrunk(): def ChromeVersionNoTrunk():
...@@ -60,13 +61,24 @@ def ChromeRevision(): ...@@ -60,13 +61,24 @@ def ChromeRevision():
'''Extract chrome revision from svn. '''Extract chrome revision from svn.
Now that the Chrome source-of-truth is git, this will return the 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. revision if one exists.
Returns: Returns:
The Chrome revision as a string. e.g. "12345" 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(): def NaClRevision():
...@@ -81,13 +93,13 @@ def NaClRevision(): ...@@ -81,13 +93,13 @@ def NaClRevision():
def FetchVersionInfo(directory=None, def FetchVersionInfo(directory=None,
directory_regex_prior_to_src_url='chrome|blink|svn'): 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. from some appropriate revision control system.
TODO(binji): This is copied from lastchange.py. Remove this function and use TODO(binji): This is copied from lastchange.py. Remove this function and use
lastchange.py directly when the dust settles. (see crbug.com/406783) lastchange.py directly when the dust settles. (see crbug.com/406783)
""" '''
svn_url_regex = re.compile( svn_url_regex = re.compile(
r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
...@@ -100,21 +112,47 @@ def FetchVersionInfo(directory=None, ...@@ -100,21 +112,47 @@ def FetchVersionInfo(directory=None,
def FetchGitCommitPosition(directory=None): def FetchGitCommitPosition(directory=None):
""" '''
Return the "commit-position" of the Chromium git repo. This should be Return the "commit-position" of the Chromium git repo. This should be
equivalent to the SVN revision if one eixsts. equivalent to the SVN revision if one eixsts.
This is a copy of the (recently reverted) change in lastchange.py. This is a copy of the (recently reverted) change in lastchange.py.
TODO(binji): Move this logic to lastchange.py when the dust settles. TODO(binji): Move this logic to lastchange.py when the dust settles.
(see crbug.com/406783) (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, proc = lastchange.RunGitCommand(directory,
['show', '-s', '--format=%B', 'HEAD']) ['show', '-s', '--format=%B', 'HEAD'])
if proc: if proc:
output = proc.communicate()[0] output = proc.communicate()[0]
if proc.returncode == 0 and output: if proc.returncode == 0 and output:
for line in reversed(output.splitlines()): for line in reversed(output.splitlines()):
match = re.search('Cr-Commit-Position: (.*)@{#(\d+)}', line) if line.startswith('Cr-Commit-Position:'):
if match: pos = line.rsplit()[-1].strip()
return lastchange.VersionInfo(match.group(1), match.group(2)) break
return lastchange.VersionInfo(None, None) 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
...@@ -68,6 +68,7 @@ def GetSDKVersion(): ...@@ -68,6 +68,7 @@ def GetSDKVersion():
version = None version = None
revision = None revision = None
commit_position = None
for line in open(readme): for line in open(readme):
if ':' in line: if ':' in line:
name, value = line.split(':', 1) name, value = line.split(':', 1)
...@@ -75,8 +76,10 @@ def GetSDKVersion(): ...@@ -75,8 +76,10 @@ def GetSDKVersion():
version = value.strip() version = value.strip()
if name == "Chrome Revision": if name == "Chrome Revision":
revision = value.strip() revision = value.strip()
if name == "Chrome Commit Position":
commit_position = value.strip()
if revision == None or version == None: if revision is None or version is None or commit_position is None:
raise Error("error parsing SDK README: %s" % readme) raise Error("error parsing SDK README: %s" % readme)
try: try:
...@@ -84,7 +87,7 @@ def GetSDKVersion(): ...@@ -84,7 +87,7 @@ def GetSDKVersion():
except ValueError: except ValueError:
raise Error("error parsing SDK README: %s" % readme) raise Error("error parsing SDK README: %s" % readme)
return (version, revision) return (version, revision, commit_position)
def GetSystemArch(platform): def GetSystemArch(platform):
...@@ -204,6 +207,8 @@ def main(args): ...@@ -204,6 +207,8 @@ def main(args):
help='Print major version of the NaCl SDK.') help='Print major version of the NaCl SDK.')
parser.add_option('--sdk-revision', action='store_true', parser.add_option('--sdk-revision', action='store_true',
help='Print revision number of the NaCl SDK.') help='Print revision number of the NaCl SDK.')
parser.add_option('--sdk-commit-position', action='store_true',
help='Print commit position of the NaCl SDK.')
parser.add_option('--check-version', parser.add_option('--check-version',
help='Check that the SDK version is at least as great as the ' help='Check that the SDK version is at least as great as the '
'version passed in.') 'version passed in.')
...@@ -229,6 +234,8 @@ def main(args): ...@@ -229,6 +234,8 @@ def main(args):
out = GetSDKVersion()[0] out = GetSDKVersion()[0]
elif options.sdk_revision: elif options.sdk_revision:
out = GetSDKVersion()[1] out = GetSDKVersion()[1]
elif options.sdk_commit_position:
out = GetSDKVersion()[2]
elif options.check_version: elif options.check_version:
required_version = ParseVersion(options.check_version) required_version = ParseVersion(options.check_version)
version = GetSDKVersion() version = GetSDKVersion()
......
...@@ -117,10 +117,11 @@ class TestGetosWithTempdir(TestCaseExtended): ...@@ -117,10 +117,11 @@ class TestGetosWithTempdir(TestCaseExtended):
def testGetSDKVersion(self): def testGetSDKVersion(self):
"""correctly parses README to find SDK version.""" """correctly parses README to find SDK version."""
expected_version = (16, '196') expected_version = (16, '196', 'f00baacabba6e-refs/heads/master@{#100}')
with open(os.path.join(self.tempdir, 'README'), 'w') as out: with open(os.path.join(self.tempdir, 'README'), 'w') as out:
out.write('Version: %s\n' % expected_version[0]) out.write('Version: %s\n' % expected_version[0])
out.write('Chrome Revision: %s\n' % expected_version[1]) out.write('Chrome Revision: %s\n' % expected_version[1])
out.write('Chrome Commit Position: %s\n' % expected_version[2])
version = getos.GetSDKVersion() version = getos.GetSDKVersion()
self.assertEqual(version, expected_version) self.assertEqual(version, expected_version)
......
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