separateDebugInfo: fix cleanup, refactor a little
- cleanup with --ignore-fail-on-non-empty - extract destDir and destFile variables - unnest all the subshells
This commit is contained in:
@@ -33,21 +33,25 @@ _separateDebugInfo() {
|
||||
|
||||
# Extract the debug info.
|
||||
echo "separating debug info from $i (build ID $id)"
|
||||
mkdir -p "$dst/${id:0:2}"
|
||||
|
||||
destDir=$dst/${id:0:2}
|
||||
destFile=$dst/${id:0:2}/${id:2}.debug
|
||||
|
||||
mkdir -p "$destDir"
|
||||
|
||||
if [ -f "$destFile" ]; then
|
||||
echo "separate-debug-info: warning: multiple files with build id $id found, overwriting"
|
||||
fi
|
||||
|
||||
# This may fail, e.g. if the binary is for a different
|
||||
# architecture than we're building for. (This happens with
|
||||
# firmware blobs in QEMU.)
|
||||
(
|
||||
if [ -f "$dst/${id:0:2}/${id:2}.debug" ]
|
||||
then
|
||||
echo "separate-debug-info: warning: multiple files with build id $id found, overwriting"
|
||||
fi
|
||||
(
|
||||
$OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug" &&
|
||||
# Also a create a symlink <original-name>.debug.
|
||||
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
|
||||
)
|
||||
) || rmdir -p "$dst/${id:0:2}"
|
||||
if $OBJCOPY --only-keep-debug "$i" "$destFile"; then
|
||||
# If we succeeded, also a create a symlink <original-name>.debug.
|
||||
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
|
||||
else
|
||||
# If we failed, try to clean up unnecessary directories
|
||||
rmdir -p "$dst/${id:0:2}" --ignore-fail-on-non-empty
|
||||
fi
|
||||
done < <(find "$prefix" -type f -print0 | sort -z)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user