aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan R Abrahams-Whitehead <ajordanr@google.com>2022-07-21 20:28:59 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-21 21:13:25 +0000
commit081dbfe709ba03290ee6203098b844b78317961c (patch)
tree63c355a2e5a8f8449b4744b0db3da763e528a584
parentb3b2c8514865be8650dc9c4f42fd081a255643b8 (diff)
downloadtoolchain-utils-081dbfe709ba03290ee6203098b844b78317961c.tar.gz
llvm_tools: Clean up on apply_all_from_json
At present, update_chromeos_llvm_hash.py will keep trying to apply patches from separate llvm subprojects, to the same LLVM dir. This causes patches to stack, so that the second time it applies the same patch it then fails to apply. This commit fixes the issue by cleaning up the git directory on every stage of the loop. This commit also fixes some type casts. BUG=b:239279349, b:239280701 TEST=./update_chromeos_llvm_hash_unittest.py TEST=./update_packages_and_run_tests.py \ --extra_change_lists 1394249 1986966 \ --chroot_path $CROS_ROOT \ --llvm_version google3 cq Change-Id: I6cc853d80c47fefaba4ff0b5133787b716177567 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3780679 Commit-Queue: Jordan Abrahams-Whitehead <ajordanr@google.com> Tested-by: Jordan Abrahams-Whitehead <ajordanr@google.com> Reviewed-by: Christopher Di Bella <cjdb@google.com> Commit-Queue: Christopher Di Bella <cjdb@google.com> Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
-rwxr-xr-xllvm_tools/update_chromeos_llvm_hash.py20
-rwxr-xr-xllvm_tools/update_chromeos_llvm_hash_unittest.py6
2 files changed, 14 insertions, 12 deletions
diff --git a/llvm_tools/update_chromeos_llvm_hash.py b/llvm_tools/update_chromeos_llvm_hash.py
index efa84ead..fe13f708 100755
--- a/llvm_tools/update_chromeos_llvm_hash.py
+++ b/llvm_tools/update_chromeos_llvm_hash.py
@@ -616,11 +616,11 @@ def UpdatePackagesPatchMetadataFile(
llvm_hash = get_llvm_hash.LLVMHash()
with llvm_hash.CreateTempDirectory() as temp_dir:
- with get_llvm_hash.CreateTempLLVMRepo(temp_dir) as src_path:
+ with get_llvm_hash.CreateTempLLVMRepo(temp_dir) as dirname:
# Ensure that 'svn_version' exists in the chromiumum mirror of LLVM by
# finding its corresponding git hash.
- git_hash = get_llvm_hash.GetGitHashFrom(src_path, svn_version)
- move_head_cmd = ['git', '-C', src_path, 'checkout', git_hash, '-q']
+ git_hash = get_llvm_hash.GetGitHashFrom(dirname, svn_version)
+ move_head_cmd = ['git', '-C', dirname, 'checkout', git_hash, '-q']
subprocess.run(move_head_cmd, stdout=subprocess.DEVNULL, check=True)
for cur_package in packages:
@@ -636,12 +636,14 @@ def UpdatePackagesPatchMetadataFile(
if not patches_json_fp.is_file():
raise RuntimeError(f'patches file {patches_json_fp} is not a file')
- patches_info = patch_utils.apply_all_from_json(
- svn_version=svn_version,
- llvm_src_dir=Path(src_path),
- patches_json_fp=patches_json_fp,
- continue_on_failure=mode == failure_modes.FailureModes.CONTINUE,
- )
+ src_path = Path(dirname)
+ with patch_utils.git_clean_context(src_path):
+ patches_info = patch_utils.apply_all_from_json(
+ svn_version=svn_version,
+ llvm_src_dir=src_path,
+ patches_json_fp=patches_json_fp,
+ continue_on_failure=mode == failure_modes.FailureModes.CONTINUE,
+ )
package_info[cur_package] = patches_info._asdict()
return package_info
diff --git a/llvm_tools/update_chromeos_llvm_hash_unittest.py b/llvm_tools/update_chromeos_llvm_hash_unittest.py
index 569fdcc4..35872324 100755
--- a/llvm_tools/update_chromeos_llvm_hash_unittest.py
+++ b/llvm_tools/update_chromeos_llvm_hash_unittest.py
@@ -653,7 +653,7 @@ class UpdateLLVMHashTest(unittest.TestCase):
llvm_variant = update_chromeos_llvm_hash.LLVMVariant.next
git_hash = 'a123testhash4'
svn_version = 1000
- chroot_path = '/some/path/to/chroot'
+ chroot_path = Path('/some/path/to/chroot')
patch_metadata_file = 'PATCHES.json'
git_hash_source = 'google3'
branch = 'update-LLVM_NEXT_HASH-a123testhash4'
@@ -731,7 +731,7 @@ class UpdateLLVMHashTest(unittest.TestCase):
# patch results contains a disabled patch in 'disable_patches' mode.
def RetrievedPatchResults(chroot_path, svn_version, packages, mode):
- self.assertEqual(chroot_path, '/some/path/to/chroot')
+ self.assertEqual(chroot_path, Path('/some/path/to/chroot'))
self.assertEqual(svn_version, 1000)
self.assertEqual(patch_metadata_file, 'PATCHES.json')
self.assertListEqual(packages, ['path/to'])
@@ -786,8 +786,8 @@ class UpdateLLVMHashTest(unittest.TestCase):
llvm_variant = update_chromeos_llvm_hash.LLVMVariant.next
git_hash = 'a123testhash5'
svn_version = 1000
- chroot_path = '/some/path/to/chroot'
patch_metadata_file = 'PATCHES.json'
+ chroot_path = Path('/some/path/to/chroot')
git_hash_source = 'tot'
branch = 'update-LLVM_NEXT_HASH-a123testhash5'
extra_commit_msg = '\ncommit-message-end'