56 lines
2.1 KiB
Smarty
Executable file
56 lines
2.1 KiB
Smarty
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
# TODO should this be extracted to shared init script
|
|
# Get the directory where the script is located
|
|
if [[ -z "${RUNFILES_DIR:-}" ]]; then
|
|
SCRIPT_DIR="$(readlink -f "${BASH_SOURCE[0]}")"
|
|
# Set RUNFILES_DIR relative to the script location
|
|
export RUNFILES_DIR="${SCRIPT_DIR}.runfiles"
|
|
fi
|
|
|
|
# --- begin runfiles.bash initialization v3 ---
|
|
# Copy-pasted from the Bazel Bash runfiles library v3.
|
|
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
|
source "$0.runfiles/$f" 2>/dev/null || \
|
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
|
# --- end runfiles.bash initialization v3 ---
|
|
|
|
# Set up JAVA_RUNFILES if not already set
|
|
if [[ -z "${JAVA_RUNFILES:-}" ]]; then
|
|
if [[ -d "$0.runfiles" ]]; then
|
|
export JAVA_RUNFILES="$0.runfiles"
|
|
elif [[ -f "${RUNFILES_MANIFEST_FILE:-}" ]]; then
|
|
export JAVA_RUNFILES="$(dirname "${RUNFILES_MANIFEST_FILE}")"
|
|
fi
|
|
fi
|
|
|
|
EXECUTE_BINARY="$(rlocation "_main/$(basename "%{EXECUTE_PATH}")")"
|
|
JQ="$(rlocation "databuild+/runtime/$(basename "%{JQ_PATH}")")"
|
|
|
|
# First argument should be the path to a config file
|
|
CONFIG_FILE=${1:-}
|
|
|
|
# Create a temporary file for stdin if needed
|
|
if [[ -z "$CONFIG_FILE" ]] || [[ "$CONFIG_FILE" == "-" ]]; then
|
|
TMP_CONFIG=$(mktemp)
|
|
cat > "$TMP_CONFIG"
|
|
CONFIG_FILE="$TMP_CONFIG"
|
|
trap 'rm -f "$TMP_CONFIG"' EXIT
|
|
fi
|
|
|
|
# Extract and set environment variables from the config
|
|
eval "$("$JQ" -r '.env | to_entries | .[] | "export " + .key + "=\"" + .value + "\""' "$CONFIG_FILE")"
|
|
|
|
# Extract arguments from the config
|
|
ARGS=()
|
|
while IFS= read -r arg; do
|
|
ARGS+=("$arg")
|
|
done < <("$JQ" -r '.args[]' "$CONFIG_FILE")
|
|
|
|
# Run the execution with both environment variables (already set) and arguments
|
|
exec "$EXECUTE_BINARY" "${ARGS[@]}"
|