setup-hooks/strip.sh: add strip{All,Debug}ListTarget variables

This change mimics existing strip{All,Debug}List variables to
allow special stripping directories just for Target.

The primary use case in mind is gcc where package has to install
both host and target ELFs. They have to be stripped by their own
strip tools accordingly.

Co-authored-by: Rick van Schijndel <Mindavi@users.noreply.github.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This commit is contained in:
Sergei Trofimovich 2022-07-22 21:22:50 +01:00
parent 17f413f293
commit 0f45ce6e77
2 changed files with 20 additions and 15 deletions

View file

@ -731,6 +731,10 @@ If set, files in `$out/sbin` are not moved to `$out/bin`. By default, they are.
List of directories to search for libraries and executables from which *all* symbols should be stripped. By default, its empty. Stripping all symbols is risky, since it may remove not just debug symbols but also ELF information necessary for normal execution. List of directories to search for libraries and executables from which *all* symbols should be stripped. By default, its empty. Stripping all symbols is risky, since it may remove not just debug symbols but also ELF information necessary for normal execution.
##### `stripAllListTarget` {#var-stdenv-stripAllListTarget}
Like `stripAllList`, but only applies to packages target platform. By default, its empty. Useful when supporting cross compilation.
##### `stripAllFlags` {#var-stdenv-stripAllFlags} ##### `stripAllFlags` {#var-stdenv-stripAllFlags}
Flags passed to the `strip` command applied to the files in the directories listed in `stripAllList`. Defaults to `-s` (i.e. `--strip-all`). Flags passed to the `strip` command applied to the files in the directories listed in `stripAllList`. Defaults to `-s` (i.e. `--strip-all`).
@ -739,6 +743,10 @@ Flags passed to the `strip` command applied to the files in the directories list
List of directories to search for libraries and executables from which only debugging-related symbols should be stripped. It defaults to `lib lib32 lib64 libexec bin sbin`. List of directories to search for libraries and executables from which only debugging-related symbols should be stripped. It defaults to `lib lib32 lib64 libexec bin sbin`.
##### `stripDebugListTarget` {#var-stdenv-stripDebugListTarget}
Like `stripDebugList`, but only applies to packages target platform. By default, its empty. Useful when supporting cross compilation.
##### `stripDebugFlags` {#var-stdenv-stripDebugFlags} ##### `stripDebugFlags` {#var-stdenv-stripDebugFlags}
Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`). Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`).

View file

@ -7,31 +7,29 @@ _doStrip() {
# to $out anyways---if it does, that's a bigger problem that a lack of # to $out anyways---if it does, that's a bigger problem that a lack of
# stripping will help catch. # stripping will help catch.
local -ra flags=(dontStripHost dontStripTarget) local -ra flags=(dontStripHost dontStripTarget)
local -ra debugDirs=(stripDebugList stripDebugListTarget)
local -ra allDirs=(stripAllList stripAllListTarget)
local -ra stripCmds=(STRIP STRIP_FOR_TARGET) local -ra stripCmds=(STRIP STRIP_FOR_TARGET)
# Optimization # Strip only host paths by default. Leave targets as is.
if [[ "${STRIP-}" == "${STRIP_FOR_TARGET-}" ]]; then stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
dontStripTarget+=1 stripDebugListTarget=${stripDebugListTarget:-}
fi stripAllList=${stripAllList:-}
stripAllListTarget=${stripAllListTarget:-}
local i local i
for i in ${!stripCmds[@]}; do for i in ${!stripCmds[@]}; do
local -n flag="${flags[$i]}" local -n flag="${flags[$i]}"
local -n debugDirList="${debugDirs[$i]}"
local -n allDirList="${allDirs[$i]}"
local -n stripCmd="${stripCmds[$i]}" local -n stripCmd="${stripCmds[$i]}"
# `dontStrip` disables them all # `dontStrip` disables them all
if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null
then continue; fi then continue; fi
stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} stripDirs "$stripCmd" "$debugDirList" "${stripDebugFlags:--S}"
if [ -n "$stripDebugList" ]; then stripDirs "$stripCmd" "$allDirList" "${stripAllFlags:--s}"
stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}"
fi
stripAllList=${stripAllList:-}
if [ -n "$stripAllList" ]; then
stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}"
fi
done done
} }
@ -50,8 +48,7 @@ stripDirs() {
dirs=${dirsNew} dirs=${dirsNew}
if [ -n "${dirs}" ]; then if [ -n "${dirs}" ]; then
header "stripping (with command $cmd and flags $stripFlags) in$dirs" echo "stripping (with command $cmd and flags $stripFlags) in$dirs"
find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null
stopNest
fi fi
} }