diff --git a/e2e/cases/run-runfiles-discovery/BUILD.bazel b/e2e/cases/run-runfiles-discovery/BUILD.bazel new file mode 100644 index 000000000..ce484eded --- /dev/null +++ b/e2e/cases/run-runfiles-discovery/BUILD.bazel @@ -0,0 +1,23 @@ +load("@aspect_rules_py//py:defs.bzl", "py_binary") +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +py_binary( + name = "hello", + srcs = ["hello.py"], + main = "hello.py", +) + +# Reproduces a py_binary launcher (hermetic_launcher 0.0.9) failing under +# `bazel run` / direct exec when RUNFILES_DIR is not pre-set: the launcher +# cannot self-locate its `.runfiles` dir and aborts with +# "execve failed with errno 2". `bazel test` masks this by setting RUNFILES_DIR. +# +# Tagged `manual` so it stays out of the default `//...` gate until the launcher +# fix lands; run explicitly with `bazel test //cases/run-runfiles-discovery:runs_via_bazel_run`. +sh_test( + name = "runs_via_bazel_run", + srcs = ["run_it.sh"], + args = ["$(rootpath :hello)"], + data = [":hello"], + tags = ["manual"], +) diff --git a/e2e/cases/run-runfiles-discovery/hello.py b/e2e/cases/run-runfiles-discovery/hello.py new file mode 100644 index 000000000..f7cf60e14 --- /dev/null +++ b/e2e/cases/run-runfiles-discovery/hello.py @@ -0,0 +1 @@ +print("Hello, world!") diff --git a/e2e/cases/run-runfiles-discovery/run_it.sh b/e2e/cases/run-runfiles-discovery/run_it.sh new file mode 100755 index 000000000..d3dfdd5fa --- /dev/null +++ b/e2e/cases/run-runfiles-discovery/run_it.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Regression test: a py_binary must be runnable via `bazel run` (and directly), +# where the launcher discovers its own `.runfiles` dir from argv[0] rather than +# relying on a pre-set RUNFILES_DIR. +# +# `bazel test` sets RUNFILES_DIR for the test, which masks the bug. We reproduce +# the `bazel run` / direct-exec path by UNSETTING the runfiles env vars before +# invoking the binary, forcing the launcher to self-locate its runfiles. +# +# BUG (hermetic_launcher 0.0.9): without RUNFILES_DIR/RUNFILES_MANIFEST_FILE set, +# the launcher fails to resolve the embedded venv-python rlocation and aborts +# with "execve failed with errno 2". Works when RUNFILES_DIR is pre-set. +set -euo pipefail + +bin="$1" +unset RUNFILES_DIR RUNFILES_MANIFEST_FILE JAVA_RUNFILES || true +output="$("$bin")" +if [[ "$output" != *"Hello, world!"* ]]; then + echo "FAIL: expected 'Hello, world!', got: $output" >&2 + exit 1 +fi +echo "PASS: py_binary ran via self-located runfiles"