-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Just strip everything by default, fully tested version :-) #15339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,33 +4,78 @@ fixupOutputHooks+=(_doStrip) | |
|
|
||
| _doStrip() { | ||
| if [ -z "$dontStrip" ]; then | ||
| stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} | ||
| if [ -n "$stripDebugList" ]; then | ||
| stripDirs "$stripDebugList" "${stripDebugFlags:--S}" | ||
| fi | ||
|
|
||
| stripAllList=${stripAllList:-} | ||
| if [ -n "$stripAllList" ]; then | ||
| stripDirs "$stripAllList" "${stripAllFlags:--s}" | ||
| stripDirs "${stripDebugList:-*}" "${stripDebugFlags:--S}" | ||
|
|
||
| if [ -n "${stripAllList:-}" ]; then | ||
| stripDirs "${stripAllList:-}" "${stripAllFlags:--s}" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| stripDirs() { | ||
| local dirs="$1" | ||
| local stripFlags="$2" | ||
| local dirsNew= | ||
|
|
||
| for d in ${dirs}; do | ||
| if [ -d "$prefix/$d" ]; then | ||
| dirsNew="${dirsNew} $prefix/$d " | ||
| # Ensure $prefix is a directory | ||
| if [ -f "$prefix" ]; then | ||
| header "Stripping (with flags $stripFlags) the file ${prefix}." | ||
| echo -ne $prefix'\0' | stripAll "$stripFlags" | ||
| stopNest | ||
| fi | ||
| [ -d "$prefix" ] || return 0 | ||
|
|
||
| # Ensure expansion occurs within $prefix/. | ||
| pushd "$prefix" >/dev/null | ||
| shopt -s dotglob | ||
| local stripDirs=( $1 ) | ||
| local ignoreDirs=( $dontStripList ) | ||
| shopt -u dotglob | ||
| popd >/dev/null | ||
| local debugIncluded= debugExcluded= p= | ||
|
|
||
| # `find` fails on missing paths. Remove them. | ||
| local roots=() | ||
| for p in "${stripDirs[@]}"; do | ||
| if [ -e "$prefix/$p" ]; then | ||
| roots+=( "$prefix/$p" ) | ||
| debugIncluded="$debugIncluded${debugIncluded:+,}$p" | ||
| fi | ||
| done | ||
| dirs=${dirsNew} | ||
| [ "${#roots[@]}" -eq 0 ] && return 0 | ||
|
||
|
|
||
| if [ -n "${dirs}" ]; then | ||
| header "stripping (with flags $stripFlags) in$dirs" | ||
| find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true | ||
| stopNest | ||
| fi | ||
| # Add ignored paths to find command. | ||
| local findArgs=( "${roots[@]}" ) | ||
| for p in "${ignoreDirs[@]}"; do | ||
| if [ -e "$prefix/$p" ]; then | ||
| findArgs+=( "-path" "$prefix/$p" "-prune" "-o" ) | ||
| debugExcluded="$debugExcluded $p" | ||
| fi | ||
| done | ||
|
|
||
| header "Stripping (with flags $stripFlags) in $prefix${debugIncluded:+"/{$debugIncluded}"}${debugExcluded:+", skipping$debugExcluded"}." | ||
| find "${findArgs[@]}" -type f -print0 | stripAll "$stripFlags" | ||
| stopNest | ||
| } | ||
|
|
||
| stripAll() { | ||
| local stripFlags="$1" | ||
|
|
||
| local _ls f stripOutput | ||
| while IFS= read -r -d $'\0' f; do | ||
| # Skip very small files, they make strip choke. | ||
| _ls=( $(ls -Ln "$f") ) | ||
| [ "${_ls[4]}" -lt 4 ] && continue; | ||
|
|
||
| if stripOutput=$(strip $commonStripFlags $stripFlags "$f" 2>&1); then | ||
| echo "Stripped $f" | ||
| else | ||
| # Ignore failures on files that cannot be stripped. | ||
| [ "$stripOutput" = "strip:$f: File format not recognized" ] && continue | ||
| [ "$stripOutput" = "strip:$f: File truncated" ] && continue | ||
|
|
||
| [ -n "$stripOutput" ] && echo "$stripOutput" | ||
| echo "Strip failed on file $f" | ||
| false # fail ! | ||
| fi | ||
| done | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: in
_doStripI would change all:-to-, so that people can explicitly define those variables as empty without being overridden back to the default values. (Yes, one could define them as" ", but it seems nicer to allow empty string as well.)Note that otherwise e.g. the first
ifwill always fire, as*is used whenever the expansion could be empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does an empty string mean ? Strip everything or nothing ?
For now, passing an empty string to stripDirs strips nothing because it is interpreted as a gob pattern. This is why "" is replaced by "*".
If you want to disable stripping, why not use dontStrip ?
My fear is that if the variable is defined for some reason, or remains (say, from another output), the result may not be expected by the user.
I may however remove the useless
if. Would that suit you ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the if in bda09f6.