diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 48e4e4fa..b24eea8d 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -123,7 +123,7 @@ release_archive="$${RELEASE}" # TODO: If a release is set, we assume it's set to a branch name. # thus we default the archive value to a commit. This is likely # only appropriate when publishing on the branch in specified -# and a smarter solution should be found to avoid unexpected behavior. +# and a smarter solution should be found to avoid unexpected behavior. if [[ -n "\\$${RELEASE:-}" ]]; then release="\\$${RELEASE}" release_archive="\\$${commit}" diff --git a/foreign_cc/private/runnable_binary_wrapper.sh b/foreign_cc/private/runnable_binary_wrapper.sh index abb128d1..854beb34 100644 --- a/foreign_cc/private/runnable_binary_wrapper.sh +++ b/foreign_cc/private/runnable_binary_wrapper.sh @@ -1,13 +1,5 @@ #!/usr/bin/env bash -# RUN_UNDER_RUNFILES is set in the "bazel test" environment, where all transitive runfiles are placed into one directory -# Otherwise, first cd to the runfiles dir for the wrapped executable before searching for shared libraries for the wrapped executable -if [[ -z $RUN_UNDER_RUNFILES ]]; then - SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - RUNFILES_DIR=${SCRIPT_DIR}/SH_BINARY_FILENAME.runfiles -fi -cd ${RUNFILES_DIR} - # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. (@bazel_tools//tools/bash/runfiles) set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash @@ -19,6 +11,15 @@ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/ { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- +if [[ ! -d "${RUNFILES_DIR}" ]]; then + >&2 echo "RUNFILES_DIR is set to '${RUNFILES_DIR}' which does not exist"; + exit 1; +fi + +RUNFILES_DIR=$( cd "${RUNFILES_DIR}" ; pwd -P ) + +cd "${RUNFILES_DIR}" + EXE=EXECUTABLE EXE_PATH=$(rlocation "${EXE#external/}") @@ -41,19 +42,23 @@ done < <(find . -name "*${SHARED_LIB_SUFFIX}" -print0) # Add paths to shared library directories to SHARED_LIBS_DIRS_ARRAY SHARED_LIBS_DIRS_ARRAY=() -for lib in "${SHARED_LIBS_ARRAY[@]}"; do - SHARED_LIBS_DIRS_ARRAY+=($(dirname $(realpath $lib))) -done +if [ ${#SHARED_LIBS_ARRAY[@]} -ne 0 ]; then + for lib in "${SHARED_LIBS_ARRAY[@]}"; do + SHARED_LIBS_DIRS_ARRAY+=($(dirname $(realpath $lib))) + done +fi -# Remove duplicates from array -IFS=" " read -r -a SHARED_LIBS_DIRS_ARRAY <<< "$(tr ' ' '\n' <<< "${SHARED_LIBS_DIRS_ARRAY[@]}" | sort -u | tr '\n' ' ')" +if [ ${#SHARED_LIBS_DIRS_ARRAY[@]} -ne 0 ]; then + # Remove duplicates from array + IFS=" " read -r -a SHARED_LIBS_DIRS_ARRAY <<< "$(tr ' ' '\n' <<< "${SHARED_LIBS_DIRS_ARRAY[@]}" | sort -u | tr '\n' ' ')" -# Allow unbound variable here, in case LD_LIBRARY_PATH or similar is not already set -set +u -for dir in "${SHARED_LIBS_DIRS_ARRAY[@]}"; do - export ${LIB_PATH_VAR}="$dir":"${!LIB_PATH_VAR}" -done -set -u + # Allow unbound variable here, in case LD_LIBRARY_PATH or similar is not already set + set +u + for dir in "${SHARED_LIBS_DIRS_ARRAY[@]}"; do + export ${LIB_PATH_VAR}="$dir":"${!LIB_PATH_VAR}" + done + set -u +fi cd - &> /dev/null exec ${EXE_PATH} "$@"