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>
This commit is contained in:
aszlig 2018-11-19 23:23:38 +01:00
parent e4fbb244ee
commit 3ca35ce0b2
No known key found for this signature in database
GPG key ID: 684089CE67EBB691

View file

@ -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)