Commit 10cb2bd4 authored by K900's avatar K900
Browse files

autoPatchelfHook: add `patchelfFlags` option

This may be useful. Eventually. Maybe.
parent c3c65740
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ class Dependency:
    found: bool = False     # Whether it was found somewhere


def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]:
def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = [], extra_args: List[str] = []) -> list[Dependency]:
    try:
        with open_elf(path) as elf:

@@ -213,7 +213,7 @@ def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List
    if file_is_dynamic_executable:
        print("setting interpreter of", path)
        subprocess.run(
                ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()],
                ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()] + extra_args,
                check=True)
        rpath += runtime_deps

@@ -250,7 +250,7 @@ def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List
    if rpath:
        print("setting RPATH to:", rpath_str)
        subprocess.run(
                ["patchelf", "--set-rpath", rpath_str, path.as_posix()],
                ["patchelf", "--set-rpath", rpath_str, path.as_posix()] + extra_args,
                check=True)

    return dependencies
@@ -262,7 +262,8 @@ def auto_patchelf(
        runtime_deps: List[Path],
        recursive: bool = True,
        ignore_missing: List[str] = [],
        append_rpaths: List[Path] = []) -> None:
        append_rpaths: List[Path] = [],
        extra_args: List[str] = []) -> None:

    if not paths_to_patch:
        sys.exit("No paths to patch, stopping.")
@@ -275,7 +276,7 @@ def auto_patchelf(
    dependencies = []
    for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch):
        if not path.is_symlink() and path.is_file():
            dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths)
            dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths, extra_args)

    missing = [dep for dep in dependencies if not dep.found]

@@ -333,6 +334,12 @@ def main() -> None:
        type=Path,
        help="Paths to append to all runtime paths unconditionally",
    )
    parser.add_argument(
        "--extra-args",
        nargs="*",
        type=str,
        help="Extra arguments to pass to patchelf"
    )

    print("automatically fixing dependencies for ELF files")
    args = parser.parse_args()
@@ -344,7 +351,8 @@ def main() -> None:
        args.runtime_dependencies,
        args.recursive,
        args.ignore_missing,
        append_rpaths=args.append_rpaths)
        append_rpaths=args.append_rpaths,
        extra_args=args.extra_args)


interpreter_path: Path  = None # type: ignore
+3 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ autoPatchelf() {

    local appendRunpathsArray=($appendRunpaths)
    local runtimeDependenciesArray=($runtimeDependencies)
    local patchelfFlagsArray=($patchelfFlags)
    @pythonInterpreter@ @autoPatchelfScript@                            \
        ${norecurse:+--no-recurse}                                      \
        --ignore-missing "${ignoreMissingDepsArray[@]}"                 \
@@ -70,7 +71,8 @@ autoPatchelf() {
        --libs "${autoPatchelfLibs[@]}"                                 \
               "${extraAutoPatchelfLibs[@]}"                            \
        --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}"  \
        --append-rpaths "${appendRunpathsArray[@]}"
        --append-rpaths "${appendRunpathsArray[@]}"                     \
        --extra-args "${patchelfFlagsArray[@]}"
}

# XXX: This should ultimately use fixupOutputHooks but we currently don't have