Skip to content

Commit

Permalink
use bash source rather than dirname $0 (envoyproxy#35804)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wbpcode authored Aug 22, 2024
1 parent 04bb74c commit f615e14
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bazel/sh_test_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 4 additions & 2 deletions ci/build_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
3 changes: 2 additions & 1 deletion ci/envoy_build_sha.sh
Original file line number Diff line number Diff line change
@@ -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)"

Expand Down
4 changes: 3 additions & 1 deletion ci/run_envoy_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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* ]]
Expand Down
2 changes: 1 addition & 1 deletion mobile/bazelw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mobile/remote
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion mobile/tools/check_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/common/tls/ocsp/test_data/certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/common/tls/test_data/certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions tools/bazel-test-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -42,7 +42,8 @@ cat > "${DOCKER_ENV}" <<EOF
export NO_PROXY="${NO_PROXY}"
EOF

. ./ci/envoy_build_sha.sh
# shellcheck source=ci/envoy_build_sha.sh
. "${SCRIPT_DIR}"/../ci/envoy_build_sha.sh
IMAGE=envoyproxy/envoy-build:${ENVOY_BUILD_SHA}

# Note docker_wrapper.sh is tightly coupled to the order of arguments here due to where the test
Expand Down
5 changes: 3 additions & 2 deletions tools/debugging/run-valgrind.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/sh
#!/usr/bin/env bash

#
# Helper script to run tests under valgrind. Usage:
# bazel test --run_under=`pwd`/tools/debugging/run-valgrind.sh ...
#

dir=$(dirname "$0")
dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"

# In order to add suppressions, it's helpful to run the tool in a mode
# where it uses the suppressions file we have so far, but also
Expand Down
2 changes: 1 addition & 1 deletion tools/git/modified_since_last_github_commit.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

BASE="$(dirname "$0")"
BASE="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
declare -r BASE
declare -r TARGET_PATH=$1
declare -r EXTENSION=$2
Expand Down

0 comments on commit f615e14

Please sign in to comment.