diff options
author | Ben Smith <binji@chromium.org> | 2014-08-28 15:19:55 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2014-08-28 22:26:24 +0000 |
commit | 6a8b61d6be4656e682eba005a1dd7f129789129c (patch) | |
tree | 740c0b41cc695897a8ed13bd0a213e827b5e4d79 /native_client_sdk | |
parent | c840fed40b6ea6c15f1d5bd3629fa7afc4549bcb (diff) | |
download | chromium_src-6a8b61d6be4656e682eba005a1dd7f129789129c.zip chromium_src-6a8b61d6be4656e682eba005a1dd7f129789129c.tar.gz chromium_src-6a8b61d6be4656e682eba005a1dd7f129789129c.tar.bz2 |
[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}
Diffstat (limited to 'native_client_sdk')
-rw-r--r-- | native_client_sdk/src/README | 1 | ||||
-rwxr-xr-x | native_client_sdk/src/build_tools/build_sdk.py | 2 | ||||
-rw-r--r-- | native_client_sdk/src/build_tools/build_version.py | 66 | ||||
-rwxr-xr-x | native_client_sdk/src/tools/getos.py | 11 | ||||
-rwxr-xr-x | native_client_sdk/src/tools/tests/getos_test.py | 3 |
5 files changed, 66 insertions, 17 deletions
diff --git a/native_client_sdk/src/README b/native_client_sdk/src/README index c44f214..923bb69 100644 --- a/native_client_sdk/src/README +++ b/native_client_sdk/src/README @@ -4,6 +4,7 @@ Welcome to the Native Client SDK Native Client Tools Bundle Version: ${VERSION} Chrome Revision: ${CHROME_REVISION} +Chrome Commit Position: ${CHROME_COMMIT_POSITION} Native Client Revision: ${NACL_REVISION} Build Date: ${DATE} diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py index d4e7f0c..ccc52b7 100755 --- a/native_client_sdk/src/build_tools/build_sdk.py +++ b/native_client_sdk/src/build_tools/build_sdk.py @@ -182,6 +182,8 @@ def BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, readme_text = open(os.path.join(SDK_SRC_DIR, 'README')).read() readme_text = readme_text.replace('${VERSION}', pepper_ver) 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) # Year/Month/Day Hour:Minute:Second diff --git a/native_client_sdk/src/build_tools/build_version.py b/native_client_sdk/src/build_tools/build_version.py index ced1a25..91e1381 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 diff --git a/native_client_sdk/src/tools/getos.py b/native_client_sdk/src/tools/getos.py index 62c2b5b..f14e02e 100755 --- a/native_client_sdk/src/tools/getos.py +++ b/native_client_sdk/src/tools/getos.py @@ -68,6 +68,7 @@ def GetSDKVersion(): version = None revision = None + commit_position = None for line in open(readme): if ':' in line: name, value = line.split(':', 1) @@ -75,8 +76,10 @@ def GetSDKVersion(): version = value.strip() if name == "Chrome Revision": 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) try: @@ -84,7 +87,7 @@ def GetSDKVersion(): except ValueError: raise Error("error parsing SDK README: %s" % readme) - return (version, revision) + return (version, revision, commit_position) def GetSystemArch(platform): @@ -204,6 +207,8 @@ def main(args): help='Print major version of the NaCl SDK.') parser.add_option('--sdk-revision', action='store_true', 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', help='Check that the SDK version is at least as great as the ' 'version passed in.') @@ -229,6 +234,8 @@ def main(args): out = GetSDKVersion()[0] elif options.sdk_revision: out = GetSDKVersion()[1] + elif options.sdk_commit_position: + out = GetSDKVersion()[2] elif options.check_version: required_version = ParseVersion(options.check_version) version = GetSDKVersion() diff --git a/native_client_sdk/src/tools/tests/getos_test.py b/native_client_sdk/src/tools/tests/getos_test.py index 9004bd9..c847fe1 100755 --- a/native_client_sdk/src/tools/tests/getos_test.py +++ b/native_client_sdk/src/tools/tests/getos_test.py @@ -117,10 +117,11 @@ class TestGetosWithTempdir(TestCaseExtended): def testGetSDKVersion(self): """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: out.write('Version: %s\n' % expected_version[0]) out.write('Chrome Revision: %s\n' % expected_version[1]) + out.write('Chrome Commit Position: %s\n' % expected_version[2]) version = getos.GetSDKVersion() self.assertEqual(version, expected_version) |