Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions e2e/cases/run-runfiles-discovery/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
1 change: 1 addition & 0 deletions e2e/cases/run-runfiles-discovery/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world!")
22 changes: 22 additions & 0 deletions e2e/cases/run-runfiles-discovery/run_it.sh
Original file line number Diff line number Diff line change
@@ -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"