From 61001472b462eba319151fbbc5e4fb7fc8ca4327 Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 11 Feb 2025 10:45:59 +0300 Subject: [PATCH] separateDebugInfo: fix cleanup, refactor a little - cleanup with --ignore-fail-on-non-empty - extract destDir and destFile variables - unnest all the subshells --- .../setup-hooks/separate-debug-info.sh | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/setup-hooks/separate-debug-info.sh b/pkgs/build-support/setup-hooks/separate-debug-info.sh index 9cec77b9b0cd..4208aa481d0d 100644 --- a/pkgs/build-support/setup-hooks/separate-debug-info.sh +++ b/pkgs/build-support/setup-hooks/separate-debug-info.sh @@ -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 .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 .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) }