From 356ca41f7d8cba2c93ad3afeefa8ecfb00840ba8 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Fri, 21 Apr 2023 22:13:53 -0500 Subject: [PATCH] Make strip script strip all binaries under target If there were both debug & release dirs it would only strip one binary, and if the debug dir had no binary at all it would error, even if the release dir had one. --- Changes.md | 7 +++++++ strip-binary.sh | 40 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Changes.md b/Changes.md index 906791d..b094c9c 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,10 @@ +## 0.0.6 - 2023-04-21 + +- When the `strip` parameter was true, stripping binaries could fail if there + were both `target/*/debug` and `target/*/release` directories present and + the `debug` directory didn't have a binary. Now it will strip all binaries + it finds under `target`. + ## 0.0.5 - 2023-03-19 - Fix use of `dtolnay/rust-toolchain` action to allow passing a `toolchain` diff --git a/strip-binary.sh b/strip-binary.sh index 506d844..08ad2cb 100755 --- a/strip-binary.sh +++ b/strip-binary.sh @@ -2,32 +2,32 @@ set -e set -x TARGET=$1 +stripped="" + +strip_binary () { + if [[ $( uname -s ) =~ "Darwin" ]]; then + EXE=$( find "$1" -maxdepth 1 -type f -perm +111 ) + else + EXE=$( find "$1" -maxdepth 1 -type f -executable ) + fi + + if [ -z "$EXE" ]; then + echo "Could not find a binary to strip in $1" + else + strip "$EXE" + stripped="$EXE" + fi +} -DIR="" for type in debug release; do if [ -d "target/$TARGET/$type" ]; then - DIR="target/$TARGET/$type" - break + strip_binary "target/$TARGET/$type" elif [ -d "target/$type" ]; then - DIR="target/$type" - break + strip_binary "target/$type" fi done -if [ -z "$DIR" ]; then - echo "Could not find directory with binary in it under target/" +if [ -z "$stripped" ]; then + echo "No binaries were stripped" exit 1 fi - -if [[ $( uname -s ) =~ "Darwin" ]]; then - EXE=$( find "$DIR" -maxdepth 1 -type f -perm +111 ) -else - EXE=$( find "$DIR" -maxdepth 1 -type f -executable ) -fi - -if [ -z "$EXE" ]; then - echo "Could not find a binary to strip in $DIR" - exit 2 -fi - -strip "$EXE"