diff options
Diffstat (limited to 'pkgs/build-support/setup-hooks')
4 files changed, 33 insertions, 8 deletions
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.py b/pkgs/build-support/setup-hooks/auto-patchelf.py index 965384b876f..261f5585480 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.py +++ b/pkgs/build-support/setup-hooks/auto-patchelf.py @@ -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 diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh index 0625565606f..371389df427 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -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 diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh index 55e196e654d..e103fe77d9b 100644 --- a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh +++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh @@ -36,5 +36,5 @@ fixDarwinDylibNames() { fixDarwinDylibNamesIn() { local dir="$1" - fixDarwinDylibNames $(find "$dir" -name "*.dylib") + fixDarwinDylibNames $(find "$dir" -name "*.dylib" -o -name "*.so" -o -name "*.so.*") } diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh index 88a50befd73..6cd01f6bf63 100644 --- a/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh @@ -193,8 +193,23 @@ makeCWrapper() { addFlags() { local n flag before after var + + # Disable file globbing, since bash will otherwise try to find + # filenames matching the the value to be prefixed/suffixed if + # it contains characters considered wildcards, such as `?` and + # `*`. We want the value as is, except we also want to split + # it on on the separator; hence we can't quote it. + local reenableGlob=0 + if [[ ! -o noglob ]]; then + reenableGlob=1 + fi + set -o noglob # shellcheck disable=SC2086 before=($1) after=($2) + if (( reenableGlob )); then + set +o noglob + fi + var="argv_tmp" printf '%s\n' "char **$var = calloc(${#before[@]} + argc + ${#after[@]} + 1, sizeof(*$var));" printf '%s\n' "assert($var != NULL);" |