Skip to content

Commit

Permalink
strip setup hook: Learn about only stripping host/target binaries alone
Browse files Browse the repository at this point in the history
`dontStrip` is still a catch-all, but `dontStripHost` and
`dontStripTarget` are also now available for finer-grained disabling.
  • Loading branch information
Ericson2314 committed Dec 31, 2017
1 parent 4ad9a97 commit a1cdc20
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions pkgs/build-support/setup-hooks/strip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,45 @@
fixupOutputHooks+=(_doStrip)

_doStrip() {
if [ -z "$dontStrip" ]; then
# 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 "$stripDebugList" "${stripDebugFlags:--S}"
stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}"
fi

stripAllList=${stripAllList:-}
if [ -n "$stripAllList" ]; then
stripDirs "$stripAllList" "${stripAllFlags:--s}"
stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}"
fi
fi
done
}

stripDirs() {
local dirs="$1"
local stripFlags="$2"
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 "
Expand All @@ -29,8 +50,8 @@ stripDirs() {
dirs=${dirsNew}

if [ -n "${dirs}" ]; then
header "stripping (with flags $stripFlags) in$dirs"
find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $STRIP $commonStripFlags $stripFlags 2>/dev/null || true
header "stripping (with command $cmd and flags $stripFlags) in$dirs"
find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $cmd $commonStripFlags $stripFlags 2>/dev/null || true
stopNest
fi
}

1 comment on commit a1cdc20

@matthewbauer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would you want dontStripHost/dontStripTarget but not dontStrip? It might be a little bit too fine grained IMO.

Please sign in to comment.