autoPatchelfHook: add `patchelfFlags` option

This may be useful. Eventually. Maybe.

K900 10cb2bd4 c3c65740

+17 -7
+14 -6
pkgs/build-support/setup-hooks/auto-patchelf.py
··· 174 174 found: bool = False # Whether it was found somewhere 175 175 176 176 177 - def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]: 177 + def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = [], extra_args: List[str] = []) -> list[Dependency]: 178 178 try: 179 179 with open_elf(path) as elf: 180 180 ··· 213 213 if file_is_dynamic_executable: 214 214 print("setting interpreter of", path) 215 215 subprocess.run( 216 - ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()], 216 + ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()] + extra_args, 217 217 check=True) 218 218 rpath += runtime_deps 219 219 ··· 250 250 if rpath: 251 251 print("setting RPATH to:", rpath_str) 252 252 subprocess.run( 253 - ["patchelf", "--set-rpath", rpath_str, path.as_posix()], 253 + ["patchelf", "--set-rpath", rpath_str, path.as_posix()] + extra_args, 254 254 check=True) 255 255 256 256 return dependencies ··· 262 262 runtime_deps: List[Path], 263 263 recursive: bool = True, 264 264 ignore_missing: List[str] = [], 265 - append_rpaths: List[Path] = []) -> None: 265 + append_rpaths: List[Path] = [], 266 + extra_args: List[str] = []) -> None: 266 267 267 268 if not paths_to_patch: 268 269 sys.exit("No paths to patch, stopping.") ··· 275 276 dependencies = [] 276 277 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 277 278 if not path.is_symlink() and path.is_file(): 278 - dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths) 279 + dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths, extra_args) 279 280 280 281 missing = [dep for dep in dependencies if not dep.found] 281 282 ··· 333 334 type=Path, 334 335 help="Paths to append to all runtime paths unconditionally", 335 336 ) 337 + parser.add_argument( 338 + "--extra-args", 339 + nargs="*", 340 + type=str, 341 + help="Extra arguments to pass to patchelf" 342 + ) 336 343 337 344 print("automatically fixing dependencies for ELF files") 338 345 args = parser.parse_args() ··· 344 351 args.runtime_dependencies, 345 352 args.recursive, 346 353 args.ignore_missing, 347 - append_rpaths=args.append_rpaths) 354 + append_rpaths=args.append_rpaths, 355 + extra_args=args.extra_args) 348 356 349 357 350 358 interpreter_path: Path = None # type: ignore
+3 -1
pkgs/build-support/setup-hooks/auto-patchelf.sh
··· 63 63 64 64 local appendRunpathsArray=($appendRunpaths) 65 65 local runtimeDependenciesArray=($runtimeDependencies) 66 + local patchelfFlagsArray=($patchelfFlags) 66 67 @pythonInterpreter@ @autoPatchelfScript@ \ 67 68 ${norecurse:+--no-recurse} \ 68 69 --ignore-missing "${ignoreMissingDepsArray[@]}" \ ··· 70 71 --libs "${autoPatchelfLibs[@]}" \ 71 72 "${extraAutoPatchelfLibs[@]}" \ 72 73 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 73 - --append-rpaths "${appendRunpathsArray[@]}" 74 + --append-rpaths "${appendRunpathsArray[@]}" \ 75 + --extra-args "${patchelfFlagsArray[@]}" 74 76 } 75 77 76 78 # XXX: This should ultimately use fixupOutputHooks but we currently don't have