aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJian Cai <jiancai@google.com>2019-11-20 15:32:56 -0800
committerJian Cai <jiancai@google.com>2019-11-24 19:10:42 +0000
commit121dbe56ddaba18ec5b15758ed669afd2e9acfd9 (patch)
tree401a4a18afc5a0a71d436200e6659fa79f09ce88
parent78c3463730b62fb048d1f76a58c9fbbab23f8efd (diff)
downloadtoolchain-utils-121dbe56ddaba18ec5b15758ed669afd2e9acfd9.tar.gz
toolchain-utils: use LLVM git hashes to track version numbers.
LLVM has stopped issuing SVN version numbers in its commits. This patch adds a way to track SVN-style version number based on a LLVM git hash. BUG=Chromium:1027950 TEST=local tests. Change-Id: Idd8055ea7deb3bcd17c18ab5b642ce8b389e446a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1915373 Tested-by: Jian Cai <jiancai@google.com> Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
-rw-r--r--llvm_tools/README.md8
-rwxr-xr-xllvm_tools/get_llvm_hash.py196
-rwxr-xr-xllvm_tools/get_llvm_hash_unittest.py76
-rwxr-xr-xllvm_tools/git_llvm_rev.py8
-rwxr-xr-xllvm_tools/llvm_bisection.py9
-rwxr-xr-xllvm_tools/llvm_bisection_unittest.py26
-rwxr-xr-xllvm_tools/llvm_patch_management.py16
-rwxr-xr-xllvm_tools/llvm_patch_management_unittest.py19
-rwxr-xr-xllvm_tools/patch_manager.py38
9 files changed, 126 insertions, 270 deletions
diff --git a/llvm_tools/README.md b/llvm_tools/README.md
index abf7a6f9..52bc263f 100644
--- a/llvm_tools/README.md
+++ b/llvm_tools/README.md
@@ -463,14 +463,6 @@ from get_llvm_hash import LLVMHash
LLVMHash().GetLLVMHash(<svn_version>)
```
-For example, to retrieve the commit message of a git hash of LLVM:
-
-```
-from get_llvm_hash import LLVMHash
-
-LLVMHash.GetCommitMessageForHash(<git_hash>)
-```
-
For example, to retrieve the latest google3 LLVM version:
```
diff --git a/llvm_tools/get_llvm_hash.py b/llvm_tools/get_llvm_hash.py
index 914bbfbf..01acbfaf 100755
--- a/llvm_tools/get_llvm_hash.py
+++ b/llvm_tools/get_llvm_hash.py
@@ -15,6 +15,7 @@ import shutil
import subprocess
import sys
import tempfile
+import git_llvm_rev
from contextlib import contextmanager
from subprocess_helpers import CheckCommand
@@ -28,6 +29,44 @@ _LLVM_GIT_URL = ('https://chromium.googlesource.com/external/github.com/llvm'
KNOWN_HASH_SOURCES = {'google3', 'google3-unstable', 'tot'}
+def GetVersionFrom(src_dir, git_hash):
+ """Obtain an SVN-style version number based on the LLVM git hash passed in.
+
+ Args:
+ git_hash: The git hash.
+
+ Returns:
+ An SVN-style version number associated with the git hash.
+ """
+
+ args = ['--llvm_dir', src_dir, '--sha', git_hash]
+ version = git_llvm_rev.main(args).strip()
+ assert version.startswith('r')
+ return int(version[1:])
+
+
+def GetGitHashFrom(src_dir, version):
+ """Finds the commit hash(es) of the LLVM version in the git log history.
+
+ Args:
+ src_dir: The LLVM source tree.
+ version: The version number.
+
+ Returns:
+ A git hash string corresponding to the version number.
+
+ Raises:
+ subprocess.CalledProcessError: Failed to find a git hash.
+ """
+
+ assert isinstance(version, int)
+ args = ['--llvm_dir', src_dir, '--rev', 'r' + str(version)]
+
+ git_hash = git_llvm_rev.main(args).rstrip()
+
+ return git_hash
+
+
@contextmanager
def CreateTempLLVMRepo(temp_dir):
"""Adds a LLVM worktree to 'temp_dir'.
@@ -134,18 +173,19 @@ def GetGoogle3LLVMVersion(stable):
"""
subdir = 'stable' if stable else 'llvm_unstable'
- path_to_google3_llvm_version = os.path.join(
- '/google/src/head/depot/google3/third_party/crosstool/v18', subdir,
- 'installs/llvm/revision')
# Cmd to get latest google3 LLVM version.
- cat_cmd = ['cat', path_to_google3_llvm_version]
+ cmd = [
+ 'cat',
+ os.path.join('/google/src/head/depot/google3/third_party/crosstool/v18',
+ subdir, 'installs/llvm/git_origin_rev_id')
+ ]
# Get latest version.
- g3_version = check_output(cat_cmd)
+ git_hash = check_output(cmd)
# Change type to an integer
- return int(g3_version.rstrip())
+ return GetVersionFrom(GetAndUpdateLLVMProjectInLLVMTools(), git_hash.strip())
def is_svn_option(svn_option):
@@ -192,24 +232,18 @@ def GetLLVMHashAndVersionFromSVNOption(svn_option):
# Determine which LLVM git hash to retrieve.
if svn_option == 'tot':
- llvm_hash = new_llvm_hash.GetTopOfTrunkGitHash()
-
- tot_commit_message = new_llvm_hash.GetCommitMessageForHash(llvm_hash)
-
- llvm_version = new_llvm_hash.GetSVNVersionFromCommitMessage(
- tot_commit_message)
+ git_hash = new_llvm_hash.GetTopOfTrunkGitHash()
+ version = GetVersionFrom(GetAndUpdateLLVMProjectInLLVMTools(), git_hash)
elif isinstance(svn_option, int):
- llvm_version = svn_option
- llvm_hash = new_llvm_hash.GetGitHashForVersion(
- GetAndUpdateLLVMProjectInLLVMTools(), llvm_version)
+ version = svn_option
+ git_hash = GetGitHashFrom(GetAndUpdateLLVMProjectInLLVMTools(), version)
else:
assert svn_option in ('google3', 'google3-unstable')
- llvm_version = GetGoogle3LLVMVersion(stable=svn_option == 'google3')
+ version = GetGoogle3LLVMVersion(stable=svn_option == 'google3')
- llvm_hash = new_llvm_hash.GetGitHashForVersion(
- GetAndUpdateLLVMProjectInLLVMTools(), llvm_version)
+ git_hash = GetGitHashFrom(GetAndUpdateLLVMProjectInLLVMTools(), version)
- return llvm_hash, llvm_version
+ return git_hash, version
class LLVMHash(object):
@@ -244,135 +278,17 @@ class LLVMHash(object):
if clone_cmd_obj.returncode:
raise ValueError('Failed to clone the LLVM repo: %s' % stderr)
- def GetCommitMessageForHash(self, git_hash):
- """Gets the commit message from the git hash.
-
- Args:
- git_hash: A git hash of LLVM.
-
- Returns:
- The commit message of the git hash.
-
- Raises:
- ValueError: Unable to retrieve json contents from the LLVM commit URL.
- """
-
- llvm_commit_url = ('https://api.github.com/repos/llvm/llvm-project/git/'
- 'commits/')
-
- commit_url = os.path.join(llvm_commit_url, git_hash)
-
- url_response = requests.get(commit_url)
-
- if not url_response:
- raise ValueError('Failed to get response from url %s: Status Code %d' %
- (commit_url, url_response.status_code))
-
- unicode_json_contents = url_response.json()
-
- return str(unicode_json_contents['message'])
-
- def GetSVNVersionFromCommitMessage(self, commit_message):
- """Gets the 'llvm-svn' from the commit message.
-
- A commit message may contain multiple 'llvm-svn' (reverting commits), so
- the last 'llvm-svn' is the real 'llvm-svn' for that commit message.
-
- Args:
- commit_message: A commit message that contains a 'llvm-svn:'.
-
- Returns:
- The last LLVM version as an integer or 'None' if there is no 'llvm-svn'.
- """
-
- # Find all "llvm-svn:" instances.
- llvm_versions = re.findall(r'llvm-svn: ([0-9]+)', commit_message)
-
- if llvm_versions:
- return int(llvm_versions[-1])
-
- return None
-
- def _ParseCommitMessages(self, subdir, hash_vals, llvm_version):
- """Parses the hashes that match the LLVM version.
-
- Args:
- subdir: The directory where the git history resides.
- hash_vals: All the hashes that match the LLVM version.
- llvm_version: The version to compare to in the commit message.
-
- Returns:
- The hash that matches the LLVM version.
-
- Raises:
- subprocess.CalledProcessError: Failed to retrieve the commit message body.
- ValueError: Failed to parse a commit message or did not find a commit
- hash.
- """
-
- # For each hash, grab the last "llvm-svn:" line
- # and compare the llvm version of that line against
- # the llvm version we are looking for and return
- # that hash only if they match.
- for cur_commit in hash_vals.splitlines():
- cur_hash = cur_commit.split()[0] # Get hash.
-
- # Cmd to output the commit body.
- find_llvm_cmd = [
- 'git', '-C', subdir, 'log', '--format=%B', '-n', '1', cur_hash
- ]
-
- out = check_output(find_llvm_cmd)
-
- commit_svn_version = self.GetSVNVersionFromCommitMessage(out.rstrip())
-
- # Check the svn version from the commit message against the llvm version
- # we are looking for.
- if commit_svn_version and commit_svn_version == llvm_version:
- return cur_hash
-
- # Failed to find the commit hash.
- raise ValueError('Could not find commit hash.')
-
- def GetGitHashForVersion(self, llvm_git_dir, llvm_version):
- """Finds the commit hash(es) of the LLVM version in the git log history.
-
- Args:
- llvm_git_dir: The LLVM git directory.
- llvm_version: The version to search for in the git log history.
-
- Returns:
- A string of the hash corresponding to the LLVM version.
-
- Raises:
- subprocess.CalledProcessError: Failed to retrieve git hashes that match
- 'llvm_version'.
- """
-
- # Get all the git hashes that match 'llvm_version'.
- hash_cmd = [
- 'git', '-C', llvm_git_dir, 'log', '--oneline', '--no-abbrev', '--grep',
- 'llvm-svn: %d' % llvm_version
- ]
-
- hash_vals = check_output(hash_cmd)
-
- return self._ParseCommitMessages(llvm_git_dir, hash_vals.rstrip(),
- llvm_version)
-
- def GetLLVMHash(self, llvm_version):
+ def GetLLVMHash(self, version):
"""Retrieves the LLVM hash corresponding to the LLVM version passed in.
Args:
- llvm_version: The LLVM version to use as a delimiter.
+ version: The LLVM version to use as a delimiter.
Returns:
The hash as a string that corresponds to the LLVM version.
"""
- hash_value = self.GetGitHashForVersion(GetAndUpdateLLVMProjectInLLVMTools(),
- llvm_version)
-
+ hash_value = GetGitHashFrom(GetAndUpdateLLVMProjectInLLVMTools(), version)
return hash_value
def GetGoogle3LLVMHash(self):
diff --git a/llvm_tools/get_llvm_hash_unittest.py b/llvm_tools/get_llvm_hash_unittest.py
index 895ee2b6..c828f433 100755
--- a/llvm_tools/get_llvm_hash_unittest.py
+++ b/llvm_tools/get_llvm_hash_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2019 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -8,13 +8,13 @@
from __future__ import print_function
+import get_llvm_hash
import subprocess
import unittest
+import unittest.mock as mock
+import test_helpers
-import get_llvm_hash
from get_llvm_hash import LLVMHash
-import mock
-import test_helpers
# We grab protected stuff from get_llvm_hash. That's OK.
# pylint: disable=protected-access
@@ -55,71 +55,17 @@ class TestGetLLVMHash(unittest.TestCase):
with self.assertRaises(ValueError) as err:
LLVMHash().CloneLLVMRepo('/tmp/tmp1')
- self.assertIn('Failed to clone', err.exception.message)
- self.assertIn('some stderr', err.exception.message)
-
- @mock.patch.object(subprocess, 'check_output')
- def testParseCommitMessageWithoutAHashFails(self, check_output_mock):
- check_output_mock.return_value = ('[Test] Test sentence.\n\n'
- 'A change was made.\n\n'
- 'llvm-svn: 1000')
-
- # Verify the exception is raised when failed to find the commit hash.
- with self.assertRaises(ValueError) as err:
- LLVMHash()._ParseCommitMessages('/tmp/tmpTest',
- 'a13testhash2 This is a test', 100)
+ self.assertIn('Failed to clone', str(err.exception.args))
+ self.assertIn('some stderr', str(err.exception.args))
- self.assertEqual(err.exception.message, 'Could not find commit hash.')
- check_output_mock.assert_called_once()
-
- @mock.patch.object(subprocess, 'check_output')
- def testParseCommitMessageIgnoresSVNMarkersInReverts(self, check_output_mock):
- output_messages = [
- '[Test] Test sentence.\n\n'
- 'A change was made.\n\n'
- 'llvm-svn: 1001',
- '[Revert] Reverted commit.\n\n'
- 'This reverts r1000:\n\n'
- ' [Test2] Update.\n\n'
- ' This updates stuff.\n\n'
- ' llvm-svn: 1000\n\n'
- 'llvm-svn: 58',
- '[Revert] Reverted commit.\n\n'
- 'This reverts r958:\n\n'
- ' [Test2] Update.\n\n'
- ' This updates stuff.\n\n'
- ' llvm-svn: 958\n\n'
- 'llvm-svn: 1000',
- ]
-
- @test_helpers.CallCountsToMockFunctions
- def MultipleCommitMessages(call_count, *_args, **_kwargs):
- return output_messages[call_count]
-
- check_output_mock.side_effect = MultipleCommitMessages
-
- hash_vals = ('a13testhash2 [Test] Test sentence.\n'
- 'a13testhash3 [Revert] Reverted commit.\n'
- 'a13testhash4 [Revert] Reverted commit.')
+ @mock.patch.object(get_llvm_hash, 'GetGitHashFrom')
+ def testGetGitHashWorks(self, mock_get_git_hash):
+ mock_get_git_hash.return_value = 'a13testhash2'
self.assertEqual(
- LLVMHash()._ParseCommitMessages('/tmp/tmpTest', hash_vals, 1000),
- 'a13testhash4')
+ get_llvm_hash.GetGitHashFrom('/tmp/tmpTest', 100), 'a13testhash2')
- self.assertEqual(check_output_mock.call_count, 3)
-
- @mock.patch.object(subprocess, 'check_output')
- @mock.patch.object(LLVMHash, '_ParseCommitMessages')
- def testGetGitHashWorks(self, mock_return_hash_val, mock_check_output):
- mock_check_output.return_value = 'a13testhash2 [Test] Test sentence.'
- mock_return_hash_val.return_value = 'a13testhash2'
-
- self.assertEqual(LLVMHash().GetGitHashForVersion('/tmp/tmpTest', 100),
- 'a13testhash2')
-
- mock_return_hash_val.assert_called_once_with(
- '/tmp/tmpTest', 'a13testhash2 [Test] Test sentence.', 100)
- mock_check_output.assert_called_once()
+ mock_get_git_hash.assert_called_once()
@mock.patch.object(LLVMHash, 'GetLLVMHash')
@mock.patch.object(get_llvm_hash, 'GetGoogle3LLVMVersion')
diff --git a/llvm_tools/git_llvm_rev.py b/llvm_tools/git_llvm_rev.py
index 4c9fed12..76a67d65 100755
--- a/llvm_tools/git_llvm_rev.py
+++ b/llvm_tools/git_llvm_rev.py
@@ -343,9 +343,13 @@ def main(argv: t.List[str]) -> None:
)
if opts.sha:
- print(translate_sha_to_rev(config, opts.sha))
+ rev = str(translate_sha_to_rev(config, opts.sha))
+ print(rev)
+ return rev
else:
- print(translate_rev_to_sha(config, Rev.parse(opts.rev)))
+ sha = str(translate_rev_to_sha(config, Rev.parse(opts.rev)))
+ print(sha)
+ return sha
if __name__ == '__main__':
diff --git a/llvm_tools/llvm_bisection.py b/llvm_tools/llvm_bisection.py
index b45be0aa..4ff921d2 100755
--- a/llvm_tools/llvm_bisection.py
+++ b/llvm_tools/llvm_bisection.py
@@ -11,6 +11,7 @@ from __future__ import print_function
import argparse
import enum
import errno
+import get_llvm_hash
import json
import os
import sys
@@ -268,7 +269,7 @@ def GetRevisionsBetweenBisection(start, end, parallel, src_path,
cur_revision not in skip_revisions:
# Verify that the current revision exists by finding its corresponding
# git hash in the LLVM source tree.
- new_llvm.GetGitHashForVersion(src_path, cur_revision)
+ get_llvm_hash.GetGitHashFrom(src_path, cur_revision)
valid_revisions.append(cur_revision)
except ValueError:
# Could not find the git hash for the current revision.
@@ -302,9 +303,7 @@ def GetRevisionsListAndHashList(start, end, parallel, src_path,
revisions = GetRevisionsBetweenBisection(
start, end, parallel, src_path, pending_revisions, skip_revisions)
- git_hashes = [
- new_llvm.GetGitHashForVersion(src_path, rev) for rev in revisions
- ]
+ git_hashes = [get_llvm_hash.GetGitHashFrom(src_path, rev) for rev in revisions]
return revisions, git_hashes
@@ -363,7 +362,7 @@ def _NoteCompletedBisection(last_tested, src_path, end):
print('Finished bisecting for %s' % last_tested)
if src_path:
- bad_llvm_hash = LLVMHash().GetGitHashForVersion(src_path, end)
+ bad_llvm_hash = get_llvm_hash.GetGitHashFrom(src_path, end)
else:
bad_llvm_hash = LLVMHash().GetLLVMHash(end)
diff --git a/llvm_tools/llvm_bisection_unittest.py b/llvm_tools/llvm_bisection_unittest.py
index 946a56ff..ccef649c 100755
--- a/llvm_tools/llvm_bisection_unittest.py
+++ b/llvm_tools/llvm_bisection_unittest.py
@@ -8,7 +8,9 @@
from __future__ import print_function
+import get_llvm_hash
import json
+import llvm_bisection
import unittest
import unittest.mock as mock
@@ -17,7 +19,6 @@ from test_helpers import ArgsOutputTest
from test_helpers import CallCountsToMockFunctions
from test_helpers import CreateTemporaryJsonFile
from test_helpers import WritePrettyJsonFile
-import llvm_bisection
class LLVMBisectionTest(unittest.TestCase):
@@ -144,7 +145,7 @@ class LLVMBisectionTest(unittest.TestCase):
llvm_bisection.GetStartAndEndRevision(start, end, test_tryjobs),
expected_revisions_tuple)
- @mock.patch.object(LLVMHash, 'GetGitHashForVersion')
+ @mock.patch.object(get_llvm_hash, 'GetGitHashFrom')
def testNoRevisionsBetweenStartAndEnd(self, mock_get_git_hash):
start = 100
end = 110
@@ -152,7 +153,7 @@ class LLVMBisectionTest(unittest.TestCase):
test_pending_revisions = {107}
test_skip_revisions = {101, 102, 103, 104, 108, 109}
- # Simulate behavior of `GetGitHashForVersion()` when the revision does not
+ # Simulate behavior of `GetGitHashFrom()` when the revision does not
# exist in the LLVM source tree.
def MockGetGitHashForRevisionRaiseException(src_path, revision):
raise ValueError('Revision does not exist')
@@ -168,7 +169,8 @@ class LLVMBisectionTest(unittest.TestCase):
start, end, parallel, abs_path_to_src, test_pending_revisions,
test_skip_revisions), [])
- @mock.patch.object(LLVMHash, 'GetGitHashForVersion')
+ # Assume llvm_bisection module has imported GetGitHashFrom
+ @mock.patch.object(get_llvm_hash, 'GetGitHashFrom')
def testSuccessfullyRetrievedRevisionsBetweenStartAndEnd(
self, mock_get_git_hash):
@@ -193,9 +195,10 @@ class LLVMBisectionTest(unittest.TestCase):
self.assertEqual(mock_get_git_hash.call_count, 2)
- # Simulate behavior of `GetGitHashForVersion()` when successfully retrieved
+ # Simulate behavior of `GetGitHashFrom()` when successfully retrieved
# a list git hashes for each revision in the revisions list.
- @mock.patch.object(LLVMHash, 'GetGitHashForVersion')
+ # Assume llvm_bisection module has imported GetGitHashFrom
+ @mock.patch.object(get_llvm_hash, 'GetGitHashFrom')
# Simulate behavior of `GetRevisionsBetweenBisection()` when successfully
# retrieved a list of valid revisions between 'start' and 'end'.
@mock.patch.object(llvm_bisection, 'GetRevisionsBetweenBisection')
@@ -216,7 +219,7 @@ class LLVMBisectionTest(unittest.TestCase):
if call_count < 3:
return expected_revisions_and_hash_tuple[1][call_count]
- assert False, 'Called `GetGitHashForVersion()` more than expected.'
+ assert False, 'Called `GetGitHashFrom()` more than expected.'
temp_worktree = '/abs/path/to/tmpDir'
@@ -227,7 +230,7 @@ class LLVMBisectionTest(unittest.TestCase):
mock_get_revisions_between_bisection.return_value = \
expected_revisions_and_hash_tuple[0]
- # Simulate behavior of `GetGitHashForVersion()` by using the testing
+ # Simulate behavior of `GetGitHashFrom()` by using the testing
# function.
mock_get_git_hash.side_effect = MockGetGitHashForRevision
@@ -370,10 +373,11 @@ class LLVMBisectionTest(unittest.TestCase):
self.assertEqual(mock_add_tryjob.call_count, 3)
- # Simulate behavior of `GetGitHashForVersion()` when successfully retrieved
- # the git hash of the bad revision.
+ # Simulate behavior of `GetGitHashFrom()` when successfully retrieved
+ # the git hash of the bad revision. Assume llvm_bisection has imported
+ # GetGitHashFrom
@mock.patch.object(
- LLVMHash, 'GetGitHashForVersion', return_value='a123testhash4')
+ get_llvm_hash, 'GetGitHashFrom', return_value='a123testhash4')
def testCompletedBisectionWhenProvidedSrcPath(self, mock_get_git_hash):
last_tested = '/some/last/tested_file.json'
diff --git a/llvm_tools/llvm_patch_management.py b/llvm_tools/llvm_patch_management.py
index dff992a5..ef8b65c8 100755
--- a/llvm_tools/llvm_patch_management.py
+++ b/llvm_tools/llvm_patch_management.py
@@ -9,10 +9,10 @@
from __future__ import print_function
import argparse
+import get_llvm_hash
import os
-from pipes import quote
-
import patch_manager
+
from assert_not_in_chroot import VerifyOutsideChroot
from failure_modes import FailureModes
from get_llvm_hash import CreateTempLLVMRepo
@@ -97,8 +97,8 @@ def GetCommandLineArgs():
# Duplicate packages were passed into the command line
if len(unique_packages) != len(args_output.packages):
- raise ValueError('Duplicate packages were passed in: %s' %
- ' '.join(args_output.packages))
+ raise ValueError('Duplicate packages were passed in: %s' % ' '.join(
+ args_output.packages))
args_output.packages = unique_packages
@@ -212,7 +212,7 @@ def UpdatePackagesPatchMetadataFile(chroot_path, svn_version,
with CreateTempLLVMRepo(temp_dir) as src_path:
# Ensure that 'svn_version' exists in the chromiumum mirror of LLVM by
# finding its corresponding git hash.
- git_hash = llvm_hash.GetGitHashForVersion(src_path, svn_version)
+ git_hash = get_llvm_hash.GetGitHashFrom(src_path, svn_version)
# Git hash of 'svn_version' exists, so move the source tree's HEAD to
# 'git_hash' via `git checkout`.
@@ -232,10 +232,8 @@ def UpdatePackagesPatchMetadataFile(chroot_path, svn_version,
patch_manager.CleanSrcTree(src_path)
# Get the patch results for the current package.
- patches_info = patch_manager.HandlePatches(svn_version,
- patch_metadata_path,
- filesdir_path, src_path,
- mode)
+ patches_info = patch_manager.HandlePatches(
+ svn_version, patch_metadata_path, filesdir_path, src_path, mode)
package_info[cur_package] = patches_info._asdict()
diff --git a/llvm_tools/llvm_patch_management_unittest.py b/llvm_tools/llvm_patch_management_unittest.py
index c9bc7fce..75f003e9 100755
--- a/llvm_tools/llvm_patch_management_unittest.py
+++ b/llvm_tools/llvm_patch_management_unittest.py
@@ -7,16 +7,17 @@
"""Unit tests when creating the arguments for the patch manager."""
from __future__ import print_function
-
from collections import namedtuple
+from failure_modes import FailureModes
+
+import get_llvm_hash
+import llvm_patch_management
import os
+import patch_manager
+import subprocess
import unittest
import unittest.mock as mock
-from failure_modes import FailureModes
-from get_llvm_hash import LLVMHash
-import llvm_patch_management
-import patch_manager
class LlvmPatchManagementTest(unittest.TestCase):
@@ -142,10 +143,10 @@ class LlvmPatchManagementTest(unittest.TestCase):
mock_isfile.assert_called_once()
- # Simulate `GetGitHashForVersion()` when successfully retrieved the git hash
+ # Simulate `GetGitHashFrom()` when successfully retrieved the git hash
# of the version passed in.
@mock.patch.object(
- LLVMHash, 'GetGitHashForVersion', return_value='a123testhash1')
+ get_llvm_hash, 'GetGitHashFrom', return_value='a123testhash1')
# Simulate `CreateTempLLVMRepo()` when successfully created a work tree from
# the LLVM repo copy in `llvm_tools` directory.
@mock.patch.object(llvm_patch_management, 'CreateTempLLVMRepo')
@@ -215,10 +216,10 @@ class LlvmPatchManagementTest(unittest.TestCase):
# Simulate `CleanSrcTree()` when successfully removed changes from the
# worktree.
@mock.patch.object(patch_manager, 'CleanSrcTree')
- # Simulate `GetGitHashForVersion()` when successfully retrieved the git hash
+ # Simulate `GetGitHashFrom()` when successfully retrieved the git hash
# of the version passed in.
@mock.patch.object(
- LLVMHash, 'GetGitHashForVersion', return_value='a123testhash1')
+ get_llvm_hash, 'GetGitHashFrom', return_value='a123testhash1')
# Simulate `CreateTempLLVMRepo()` when successfully created a work tree from
# the LLVM repo copy in `llvm_tools` directory.
@mock.patch.object(llvm_patch_management, 'CreateTempLLVMRepo')
diff --git a/llvm_tools/patch_manager.py b/llvm_tools/patch_manager.py
index 806b944f..c51ba200 100755
--- a/llvm_tools/patch_manager.py
+++ b/llvm_tools/patch_manager.py
@@ -147,14 +147,13 @@ def GetCommandLineArgs():
def GetHEADSVNVersion(src_path):
"""Gets the SVN version of HEAD in the src tree."""
- get_head_cmd = ['git', '-C', src_path, 'log', '-1', '--pretty=%B']
+ cmd = ['git', '-C', src_path, 'rev-parse', 'HEAD']
- head_commit_message = check_output(get_head_cmd)
+ git_hash = check_output(cmd)
- head_svn_version = LLVMHash().GetSVNVersionFromCommitMessage(
- head_commit_message)
+ version = GetVersionFrom(src_path, git_hash)
- return head_svn_version
+ return version
def VerifyHEADIsTheSameAsSVNVersion(src_path, svn_version):
@@ -282,11 +281,9 @@ def GetCommitHashesForBisection(src_path, good_svn_version, bad_svn_version):
new_llvm_hash = LLVMHash()
- bad_commit_hash = new_llvm_hash.GetGitHashForVersion(src_path,
- bad_svn_version)
+ bad_commit_hash = get_llvm_hash.GetGitHashFrom(src_path, bad_svn_version)
- good_commit_hash = new_llvm_hash.GetGitHashForVersion(src_path,
- good_svn_version)
+ good_commit_hash = get_llvm_hash.GetGitHashFrom(src_path, good_svn_version)
return good_commit_hash, bad_commit_hash
@@ -295,13 +292,13 @@ def PerformBisection(src_path, good_commit, bad_commit, svn_version,
patch_metadata_file, filesdir_path, num_patches):
"""Performs bisection to determine where a patch stops applying."""
- bisect_start_cmd = [
+ start_cmd = [
'git', '-C', src_path, 'bisect', 'start', bad_commit, good_commit
]
- check_output(bisect_start_cmd)
+ check_output(start_cmd)
- bisect_run_cmd = [
+ run_cmd = [
'git', '-C', src_path, 'bisect', 'run',
os.path.abspath(__file__), '--svn_version',
'%d' % svn_version, '--patch_metadata_file', patch_metadata_file,
@@ -310,25 +307,24 @@ def PerformBisection(src_path, good_commit, bad_commit, svn_version,
'%d' % num_patches
]
- check_call(bisect_run_cmd)
+ check_call(run_cmd)
# Successfully bisected the patch, so retrieve the SVN version from the
# commit message.
- get_bad_commit_from_bisect_run_cmd = [
- 'git', '-C', src_path, 'show', 'refs/bisect/bad'
+ get_bad_commit_hash_cmd = [
+ 'git', '-C', src_path, 'rev-parse', 'refs/bisect/bad'
]
- bad_commit_message = check_output(get_bad_commit_from_bisect_run_cmd)
+ git_hash = check_output(get_bad_commit_hash_cmd)
- end_bisection_cmd = ['git', '-C', src_path, 'bisect', 'reset']
+ end_cmd = ['git', '-C', src_path, 'bisect', 'reset']
- check_output(end_bisection_cmd)
+ check_output(end_cmd)
# `git bisect run` returns the bad commit hash and the commit message.
- bad_version = LLVMHash().GetSVNVersionFromCommitMessage(
- bad_commit_message.rstrip())
+ version = GetVersionFrom(src_path, git_hash)
- return bad_version
+ return version
def CleanSrcTree(src_path):