databuild/databuild/runtime/simple_executable_wrapper.sh.tpl
2025-07-31 19:59:13 -07:00

40 lines
1.1 KiB
Smarty
Executable file

#!/bin/bash
set -e
%{RUNFILES_PREFIX}
%{PREFIX}
# Check if rlocation function is available
if ! type rlocation >/dev/null 2>&1; then
echo "Error: rlocation function not available. Runfiles may not be properly initialized." >&2
exit 1
fi
# Resolve the executable using rlocation
EXECUTABLE_BINARY="$(rlocation "_main/%{EXECUTABLE_SHORT_PATH}")"
# Check if rlocation returned something
if [[ -z "${EXECUTABLE_BINARY}" ]]; then
echo "Error: rlocation returned empty result for '_main/%{EXECUTABLE_SHORT_PATH}'" >&2
exit 1
fi
# Check if the resolved binary exists
if [[ ! -f "${EXECUTABLE_BINARY}" ]]; then
echo "Error: Resolved executable '${EXECUTABLE_BINARY}' does not exist" >&2
exit 1
fi
# Check if the resolved binary is executable
if [[ ! -x "${EXECUTABLE_BINARY}" ]]; then
echo "Error: Resolved executable '${EXECUTABLE_BINARY}' is not executable" >&2
exit 1
fi
# Run the configuration
if [[ -n "${EXECUTABLE_SUBCOMMAND:-}" ]]; then
exec "${EXECUTABLE_BINARY}" "${EXECUTABLE_SUBCOMMAND}" "$@"
else
exec "${EXECUTABLE_BINARY}" "$@"
fi