Increase resiliency of `runnable_binary` (#1134)
This commit is contained in:
parent
d873cace68
commit
4831827e29
|
@ -123,7 +123,7 @@ release_archive="$${RELEASE}"
|
||||||
# TODO: If a release is set, we assume it's set to a branch name.
|
# 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
|
# thus we default the archive value to a commit. This is likely
|
||||||
# only appropriate when publishing on the branch in specified
|
# 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
|
if [[ -n "\\$${RELEASE:-}" ]]; then
|
||||||
release="\\$${RELEASE}"
|
release="\\$${RELEASE}"
|
||||||
release_archive="\\$${commit}"
|
release_archive="\\$${commit}"
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/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 ---
|
# --- begin runfiles.bash initialization v2 ---
|
||||||
# Copy-pasted from the Bazel Bash runfiles library v2. (@bazel_tools//tools/bash/runfiles)
|
# 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
|
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
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
# --- end runfiles.bash initialization v2 ---
|
# --- 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=EXECUTABLE
|
||||||
EXE_PATH=$(rlocation "${EXE#external/}")
|
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
|
# Add paths to shared library directories to SHARED_LIBS_DIRS_ARRAY
|
||||||
SHARED_LIBS_DIRS_ARRAY=()
|
SHARED_LIBS_DIRS_ARRAY=()
|
||||||
for lib in "${SHARED_LIBS_ARRAY[@]}"; do
|
if [ ${#SHARED_LIBS_ARRAY[@]} -ne 0 ]; then
|
||||||
SHARED_LIBS_DIRS_ARRAY+=($(dirname $(realpath $lib)))
|
for lib in "${SHARED_LIBS_ARRAY[@]}"; do
|
||||||
done
|
SHARED_LIBS_DIRS_ARRAY+=($(dirname $(realpath $lib)))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove duplicates from array
|
if [ ${#SHARED_LIBS_DIRS_ARRAY[@]} -ne 0 ]; then
|
||||||
IFS=" " read -r -a SHARED_LIBS_DIRS_ARRAY <<< "$(tr ' ' '\n' <<< "${SHARED_LIBS_DIRS_ARRAY[@]}" | sort -u | tr '\n' ' ')"
|
# 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
|
# Allow unbound variable here, in case LD_LIBRARY_PATH or similar is not already set
|
||||||
set +u
|
set +u
|
||||||
for dir in "${SHARED_LIBS_DIRS_ARRAY[@]}"; do
|
for dir in "${SHARED_LIBS_DIRS_ARRAY[@]}"; do
|
||||||
export ${LIB_PATH_VAR}="$dir":"${!LIB_PATH_VAR}"
|
export ${LIB_PATH_VAR}="$dir":"${!LIB_PATH_VAR}"
|
||||||
done
|
done
|
||||||
set -u
|
set -u
|
||||||
|
fi
|
||||||
|
|
||||||
cd - &> /dev/null
|
cd - &> /dev/null
|
||||||
exec ${EXE_PATH} "$@"
|
exec ${EXE_PATH} "$@"
|
||||||
|
|
Loading…
Reference in New Issue