diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a901bb236..e468e2bd91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,11 @@ A brief description of the categories of changes: stage2 bootstrap template. * (bzlmod) Properly handle relative path URLs in parse_simpleapi_html.bzl * (gazelle) Correctly resolve deps that have top-level module overlap with a gazelle_python.yaml dep module +* (rules) Make `RUNFILES_MANIFEST_FILE`-based invocations work when used with + {obj}`--bootstrap_impl=script`. This fixes invocations using non-sandboxed + test execution with `--enable_runfiles=false --build_runfile_manifests=true`. + ([#2186](https://github.com/bazelbuild/rules_python/issues/2186)). + ### Added * (rules) Executables provide {obj}`PyExecutableInfo`, which contains diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index 959e7babe6..e7e418cafb 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -44,10 +44,10 @@ else echo "$RUNFILES_DIR" return 0 elif [[ "${RUNFILES_MANIFEST_FILE:-}" = *".runfiles_manifest" ]]; then - echo "${RUNFILES_MANIFEST_FILE%%.runfiles_manifest}" + echo "${RUNFILES_MANIFEST_FILE%%.runfiles_manifest}.runfiles" return 0 elif [[ "${RUNFILES_MANIFEST_FILE:-}" = *".runfiles/MANIFEST" ]]; then - echo "${RUNFILES_MANIFEST_FILE%%.runfiles/MANIFEST}" + echo "${RUNFILES_MANIFEST_FILE%%.runfiles/MANIFEST}.runfiles" return 0 fi @@ -57,7 +57,6 @@ else if [[ "$stub_filename" != /* ]]; then stub_filename="$PWD/$stub_filename" fi - while true; do module_space="${stub_filename}.runfiles" if [[ -d "$module_space" ]]; then diff --git a/tests/bootstrap_impls/run_binary_zip_no_test.sh b/tests/bootstrap_impls/run_binary_zip_no_test.sh index 2ee69f3f66..c45cae54cd 100755 --- a/tests/bootstrap_impls/run_binary_zip_no_test.sh +++ b/tests/bootstrap_impls/run_binary_zip_no_test.sh @@ -29,15 +29,46 @@ if [[ -z "$bin" ]]; then echo "Unable to locate test binary: $BIN_RLOCATION" exit 1 fi -actual=$($bin 2>&1) - -# How we detect if a zip file was executed from depends on which bootstrap -# is used. -# bootstrap_impl=script outputs RULES_PYTHON_ZIP_DIR= -# bootstrap_impl=system_python outputs file:.*Bazel.runfiles -expected_pattern="Hello" -if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then - echo "expected output to match: $expected_pattern" - echo "but got:\n$actual" + +function test_invocation() { + actual=$($bin) + # How we detect if a zip file was executed from depends on which bootstrap + # is used. + # bootstrap_impl=script outputs RULES_PYTHON_ZIP_DIR= + # bootstrap_impl=system_python outputs file:.*Bazel.runfiles + expected_pattern="Hello" + if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then + echo "Test case failed: $1" + echo "expected output to match: $expected_pattern" + echo "but got:\n$actual" + exit 1 + fi +} + +# Test invocation with RUNFILES_DIR set +unset RUNFILES_MANIFEST_FILE +if [[ ! -e "$RUNFILES_DIR" ]]; then + echo "Runfiles doesn't exist: $RUNFILES_DIR" exit 1 fi +test_invocation "using RUNFILES_DIR" + + +orig_runfiles_dir="$RUNFILES_DIR" +unset RUNFILES_DIR + +# Test invocation using manifest within runfiles directory (output manifest) +# NOTE: this file may not actually exist in our test, but that's OK; the +# bootstrap just uses the path to find the runfiles directory. +export RUNFILES_MANIFEST_FILE="$orig_runfiles_dir/MANIFEST" +test_invocation "using RUNFILES_MANIFEST_FILE with output manifest" + +# Test invocation using manifest outside runfiles (input manifest) +# NOTE: this file may not actually exist in our test, but that's OK; the +# bootstrap just uses the path to find the runfiles directory. +export RUNFILES_MANIFEST_FILE="${orig_runfiles_dir%%.runfiles}.runfiles_manifest" +test_invocation "using RUNFILES_MANIFEST_FILE with input manifest" + +# Test invocation without any runfiles env vars set +unset RUNFILES_MANIFEST_FILE +test_invocation "using no runfiles env vars"