summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/auto-patchelf.sh
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-11-19 23:23:38 +0100
committeraszlig <aszlig@nix.build>2018-11-20 00:11:29 +0100
commit3ca35ce0b2dd1adb11044e03a816c77a72f7135d (patch)
tree6568304b95fec00339b1a84d806f6f1368e23276 /pkgs/build-support/setup-hooks/auto-patchelf.sh
parente4fbb244ee313a3003144e8e148341c9e5c67295 (diff)
downloadnixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar.gz
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar.bz2
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar.lz
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar.xz
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.tar.zst
nixpkgs-3ca35ce0b2dd1adb11044e03a816c77a72f7135d.zip
autoPatchelfHook: Add --no-recurse flag
This is to be used with the autoPatchelf command and allows to only
patch a specific file or directory without recursing into
subdirectories.

Apart from being able to run the command in a standalone way, as
detailled in the previous commit this is also needed for the Android SDK
emulator, because according to @svanderburg there are subdirectories we
don't want to patch.

The reason why I didn't use GNU getopt is that it might not be available
on all operating systems and the getopts bash builtin doesn't support
long arguments. Apart from that, the implementation for recognizing the
flag is pretty trivial and it's also using bash builtins only, so if we
want to do something really fancy someday, we can still change it.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/build-support/setup-hooks/auto-patchelf.sh')
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh26
1 files changed, 23 insertions, 3 deletions
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index 62348d71ed0..43b1679670d 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -148,12 +148,32 @@ autoPatchelfFile() {
 }
 
 autoPatchelf() {
+    local -a findOpts=()
+
+    while [ $# -gt 0 ]; do
+        case "$1" in
+            --) shift; break;;
+            --no-recurse) shift; findOpts+=("-maxdepth" 1);;
+            --*)
+                echo "autoPatchelf: ERROR: Invalid command line" \
+                     "argument: $1" >&2
+                return 1;;
+            *) break;;
+        esac
+    done
+
+    if [ $# -eq 0 ]; then
+        echo "autoPatchelf: No paths to patch specified." >&2
+        return 1
+    fi
+
     echo "automatically fixing dependencies for ELF files" >&2
 
     # Add all shared objects of the current output path to the start of
     # cachedDependencies so that it's choosen first in findDependency.
     cachedDependencies+=(
-        $(find "$@" \! -type d \( -name '*.so' -o -name '*.so.*' \))
+        $(find "$@" "${findOpts[@]}" \! -type d \
+               \( -name '*.so' -o -name '*.so.*' \))
     )
     local elffile
 
@@ -169,7 +189,7 @@ autoPatchelf() {
           LANG=C readelf -l "$file" | grep -q "^ *INTERP\\>" || continue
       fi
       autoPatchelfFile "$file"
-    done < <(find "$@" -type f -print0)
+    done < <(find "$@" "${findOpts[@]}" -type f -print0)
 }
 
 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
@@ -182,7 +202,7 @@ autoPatchelf() {
 # fixupOutput and the postFixup hook runs later.
 postFixupHooks+=('
     if [ -z "$dontAutoPatchelf" ]; then
-        autoPatchelf $(for output in $outputs; do
+        autoPatchelf -- $(for output in $outputs; do
             [ -e "${!output}" ] || continue
             echo "${!output}"
         done)