aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2024-04-16 16:58:35 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-16 23:37:30 +0000
commita37c013c31fd5b50a5ac48353e3ac33ec49c01b3 (patch)
tree05f9e5566f58d811535ba246e3db1fa46c746052
parentc6733c05ba5253d8c7606dfe8a8a86611bc66b24 (diff)
downloadtoolchain-utils-a37c013c31fd5b50a5ac48353e3ac33ec49c01b3.tar.gz
llvm_tools: move FindChromeOSRootAbove to chroot.py
This will be used more widely in later CLs. BUG=b:333462347 TEST=unittests Change-Id: Icbba5f343f3e92e347785686c3bb324d53ed46b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5460283 Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org> Tested-by: George Burgess <gbiv@chromium.org> Commit-Queue: George Burgess <gbiv@chromium.org>
-rwxr-xr-xllvm_tools/chroot.py17
-rwxr-xr-xllvm_tools/get_llvm_hash.py16
2 files changed, 20 insertions, 13 deletions
diff --git a/llvm_tools/chroot.py b/llvm_tools/chroot.py
index 1dcf8e66..a104bd63 100755
--- a/llvm_tools/chroot.py
+++ b/llvm_tools/chroot.py
@@ -49,6 +49,23 @@ def VerifyChromeOSRoot(chromeos_root: Union[Path, str]) -> None:
assert path.is_dir(), msg
+def FindChromeOSRootAbove(chromeos_tree_path: Path) -> Path:
+ """Returns the root of a ChromeOS tree, given a path in said tree.
+
+ May return `chromeos_tree_path`, if that's already the root of the tree.
+
+ Raises:
+ ValueError if the given path is not in a ChromeOS tree.
+ """
+ if (chromeos_tree_path / ".repo").exists():
+ return chromeos_tree_path
+
+ for parent in chromeos_tree_path.parents:
+ if (parent / ".repo").exists():
+ return parent
+ raise ValueError(f"{chromeos_tree_path} is not in a repo checkout")
+
+
def GetChrootEbuildPaths(
chromeos_root: Union[Path, str],
packages: Iterable[str],
diff --git a/llvm_tools/get_llvm_hash.py b/llvm_tools/get_llvm_hash.py
index 05e14b58..401a68a5 100755
--- a/llvm_tools/get_llvm_hash.py
+++ b/llvm_tools/get_llvm_hash.py
@@ -17,6 +17,7 @@ import sys
import tempfile
from typing import Iterator, Optional, Tuple, Union
+import chroot
import git_llvm_rev
import llvm_next
import manifest_utils
@@ -363,17 +364,6 @@ def GetLLVMHashAndVersionFromSVNOption(
return git_hash, version
-def _FindChromeOSTreeRoot(chromeos_tree_path: Path) -> Path:
- """Returns the root of a ChromeOS tree, given a path in said tree."""
- if (chromeos_tree_path / ".repo").exists():
- return chromeos_tree_path
-
- for parent in chromeos_tree_path.parents:
- if (parent / ".repo").exists():
- return parent
- raise ValueError(f"{chromeos_tree_path} is not in a repo checkout")
-
-
def GetCrOSCurrentLLVMHash(chromeos_tree: Path) -> str:
"""Retrieves the current ChromeOS LLVM hash.
@@ -385,7 +375,7 @@ def GetCrOSCurrentLLVMHash(chromeos_tree: Path) -> str:
ManifestValueError if the toolchain manifest doesn't match the
expected structure.
"""
- chromeos_root = _FindChromeOSTreeRoot(chromeos_tree)
+ chromeos_root = chroot.FindChromeOSRootAbove(chromeos_tree)
return manifest_utils.extract_current_llvm_hash(chromeos_root)
@@ -499,7 +489,7 @@ def main() -> None:
# be more easily detected (which allows more flexibility in the
# implementation in the future for things outside of what directly
# needs this value).
- chromeos_tree = _FindChromeOSTreeRoot(my_dir)
+ chromeos_tree = chroot.FindChromeOSRootAbove(my_dir)
new_llvm_hash = LLVMHash()
if isinstance(cur_llvm_version, int):