diff options
Diffstat (limited to 'llvm_tools/update_chromeos_llvm_hash.py')
-rwxr-xr-x | llvm_tools/update_chromeos_llvm_hash.py | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/llvm_tools/update_chromeos_llvm_hash.py b/llvm_tools/update_chromeos_llvm_hash.py index ea09af48..f6161773 100755 --- a/llvm_tools/update_chromeos_llvm_hash.py +++ b/llvm_tools/update_chromeos_llvm_hash.py @@ -10,6 +10,7 @@ for review. """ import argparse +import dataclasses import enum import os from pathlib import Path @@ -28,14 +29,8 @@ import patch_utils import subprocess_helpers -DEFAULT_PACKAGES = [ - "dev-util/lldb-server", - "sys-devel/llvm", - "sys-libs/compiler-rt", - "sys-libs/libcxx", - "sys-libs/llvm-libunwind", - "sys-libs/scudo", -] +# Default list of packages to update. +DEFAULT_PACKAGES = patch_utils.CHROMEOS_PATCHES_JSON_PACKAGES DEFAULT_MANIFEST_PACKAGES = ["sys-devel/llvm"] @@ -48,19 +43,28 @@ class LLVMVariant(enum.Enum): next = "LLVM_NEXT_HASH" +@dataclasses.dataclass(frozen=True, eq=True) +class ChrootOpts: + """A class that holds chroot options.""" + + chromeos_root: Path + chroot_name: str = "chroot" + out_name: str = "out" + + class PortagePackage: """Represents a portage package with location info.""" - def __init__(self, chromeos_root: Path, package: str): + def __init__(self, chroot_opts: ChrootOpts, package: str): """Create a new PortagePackage. Args: - chromeos_root: Path to the root of the code checkout. + chroot_opts: options that specify the ChromeOS chroot to use. package: "category/package" string. """ self.package = package potential_ebuild_path = PortagePackage.find_package_ebuild( - chromeos_root, package + chroot_opts, package ) if potential_ebuild_path.is_symlink(): self.uprev_target: Optional[Path] = potential_ebuild_path.absolute() @@ -71,12 +75,14 @@ class PortagePackage: self.ebuild_path = potential_ebuild_path.absolute() @staticmethod - def find_package_ebuild(chromeos_root: Path, package: str) -> Path: + def find_package_ebuild(chroot_opts: ChrootOpts, package: str) -> Path: """Look up the package's ebuild location.""" - chromeos_root_str = str(chromeos_root) + chromeos_root_str = str(chroot_opts.chromeos_root) ebuild_paths = chroot.GetChrootEbuildPaths( chromeos_root_str, [package], + chroot_opts.chroot_name, + chroot_opts.out_name, ) converted = chroot.ConvertChrootPathsToAbsolutePaths( chromeos_root_str, ebuild_paths @@ -133,7 +139,7 @@ class PortagePackage: def defaultCrosRoot() -> Path: - """Get default location of chroot_path. + """Get default location of chromeos_path. The logic assumes that the cros_root is ~/chromiumos, unless llvm_tools is inside of a CrOS checkout, in which case that checkout should be used. @@ -164,7 +170,7 @@ def GetCommandLineArgs(): # Add argument for a specific chroot path. parser.add_argument( - "--chroot_path", + "--chromeos_path", type=Path, default=defaultCrosRoot(), help="the path to the chroot (default: %(default)s)", @@ -211,7 +217,6 @@ def GetCommandLineArgs(): failure_modes.FailureModes.FAIL.value, failure_modes.FailureModes.CONTINUE.value, failure_modes.FailureModes.DISABLE_PATCHES.value, - failure_modes.FailureModes.REMOVE_PATCHES.value, ], help="the mode of the patch manager when handling failed patches " "(default: %(default)s)", @@ -225,9 +230,10 @@ def GetCommandLineArgs(): "metadata if applicable (default: PATCHES.json inside $FILESDIR)", ) parser.add_argument( - "--repo_manifest", - action="store_true", - help="Updates the llvm-project revision attribute" + "--no_repo_manifest", + dest="repo_manifest", + action="store_false", + help="Skip updating the llvm-project revision attribute" " in the internal manifest.", ) parser.add_argument( @@ -523,24 +529,26 @@ def StagePackagesPatchResultsForCommit( return commit_messages -def UpdatePortageManifests(packages: Iterable[str], chroot_path: Path) -> None: +def UpdatePortageManifests( + packages: Iterable[str], chromeos_path: Path +) -> None: """Updates portage manifest files for packages. Args: packages: A list of packages to update manifests for. - chroot_path: The absolute path to the chroot. + chromeos_path: The absolute path to the chromeos checkout. Raises: CalledProcessError: ebuild failed to update manifest. """ - manifest_ebuilds = chroot.GetChrootEbuildPaths(chroot_path, packages) + manifest_ebuilds = chroot.GetChrootEbuildPaths(chromeos_path, packages) for ebuild_path in manifest_ebuilds: ebuild_dir = os.path.dirname(ebuild_path) subprocess_helpers.ChrootRunCommand( - chroot_path, ["ebuild", ebuild_path, "manifest"] + chromeos_path, ["ebuild", ebuild_path, "manifest"] ) subprocess_helpers.ChrootRunCommand( - chroot_path, ["git", "-C", ebuild_dir, "add", "Manifest"] + chromeos_path, ["git", "-C", ebuild_dir, "add", "Manifest"] ) @@ -550,12 +558,13 @@ def UpdatePackages( llvm_variant: LLVMVariant, git_hash: str, svn_version: int, - chroot_path: Path, + chroot_opts: ChrootOpts, mode: Optional[failure_modes.FailureModes], git_hash_source: Union[int, str], extra_commit_msg_lines: Optional[Iterable[str]], delete_branch: bool = True, upload_changes: bool = True, + wip: bool = False, ) -> Optional[git.CommitContents]: """Updates an LLVM hash and uprevs the ebuild of the packages. @@ -568,7 +577,7 @@ def UpdatePackages( llvm_variant: The LLVM hash to update. git_hash: The new git hash. svn_version: The SVN-style revision number of git_hash. - chroot_path: The absolute path to the chroot. + chroot_opts: options that specify the ChromeOS chroot to use. mode: The mode of the patch manager when handling an applicable patch. If None is passed, the patch manager won't be invoked. that failed to apply. @@ -579,14 +588,15 @@ def UpdatePackages( Newlines are added automatically. delete_branch: Delete the git branch as a final step. upload_changes: Upload the commit to gerrit as a CL. + wip: if True, any changes uploaded will be uploaded as + work-in-progress. Returns: If upload_changes is set, a git.CommitContents object. Otherwise None. """ - - portage_packages = (PortagePackage(chroot_path, pkg) for pkg in packages) + portage_packages = (PortagePackage(chroot_opts, pkg) for pkg in packages) chromiumos_overlay_path = ( - chroot_path / "src" / "third_party" / "chromiumos-overlay" + chroot_opts.chromeos_root / "src" / "third_party" / "chromiumos-overlay" ) branch_name = "update-" + llvm_variant.value + "-" + git_hash @@ -615,14 +625,14 @@ def UpdatePackages( updated_packages.append(pkg.package) commit_lines.append(pkg.package) if manifest_packages: - UpdatePortageManifests(manifest_packages, chroot_path) + UpdatePortageManifests(manifest_packages, chroot_opts.chromeos_root) commit_lines.append("Updated manifest for:") commit_lines.extend(manifest_packages) - EnsurePackageMaskContains(chroot_path, git_hash) + EnsurePackageMaskContains(chroot_opts.chromeos_root, git_hash) # Handle the patches for each package. if mode is not None: package_info_dict = UpdatePackagesPatchMetadataFile( - chroot_path, svn_version, updated_packages, mode + chroot_opts, svn_version, updated_packages, mode ) # Update the commit message if changes were made to a package's # patches. @@ -634,7 +644,9 @@ def UpdatePackages( git.CommitChanges(chromiumos_overlay_path, commit_lines) if upload_changes: change_list = git.UploadChanges( - chromiumos_overlay_path, branch_name + chromiumos_overlay_path, + branch_name, + wip=wip, ) finally: if delete_branch: @@ -645,12 +657,12 @@ def UpdatePackages( def EnsurePackageMaskContains( - chroot_path: Union[Path, str], git_hash: str + chromeos_path: Union[Path, str], git_hash: str ) -> None: """Adds the major version of llvm to package.mask if not already present. Args: - chroot_path: The absolute path to the chroot. + chromeos_path: The absolute path to the chromeos checkout. git_hash: The new git hash. Raises: @@ -660,7 +672,7 @@ def EnsurePackageMaskContains( llvm_major_version = get_llvm_hash.GetLLVMMajorVersion(git_hash) overlay_dir = os.path.join( - chroot_path, "src/third_party/chromiumos-overlay" + chromeos_path, "src/third_party/chromiumos-overlay" ) mask_path = os.path.join( overlay_dir, "profiles/targets/chromeos/package.mask" @@ -675,7 +687,7 @@ def EnsurePackageMaskContains( def UpdatePackagesPatchMetadataFile( - chroot_path: Path, + chroot_opts: ChrootOpts, svn_version: int, packages: Iterable[str], mode: failure_modes.FailureModes, @@ -683,7 +695,7 @@ def UpdatePackagesPatchMetadataFile( """Updates the packages metadata file. Args: - chroot_path: The absolute path to the chroot. + chroot_opts: options that specify the ChromeOS chroot to use. svn_version: The version to use for patch management. packages: All the packages to update their patch metadata file. mode: The mode for the patch manager to use when an applicable patch @@ -712,7 +724,10 @@ def UpdatePackagesPatchMetadataFile( for cur_package in packages: # Get the absolute path to $FILESDIR of the package. chroot_ebuild_str = subprocess_helpers.ChrootRunCommand( - chroot_path, ["equery", "w", cur_package] + chroot_opts.chromeos_root, + ["equery", "w", cur_package], + chroot_name=chroot_opts.chroot_name, + out_name=chroot_opts.out_name, ).strip() if not chroot_ebuild_str: raise RuntimeError( @@ -720,7 +735,7 @@ def UpdatePackagesPatchMetadataFile( ) chroot_ebuild_path = Path( chroot.ConvertChrootPathsToAbsolutePaths( - str(chroot_path), [chroot_ebuild_str] + str(chroot_opts.chromeos_root), [chroot_ebuild_str] )[0] ) patches_json_fp = ( @@ -744,10 +759,6 @@ def UpdatePackagesPatchMetadataFile( continue_on_failure=mode == failure_modes.FailureModes.CONTINUE, ) - elif mode == failure_modes.FailureModes.REMOVE_PATCHES: - patches_info = patch_utils.remove_old_patches( - svn_version, src_path, patches_json_fp - ) elif mode == failure_modes.FailureModes.DISABLE_PATCHES: patches_info = patch_utils.update_version_ranges( svn_version, src_path, patches_json_fp @@ -835,7 +846,7 @@ def main(): args_output = GetCommandLineArgs() - chroot.VerifyChromeOSRoot(args_output.chroot_path) + chroot.VerifyChromeOSRoot(args_output.chromeos_path) llvm_variant = LLVMVariant.current if args_output.is_llvm_next: @@ -866,7 +877,7 @@ def main(): llvm_variant=llvm_variant, git_hash=git_hash, svn_version=svn_version, - chroot_path=args_output.chroot_path, + chroot_opts=ChrootOpts(args_output.chromeos_path), mode=patch_update_mode, git_hash_source=git_hash_source, extra_commit_msg_lines=None, @@ -880,7 +891,7 @@ def main(): else: print("--no-upload passed, did not create a change list") - if args_output.repo_manifest: + if args_output.repo_manifest and not args_output.is_llvm_next: print( f"Updating internal manifest to {git_hash} ({svn_version})...", end="", @@ -892,7 +903,7 @@ def main(): ) change_list = ChangeRepoManifest( git_hash, - args_output.chroot_path, + args_output.chromeos_path, extra_commit_msg_lines=cq_depend_line, delete_branch=not args_output.no_delete_branch, upload_changes=not args_output.no_upload_changes, |