From f615e1479a261aab0ad4342c0a48128498f72b90 Mon Sep 17 00:00:00 2001 From: code Date: Thu, 22 Aug 2024 22:52:29 +0800 Subject: [PATCH] use bash source rather than dirname $0 (#35804) Commit Message: use bash source rather than dirname $0 Additional Description: Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. --------- Signed-off-by: wangbaiping --- bazel/sh_test_wrapper.sh | 2 +- ci/build_setup.sh | 6 ++++-- ci/do_ci.sh | 4 +++- ci/envoy_build_sha.sh | 3 ++- ci/run_envoy_docker.sh | 4 +++- mobile/bazelw | 2 +- mobile/remote | 2 +- mobile/tools/check_format.sh | 2 +- test/common/tls/ocsp/test_data/certs.sh | 2 +- test/common/tls/test_data/certs.sh | 2 +- .../network/thrift_proxy/driver/generate_bindings.sh | 2 +- tools/bazel-test-docker.sh | 5 +++-- tools/debugging/run-valgrind.sh | 5 +++-- tools/git/modified_since_last_github_commit.sh | 2 +- 14 files changed, 26 insertions(+), 17 deletions(-) diff --git a/bazel/sh_test_wrapper.sh b/bazel/sh_test_wrapper.sh index fd10ffee5671..85edf3a9d4d2 100755 --- a/bazel/sh_test_wrapper.sh +++ b/bazel/sh_test_wrapper.sh @@ -4,7 +4,7 @@ # TODO(lizan): remove when we have a solution for # https://github.com/bazelbuild/bazel/issues/3510 -cd "$(dirname "$0")" || exit 1 +cd "$(realpath "$(dirname "${BASH_SOURCE[0]}")")" || exit 1 if [ $# -gt 0 ]; then "./${1}" "${@:2}" diff --git a/ci/build_setup.sh b/ci/build_setup.sh index 36f325417582..abdbea03859b 100755 --- a/ci/build_setup.sh +++ b/ci/build_setup.sh @@ -11,6 +11,8 @@ if [[ -n "$NO_BUILD_SETUP" ]]; then return fi +CURRENT_SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + export PPROF_PATH=/thirdparty_build/bin/pprof if [[ -z "${NUM_CPUS}" ]]; then @@ -118,7 +120,7 @@ export BAZEL_BUILD_OPTION_LIST export BAZEL_GLOBAL_OPTION_LIST if [[ -e "${LLVM_ROOT}" ]]; then - "$(dirname "$0")/../bazel/setup_clang.sh" "${LLVM_ROOT}" + "${CURRENT_SCRIPT_DIR}/../bazel/setup_clang.sh" "${LLVM_ROOT}" else echo "LLVM_ROOT not found, not setting up llvm." fi @@ -155,7 +157,7 @@ mkdir -p "${ENVOY_BUILD_PROFILE}" if [[ "${ENVOY_BUILD_FILTER_EXAMPLE}" == "true" ]]; then # shellcheck source=ci/filter_example_setup.sh - . "$(dirname "$0")"/filter_example_setup.sh + . "${CURRENT_SCRIPT_DIR}"/filter_example_setup.sh else echo "Skip setting up Envoy Filter Example." fi diff --git a/ci/do_ci.sh b/ci/do_ci.sh index ed856b0af883..1d51f478f15c 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -8,8 +8,10 @@ set -e export SRCDIR="${SRCDIR:-$PWD}" export ENVOY_SRCDIR="${ENVOY_SRCDIR:-$PWD}" +CURRENT_SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + # shellcheck source=ci/build_setup.sh -. "$(dirname "$0")"/build_setup.sh +. "${CURRENT_SCRIPT_DIR}"/build_setup.sh echo "building using ${NUM_CPUS} CPUs" echo "building for ${ENVOY_BUILD_ARCH}" diff --git a/ci/envoy_build_sha.sh b/ci/envoy_build_sha.sh index 916da9b84b76..0a6243ed82d9 100644 --- a/ci/envoy_build_sha.sh +++ b/ci/envoy_build_sha.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash +CURRENT_SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -ENVOY_BUILD_CONTAINER="$(grep envoyproxy/envoy-build-ubuntu "$(dirname "$0")"/../.bazelrc | sed -e 's#.*envoyproxy/envoy-build-ubuntu:\(.*\)#\1#' | uniq)" +ENVOY_BUILD_CONTAINER="$(grep envoyproxy/envoy-build-ubuntu "${CURRENT_SCRIPT_DIR}"/../.bazelrc | sed -e 's#.*envoyproxy/envoy-build-ubuntu:\(.*\)#\1#' | uniq)" ENVOY_BUILD_SHA="$(echo "${ENVOY_BUILD_CONTAINER}" | cut -d@ -f1)" ENVOY_BUILD_CONTAINER_SHA="$(echo "${ENVOY_BUILD_CONTAINER}" | cut -d@ -f2)" diff --git a/ci/run_envoy_docker.sh b/ci/run_envoy_docker.sh index 809d141fb9da..d73964e8cc1c 100755 --- a/ci/run_envoy_docker.sh +++ b/ci/run_envoy_docker.sh @@ -2,8 +2,10 @@ set -e +CURRENT_SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + # shellcheck source=ci/envoy_build_sha.sh -. "$(dirname "$0")"/envoy_build_sha.sh +. "${CURRENT_SCRIPT_DIR}"/envoy_build_sha.sh function is_windows() { [[ "$(uname -s)" == *NT* ]] diff --git a/mobile/bazelw b/mobile/bazelw index 7d16ff11b932..f461863b9e76 100755 --- a/mobile/bazelw +++ b/mobile/bazelw @@ -42,7 +42,7 @@ case "$bazel_platform" in esac readonly bazel_version_url="https://github.com/bazelbuild/bazelisk/releases/download/v$bazelisk_version/bazelisk-$bazel_platform" -script_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +script_root="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" readonly bazelisk="$script_root/tmp/bazel/versions/bazelisk-$bazelisk_version-$bazel_platform" if [[ ! -x "$bazelisk" ]]; then diff --git a/mobile/remote b/mobile/remote index d6828af230ac..1b5ea4099101 100755 --- a/mobile/remote +++ b/mobile/remote @@ -2,7 +2,7 @@ set -euo pipefail -script_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +script_root="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" certificate="$script_root/tmp/certs/engflow.crt" key="$script_root/tmp/certs/engflow.key" diff --git a/mobile/tools/check_format.sh b/mobile/tools/check_format.sh index 257a8e97506b..d4d00e06bf35 100755 --- a/mobile/tools/check_format.sh +++ b/mobile/tools/check_format.sh @@ -45,7 +45,7 @@ FORMAT_ARGS+=( export ENVOY_BAZEL_PREFIX="@envoy" && ./bazelw run @envoy//tools/code_format:check_format -- "${ENVOY_FORMAT_ACTION}" --path "$PWD" "${FORMAT_ARGS[@]}" -KTFMT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/ktfmt.sh +KTFMT="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"/ktfmt.sh KOTLIN_DIRS=( "library/kotlin" "test/kotlin" diff --git a/test/common/tls/ocsp/test_data/certs.sh b/test/common/tls/ocsp/test_data/certs.sh index bc531ad2e94d..633a5304c3f0 100755 --- a/test/common/tls/ocsp/test_data/certs.sh +++ b/test/common/tls/ocsp/test_data/certs.sh @@ -5,7 +5,7 @@ set -e readonly DEFAULT_VALIDITY_DAYS=${DEFAULT_VALIDITY_DAYS:-730} -HERE=$(cd "$(dirname "$0")" && pwd) +HERE="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" readonly HERE cd "$HERE" || exit 1 diff --git a/test/common/tls/test_data/certs.sh b/test/common/tls/test_data/certs.sh index d1ba810665bd..2a89c216de46 100755 --- a/test/common/tls/test_data/certs.sh +++ b/test/common/tls/test_data/certs.sh @@ -3,7 +3,7 @@ set -e readonly DEFAULT_VALIDITY_DAYS=${DEFAULT_VALIDITY_DAYS:-730} -HERE=$(cd "$(dirname "$0")" && pwd) +HERE="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" readonly HERE cd "$HERE" || exit 1 diff --git a/test/extensions/filters/network/thrift_proxy/driver/generate_bindings.sh b/test/extensions/filters/network/thrift_proxy/driver/generate_bindings.sh index 0ba2827b95f5..d70964c64ae4 100755 --- a/test/extensions/filters/network/thrift_proxy/driver/generate_bindings.sh +++ b/test/extensions/filters/network/thrift_proxy/driver/generate_bindings.sh @@ -3,7 +3,7 @@ # Generates the thrift bindings for example.thrift. Requires that # apache-thrift's thrift generator is installed and on the path. -DIR=$(cd "$(dirname "$0")" && pwd) +DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" cd "${DIR}" || exit 1 thrift --gen py --out ./generated example.thrift diff --git a/tools/bazel-test-docker.sh b/tools/bazel-test-docker.sh index e6575a5fe81c..ff76215a045a 100755 --- a/tools/bazel-test-docker.sh +++ b/tools/bazel-test-docker.sh @@ -14,7 +14,7 @@ if [[ -z "$1" ]]; then exit 1 fi -SCRIPT_DIR="$(realpath "$(dirname "$0")")" +SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" [[ -z "${BAZEL}" ]] && BAZEL=bazel [[ -z "${DOCKER}" ]] && DOCKER=docker @@ -42,7 +42,8 @@ cat > "${DOCKER_ENV}" <