Avoid recursion for relative paths

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2024-03-07 16:50:33 +00:00
parent c02c5b1520
commit 4c4f1f1428

View File

@ -22,9 +22,16 @@
# be silenced, e.g. " --version | test ". In this example, "make lib test" will # be silenced, e.g. " --version | test ". In this example, "make lib test" will
# not be silent, but "make lib" will be. # not be silent, but "make lib" will be.
# Locate original tool # Function to normalise paths
TOOL_WITH_PATH=$(dirname "$0")/$TOOL get_real_filename() {
ORIGINAL_TOOL=$(type -ap "${TOOL}" | grep -v -Fx "$TOOL_WITH_PATH" | head -n1) 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() { print_quoted_args() {
# similar to printf '%q' "$@" # similar to printf '%q' "$@"