diff options
-rwxr-xr-x | llvm_tools/chroot.py | 17 | ||||
-rwxr-xr-x | llvm_tools/get_llvm_hash.py | 16 |
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): |