From ec84093ae6511f7c80ca22a8379e1d623f10f598 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 5 Mar 2024 18:09:35 +0000 Subject: [PATCH 1/4] Follow-up for less verbose logging Signed-off-by: Dave Rodgman --- tests/scripts/quiet/cmake | 2 +- tests/scripts/quiet/make | 2 +- tests/scripts/quiet/quiet.sh | 0 3 files changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 tests/scripts/quiet/quiet.sh diff --git a/tests/scripts/quiet/cmake b/tests/scripts/quiet/cmake index 930931d53..c03d8c3e3 100755 --- a/tests/scripts/quiet/cmake +++ b/tests/scripts/quiet/cmake @@ -16,4 +16,4 @@ export NO_SILENCE=" --version " export TOOL="cmake" -exec "$(dirname "$0")/quiet.sh" "$@" +. "$(dirname "$0")/quiet.sh" diff --git a/tests/scripts/quiet/make b/tests/scripts/quiet/make index d022551df..6af3a57ce 100755 --- a/tests/scripts/quiet/make +++ b/tests/scripts/quiet/make @@ -16,4 +16,4 @@ export NO_SILENCE=" --version | test " export TOOL="make" -exec "$(dirname "$0")/quiet.sh" "$@" +. "$(dirname "$0")/quiet.sh" diff --git a/tests/scripts/quiet/quiet.sh b/tests/scripts/quiet/quiet.sh old mode 100755 new mode 100644 From b75b47563a8095861cd691bb26b2f4aa48e75b2a Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 7 Mar 2024 16:50:33 +0000 Subject: [PATCH 2/4] Avoid recursion for relative paths Signed-off-by: Dave Rodgman --- tests/scripts/quiet/quiet.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/scripts/quiet/quiet.sh b/tests/scripts/quiet/quiet.sh index 30ee569a2..b1432301d 100644 --- a/tests/scripts/quiet/quiet.sh +++ b/tests/scripts/quiet/quiet.sh @@ -22,9 +22,16 @@ # be silenced, e.g. " --version | test ". In this example, "make lib test" will # not be silent, but "make lib" will be. -# Locate original tool -TOOL_WITH_PATH=$(dirname "$0")/$TOOL -ORIGINAL_TOOL=$(type -ap "${TOOL}" | grep -v -Fx "$TOOL_WITH_PATH" | head -n1) +# Function to normalise paths +get_real_filename() { + leafname="$(basename "$1")" + ( cd $(dirname "$1"); echo "$(pwd)/$leafname" ) +} + +# Normalise path to wrapper script +WRAPPER_WITH_PATH=$(get_real_filename "$0") +# Identify original tool (compare normalised path to WRAPPER_WITH_PATH to avoid recursively calling the same wrapper script) +ORIGINAL_TOOL="$(for p in $(type -ap "$TOOL"); do get_real_filename "$p" ; done | grep -v -Fx "$WRAPPER_WITH_PATH" | head -n1)" print_quoted_args() { # similar to printf '%q' "$@" From 9554940fb5b36efccd83e0f87eac0389d439f545 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 12 Mar 2024 13:32:36 +0000 Subject: [PATCH 3/4] Remove unnecessary use of export Signed-off-by: Dave Rodgman --- tests/scripts/quiet/cmake | 4 ++-- tests/scripts/quiet/make | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/scripts/quiet/cmake b/tests/scripts/quiet/cmake index c03d8c3e3..a34365bea 100755 --- a/tests/scripts/quiet/cmake +++ b/tests/scripts/quiet/cmake @@ -12,8 +12,8 @@ # export VERBOSE_LOGS=1 # don't silence invocations containing these arguments -export NO_SILENCE=" --version " +NO_SILENCE=" --version " -export TOOL="cmake" +TOOL="cmake" . "$(dirname "$0")/quiet.sh" diff --git a/tests/scripts/quiet/make b/tests/scripts/quiet/make index 6af3a57ce..920e5b875 100755 --- a/tests/scripts/quiet/make +++ b/tests/scripts/quiet/make @@ -12,8 +12,8 @@ # export VERBOSE_LOGS=1 # don't silence invocations containing these arguments -export NO_SILENCE=" --version | test " +NO_SILENCE=" --version | test " -export TOOL="make" +TOOL="make" . "$(dirname "$0")/quiet.sh" From 98ff287ab467f108d589f00c0fbf011088cbe3f4 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 12 Mar 2024 13:33:09 +0000 Subject: [PATCH 4/4] Simplify locating original tool Signed-off-by: Dave Rodgman --- tests/scripts/quiet/quiet.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/scripts/quiet/quiet.sh b/tests/scripts/quiet/quiet.sh index b1432301d..0f26184d0 100644 --- a/tests/scripts/quiet/quiet.sh +++ b/tests/scripts/quiet/quiet.sh @@ -22,16 +22,13 @@ # be silenced, e.g. " --version | test ". In this example, "make lib test" will # not be silent, but "make lib" will be. -# Function to normalise paths -get_real_filename() { - leafname="$(basename "$1")" - ( cd $(dirname "$1"); echo "$(pwd)/$leafname" ) -} - -# Normalise path to wrapper script -WRAPPER_WITH_PATH=$(get_real_filename "$0") -# Identify original tool (compare normalised path to WRAPPER_WITH_PATH to avoid recursively calling the same wrapper script) -ORIGINAL_TOOL="$(for p in $(type -ap "$TOOL"); do get_real_filename "$p" ; done | grep -v -Fx "$WRAPPER_WITH_PATH" | head -n1)" +# Identify path to original tool. There is an edge-case here where the quiet wrapper is on the path via +# a symlink or relative path, but "type -ap" yields the wrapper with it's normalised path. We use +# the -ef operator to compare paths, to avoid picking the wrapper in this case (to avoid infinitely +# recursing). +while IFS= read -r ORIGINAL_TOOL; do + if ! [[ $ORIGINAL_TOOL -ef "$0" ]]; then break; fi +done < <(type -ap -- "$TOOL") print_quoted_args() { # similar to printf '%q' "$@"