diff --git a/bin/et b/bin/et index f5389c1af7445..38c60777ceb2f 100755 --- a/bin/et +++ b/bin/et @@ -9,25 +9,19 @@ set -e # Needed because if it is set, cd may print the path it changed to. unset CDPATH -# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one -# link at a time, and then cds into the link destination and find out where it -# ends up. -# -# The function is enclosed in a subshell to avoid changing the working directory -# of the caller. -function follow_links() ( - cd -P "$(dirname -- "$1")" - file="$PWD/$(basename -- "$1")" - while [[ -h "$file" ]]; do - cd -P "$(dirname -- "$file")" - file="$(readlink -- "$file")" - cd -P "$(dirname -- "$file")" - file="$PWD/$(basename -- "$file")" - done - echo "$file" -) +# Returns the canonical path for its argument, with any symlinks resolved. +function canonical_path() { + if [[ -x "$(which realpath)" ]]; then + realpath -q -- "$1" + elif [[ -x "$(which readlink)" ]]; then + readlink -f -- "$1" + else + echo "The host platform is not supported by this tool" + exit 1 + fi +} -SCRIPT_DIR="$(dirname -- "$(follow_links "${BASH_SOURCE[0]}")")" +SCRIPT_DIR="$(dirname -- "$(canonical_path "${BASH_SOURCE[0]}")")" ENGINE_DIR="$(cd "$SCRIPT_DIR/.."; pwd -P)" case "$(uname -s)" in