From 73108e9f36374ed1d71364355f23c749329a7024 Mon Sep 17 00:00:00 2001 From: Logan Pulley Date: Fri, 14 Mar 2025 13:13:03 -0500 Subject: [PATCH 1/6] Fix finding runfiles root for symlinks --- python/private/stage1_bootstrap_template.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index 19ff763094..da26defd05 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -76,8 +76,7 @@ else if [[ ! -L "$stub_filename" ]]; then break fi - target=$(realpath $maybe_runfiles_root) - stub_filename="$target" + stub_filename=$(realpath $stub_filename) done echo >&2 "Unable to find runfiles directory for $1" exit 1 From 42ef5322fbcf6dedde6d52c24300bf112ee9f7df Mon Sep 17 00:00:00 2001 From: Logan Pulley Date: Fri, 14 Mar 2025 13:18:35 -0500 Subject: [PATCH 2/6] Add entry to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9029794ffc..88cd3fb1f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ Unreleased changes template. evaluation contexts will invoke Python interpreter with `-B` to avoid creating `.pyc` files. * (deps) doublestar 4.7.1 (required for recent Gazelle versions) +* (runfiles) ({obj}`--bootstrap_impl=script`) Follow symlinks when searching for runfiles. {#v0-0-0-added} ### Added From a047357aea883ead16f9efbb51e9a8d1d3d717ad Mon Sep 17 00:00:00 2001 From: Logan Pulley Date: Fri, 14 Mar 2025 13:28:19 -0500 Subject: [PATCH 3/6] Use readlink, not realpath --- python/private/stage1_bootstrap_template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index da26defd05..510c2d73da 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -76,7 +76,7 @@ else if [[ ! -L "$stub_filename" ]]; then break fi - stub_filename=$(realpath $stub_filename) + stub_filename=$(readlink $stub_filename) done echo >&2 "Unable to find runfiles directory for $1" exit 1 From 2e0358484d7fe77e58ca536814373135b937c7b2 Mon Sep 17 00:00:00 2001 From: Logan Pulley Date: Tue, 18 Mar 2025 15:18:05 +0000 Subject: [PATCH 4/6] Create run_binary_find_runfiles_test --- tests/bootstrap_impls/BUILD.bazel | 14 +++++ .../run_binary_find_runfiles_test.sh | 59 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 tests/bootstrap_impls/run_binary_find_runfiles_test.sh diff --git a/tests/bootstrap_impls/BUILD.bazel b/tests/bootstrap_impls/BUILD.bazel index 8a64bf2b5b..ce91b92b9c 100644 --- a/tests/bootstrap_impls/BUILD.bazel +++ b/tests/bootstrap_impls/BUILD.bazel @@ -70,6 +70,12 @@ sh_py_run_test( venvs_use_declare_symlink = "no", ) +sh_py_run_test( + name = "run_binary_find_runfiles_test", + py_src = "bin.py", + sh_src = "run_binary_find_runfiles_test.sh", +) + sh_py_run_test( name = "run_binary_bootstrap_script_zip_yes_test", bootstrap_impl = "script", @@ -88,6 +94,14 @@ sh_py_run_test( target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, ) +sh_py_run_test( + name = "run_binary_bootstrap_script_find_runfiles_test", + bootstrap_impl = "script", + py_src = "bin.py", + sh_src = "run_binary_find_runfiles_test.sh", + target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, +) + py_reconfig_test( name = "sys_path_order_bootstrap_script_test", srcs = ["sys_path_order_test.py"], diff --git a/tests/bootstrap_impls/run_binary_find_runfiles_test.sh b/tests/bootstrap_impls/run_binary_find_runfiles_test.sh new file mode 100755 index 0000000000..a6c1b565db --- /dev/null +++ b/tests/bootstrap_impls/run_binary_find_runfiles_test.sh @@ -0,0 +1,59 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + 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 +e + +bin=$(rlocation $BIN_RLOCATION) +if [[ -z "$bin" ]]; then + echo "Unable to locate test binary: $BIN_RLOCATION" + exit 1 +fi + +bin_link_layer_1=$TEST_TMPDIR/link1 +ln -s "$bin" "$bin_link_layer_1" +bin_link_layer_2=$TEST_TMPDIR/link2 +ln -s "$bin_link_layer_1" "$bin_link_layer_2" + +result=$(RUNFILES_DIR='' RUNFILES_MANIFEST_FILE='' $bin) +result_link_layer_1=$(RUNFILES_DIR='' RUNFILES_MANIFEST_FILE='' $bin_link_layer_1) +result_link_layer_2=$(RUNFILES_DIR='' RUNFILES_MANIFEST_FILE='' $bin_link_layer_2) + +if [[ "$result" != "$result_link_layer_1" ]]; then + echo "Output from test does not match output when invoked via a link;" + echo "Output from test:" + echo "$result" + echo "Output when invoked via a link:" + echo "$result_link_layer_1" + exit 1 +fi +if [[ "$result" != "$result_link_layer_2" ]]; then + echo "Output from test does not match output when invoked via a link to a link;" + echo "Output from test:" + echo "$result" + echo "Output when invoked via a link to a link:" + echo "$result_link_layer_2" + exit 1 +fi + +exit 0 From 029491420ebf26d9ab167c3297470809f0150f64 Mon Sep 17 00:00:00 2001 From: Logan Pulley Date: Fri, 21 Mar 2025 21:35:35 -0500 Subject: [PATCH 5/6] Set 'target_compatible_with' on test --- tests/bootstrap_impls/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap_impls/BUILD.bazel b/tests/bootstrap_impls/BUILD.bazel index ce91b92b9c..d86d097c8b 100644 --- a/tests/bootstrap_impls/BUILD.bazel +++ b/tests/bootstrap_impls/BUILD.bazel @@ -74,6 +74,7 @@ sh_py_run_test( name = "run_binary_find_runfiles_test", py_src = "bin.py", sh_src = "run_binary_find_runfiles_test.sh", + target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, ) sh_py_run_test( From 1b0c3f606c955f31531cc8f8afac03c13a675fb0 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sat, 22 Mar 2025 11:58:01 +0900 Subject: [PATCH 6/6] move changelog entry to unreleased section --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e4d31755..9cb4d2391d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Unreleased changes template. {#v0-0-0-fixed} ### Fixed -* Nothing fixed. +* (runfiles) ({obj}`--bootstrap_impl=script`) Follow symlinks when searching for runfiles. {#v0-0-0-added} ### Added @@ -98,7 +98,6 @@ Unreleased changes template. evaluation contexts will invoke Python interpreter with `-B` to avoid creating `.pyc` files. * (deps) doublestar 4.7.1 (required for recent Gazelle versions) -* (runfiles) ({obj}`--bootstrap_impl=script`) Follow symlinks when searching for runfiles. {#v1-3-0-added} ### Added