diff options
Diffstat (limited to 'llvm_tools/get_upstream_patch.py')
-rwxr-xr-x | llvm_tools/get_upstream_patch.py | 67 |
1 files changed, 15 insertions, 52 deletions
diff --git a/llvm_tools/get_upstream_patch.py b/llvm_tools/get_upstream_patch.py index 52634cd9..7335aade 100755 --- a/llvm_tools/get_upstream_patch.py +++ b/llvm_tools/get_upstream_patch.py @@ -12,7 +12,6 @@ import json import logging import os from pathlib import Path -import shlex import subprocess import sys import typing as t @@ -26,7 +25,7 @@ import patch_utils __DOC_EPILOGUE = """ Example Usage: - get_upstream_patch --chroot_path ~/chromiumos --platform chromiumos \ + get_upstream_patch --chromeos_path ~/chromiumos --platform chromiumos \ --sha 1234567 --sha 890abdc """ @@ -191,41 +190,6 @@ def add_patch( os.rename(temp_file, patches_json_path) -def parse_ebuild_for_assignment(ebuild_path: str, var_name: str) -> str: - # '_pre' filters the LLVM 9.0 ebuild, which we never want to target, from - # this list. - candidates = [ - x - for x in os.listdir(ebuild_path) - if x.endswith(".ebuild") and "_pre" in x - ] - - if not candidates: - raise ValueError("No ebuilds found under %r" % ebuild_path) - - ebuild = os.path.join(ebuild_path, max(candidates)) - with open(ebuild, encoding="utf-8") as f: - var_name_eq = var_name + "=" - for orig_line in f: - if not orig_line.startswith(var_name_eq): - continue - - # We shouldn't see much variety here, so do the simplest thing - # possible. - line = orig_line[len(var_name_eq) :] - # Remove comments - line = line.split("#")[0] - # Remove quotes - parts = shlex.split(line) - if len(parts) != 1: - raise ValueError( - "Expected exactly one quoted value in %r" % orig_line - ) - return parts[0].strip() - - raise ValueError("No %s= line found in %r" % (var_name, ebuild)) - - # Resolves a git ref (or similar) to a LLVM SHA. def resolve_llvm_ref(llvm_dir: t.Union[Path, str], sha: str) -> str: return subprocess.check_output( @@ -309,18 +273,18 @@ def make_cl( git.DeleteBranch(llvm_symlink_dir, branch) -def resolve_symbolic_sha(start_sha: str, llvm_symlink_dir: str) -> str: +def resolve_symbolic_sha(start_sha: str, chromeos_path: Path) -> str: if start_sha == "llvm": - return parse_ebuild_for_assignment(llvm_symlink_dir, "LLVM_HASH") + return get_llvm_hash.LLVMHash().GetCrOSCurrentLLVMHash(chromeos_path) if start_sha == "llvm-next": - return parse_ebuild_for_assignment(llvm_symlink_dir, "LLVM_NEXT_HASH") + return get_llvm_hash.LLVMHash().GetCrOSLLVMNextHash() return start_sha def find_patches_and_make_cl( - chroot_path: str, + chromeos_path: str, patches: t.List[str], start_rev: git_llvm_rev.Rev, llvm_config: git_llvm_rev.LLVMConfig, @@ -360,14 +324,14 @@ def find_patches_and_make_cl( packages = get_package_names(parsed_patch.sha, llvm_config.dir) # Find out the ebuild of the corresponding ChromeOS packages ebuild_paths = chroot.GetChrootEbuildPaths( - chroot_path, + chromeos_path, [ "sys-devel/llvm" if package == "llvm" else "sys-libs/" + package for package in packages ], ) ebuild_paths = chroot.ConvertChrootPathsToAbsolutePaths( - chroot_path, ebuild_paths + chromeos_path, ebuild_paths ) # Create a local patch for all the affected llvm projects try: @@ -390,7 +354,6 @@ def find_patches_and_make_cl( successes.append(parsed_patch.sha) if create_cl: - commit_messages.extend( [ parsed_patch.git_msg(), @@ -492,7 +455,7 @@ def _get_duplicate_shas( def get_from_upstream( - chroot_path: str, + chromeos_path: str, create_cl: bool, start_sha: str, patches: t.List[str], @@ -503,8 +466,8 @@ def get_from_upstream( cc: t.Optional[t.List[str]] = None, ): llvm_symlink = chroot.ConvertChrootPathsToAbsolutePaths( - chroot_path, - chroot.GetChrootEbuildPaths(chroot_path, ["sys-devel/llvm"]), + chromeos_path, + chroot.GetChrootEbuildPaths(chromeos_path, ["sys-devel/llvm"]), )[0] llvm_symlink_dir = os.path.dirname(llvm_symlink) @@ -516,7 +479,7 @@ def get_from_upstream( error_path = os.path.dirname(os.path.dirname(llvm_symlink_dir)) raise ValueError(f"Uncommited changes detected in {error_path}") - start_sha = resolve_symbolic_sha(start_sha, llvm_symlink_dir) + start_sha = resolve_symbolic_sha(start_sha, Path(chromeos_path)) logging.info("Base llvm hash == %s", start_sha) llvm_config = git_llvm_rev.LLVMConfig( @@ -525,7 +488,7 @@ def get_from_upstream( start_sha = resolve_llvm_ref(llvm_config.dir, start_sha) find_patches_and_make_cl( - chroot_path=chroot_path, + chromeos_path=chromeos_path, patches=patches, platforms=platforms, start_rev=git_llvm_rev.translate_sha_to_rev(llvm_config, start_sha), @@ -555,7 +518,7 @@ def main(): epilog=__DOC_EPILOGUE, ) parser.add_argument( - "--chroot_path", + "--chromeos_path", default=os.path.join(os.path.expanduser("~"), "chromiumos"), help="the path to the chroot (default: %(default)s)", ) @@ -604,7 +567,7 @@ def main(): "when --differential appears exactly once.", ) args = parser.parse_args() - chroot.VerifyChromeOSRoot(args.chroot_path) + chroot.VerifyChromeOSRoot(args.chromeos_path) if not (args.sha or args.differential): parser.error("--sha or --differential required") @@ -616,7 +579,7 @@ def main(): ) get_from_upstream( - chroot_path=args.chroot_path, + chromeos_path=args.chromeos_path, allow_failures=args.allow_failures, create_cl=args.create_cl, start_sha=args.start_sha, |