runfiles done right
This commit is contained in:
parent
daba2e2b12
commit
8ca2b4a00b
3 changed files with 43 additions and 33 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
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 ---
|
# --- begin runfiles.bash initialization v3 ---
|
||||||
# Copy-pasted from the Bazel Bash runfiles library v3.
|
# Copy-pasted from the Bazel Bash runfiles library v3.
|
||||||
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
|
@ -12,8 +20,6 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
{ 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 v3 ---
|
# --- end runfiles.bash initialization v3 ---
|
||||||
|
|
||||||
CONFIGURE_BINARY="%{CONFIGURE_PATH}"
|
|
||||||
|
|
||||||
# Set up JAVA_RUNFILES if not already set
|
# Set up JAVA_RUNFILES if not already set
|
||||||
if [[ -z "${JAVA_RUNFILES:-}" ]]; then
|
if [[ -z "${JAVA_RUNFILES:-}" ]]; then
|
||||||
if [[ -d "$0.runfiles" ]]; then
|
if [[ -d "$0.runfiles" ]]; then
|
||||||
|
|
@ -23,16 +29,7 @@ if [[ -z "${JAVA_RUNFILES:-}" ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CONFIGURE_BINARY="$(rlocation "_main/$(basename "%{CONFIGURE_PATH}")")"
|
||||||
if [[ ! -x "$CONFIGURE_BINARY" ]]; then
|
|
||||||
CONFIGURE_BASENAME=$(basename "$CONFIGURE_BINARY")
|
|
||||||
if [[ ! -x "$CONFIGURE_BASENAME" ]]; then
|
|
||||||
echo "Error: CONFIGURE binary not found or not executable at $CONFIGURE_BINARY and $CONFIGURE_BASENAME" >&2
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
CONFIGURE_BINARY=./$CONFIGURE_BASENAME
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run the configuration
|
# Run the configuration
|
||||||
exec "${CONFIGURE_BINARY}" "$@"
|
exec "${CONFIGURE_BINARY}" "$@"
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,39 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
EXECUTE_BINARY="%{EXECUTE_PATH}"
|
# TODO should this be extracted to shared init script
|
||||||
JQ="%{JQ_PATH}"
|
# 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
|
||||||
|
|
||||||
if [[ ! -x "$EXECUTE_BINARY" ]]; then
|
# --- begin runfiles.bash initialization v3 ---
|
||||||
EXECUTE_BASENAME=$(basename "$EXECUTE_BINARY")
|
# Copy-pasted from the Bazel Bash runfiles library v3.
|
||||||
if [[ ! -x "$EXECUTE_BASENAME" ]]; then
|
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
echo "Error: Execute binary not found or not executable at $EXECUTE_BINARY and $EXECUTE_BASENAME" >&2
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
exit 1
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
else
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
EXECUTE_BINARY=./$EXECUTE_BASENAME
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure the binaries exist and are executable
|
EXECUTE_BINARY="$(rlocation "_main/$(basename "%{EXECUTE_PATH}")")"
|
||||||
if [[ ! -x "$JQ" ]]; then
|
JQ="$(rlocation "databuild+/runtime/$(basename "%{JQ_PATH}")")"
|
||||||
JQ_PATH="../databuild+/runtime/$(basename $JQ)"
|
|
||||||
if [[ ! -x "$JQ_PATH" ]]; then
|
|
||||||
echo "Error: JQ binary not found or not executable at $JQ or $JQ_PATH" >&2
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
JQ=$JQ_PATH
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# First argument should be the path to a config file
|
# First argument should be the path to a config file
|
||||||
CONFIG_FILE="$1"
|
CONFIG_FILE=${1:-}
|
||||||
|
|
||||||
# Create a temporary file for stdin if needed
|
# Create a temporary file for stdin if needed
|
||||||
if [[ -z "$CONFIG_FILE" ]] || [[ "$CONFIG_FILE" == "-" ]]; then
|
if [[ -z "$CONFIG_FILE" ]] || [[ "$CONFIG_FILE" == "-" ]]; then
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,9 @@ def _databuild_job_exec_impl(ctx):
|
||||||
|
|
||||||
runfiles = ctx.runfiles(
|
runfiles = ctx.runfiles(
|
||||||
files = [jq_file, execute_file],
|
files = [jq_file, execute_file],
|
||||||
).merge(ctx.attr.execute.default_runfiles).merge(ctx.attr._jq.default_runfiles)
|
).merge(ctx.attr.execute.default_runfiles).merge(ctx.attr._jq.default_runfiles).merge(
|
||||||
|
ctx.attr._bash_runfiles.default_runfiles,
|
||||||
|
)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
DefaultInfo(
|
DefaultInfo(
|
||||||
|
|
@ -156,6 +158,10 @@ _databuild_job_exec_rule = rule(
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "exec",
|
cfg = "exec",
|
||||||
),
|
),
|
||||||
|
"_bash_runfiles": attr.label(
|
||||||
|
default = Label("@bazel_tools//tools/bash/runfiles"),
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
executable = True,
|
executable = True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue