mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-25 03:17:13 +00:00
e4d17dc558
Use "find -exec" to strip rather than "find … | xargs …". The former ensures that stripping is attempted for each file, whereas the latter will stop stripping at the first failure. Unstripped files can fool runtime dependency detection and bloat closure sizes.
58 lines
1.6 KiB
Bash
58 lines
1.6 KiB
Bash
# This setup hook strips libraries and executables in the fixup phase.
|
|
|
|
fixupOutputHooks+=(_doStrip)
|
|
|
|
_doStrip() {
|
|
# We don't bother to strip build platform code because it shouldn't make it
|
|
# to $out anyways---if it does, that's a bigger problem that a lack of
|
|
# stripping will help catch.
|
|
local -ra flags=(dontStripHost dontStripTarget)
|
|
local -ra stripCmds=(STRIP TARGET_STRIP)
|
|
|
|
# Optimization
|
|
if [[ "${STRIP-}" == "${TARGET_STRIP-}" ]]; then
|
|
dontStripTarget+=1
|
|
fi
|
|
|
|
local i
|
|
for i in ${!stripCmds[@]}; do
|
|
local -n flag="${flags[$i]}"
|
|
local -n stripCmd="${stripCmds[$i]}"
|
|
|
|
# `dontStrip` disables them all
|
|
if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null
|
|
then continue; fi
|
|
|
|
stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
|
|
if [ -n "$stripDebugList" ]; then
|
|
stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}"
|
|
fi
|
|
|
|
stripAllList=${stripAllList:-}
|
|
if [ -n "$stripAllList" ]; then
|
|
stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}"
|
|
fi
|
|
done
|
|
}
|
|
|
|
stripDirs() {
|
|
local cmd="$1"
|
|
local dirs="$2"
|
|
local stripFlags="$3"
|
|
local dirsNew=
|
|
|
|
local d
|
|
for d in ${dirs}; do
|
|
if [ -d "$prefix/$d" ]; then
|
|
dirsNew="${dirsNew} $prefix/$d "
|
|
fi
|
|
done
|
|
dirs=${dirsNew}
|
|
|
|
if [ -n "${dirs}" ]; then
|
|
header "stripping (with command $cmd and flags $stripFlags) in$dirs"
|
|
find $dirs -type f -exec $cmd $commonStripFlags $stripFlags '{}' \; #
|
|
stopNest
|
|
fi
|
|
}
|