Skip to content

Commit 1b2714e

Browse files
rickeylevcomius
andauthored
tests: use $(rootpaths) to get executable files paths for Bazel 8 compatibility (bazel-contrib#2395)
In Bazel 8, the singular `$(rootpath)` expansions require that the target expands to a single file. The py rules have an unfortunate legacy behavior where their default outputs are the executable and the main py file, thus causing an error. To fix, use the plural `$(rootpaths)`, then post-process the space-separated string to get just the executable portion of it. Along the way... * Add tests/integration/py_cc_toolchain_registered/bazel-* symlink to Bazel ignore. This avoids an infinite symlink expansions error and performance issues when those symlinks exist. Work towards bazel-contrib#2378 --------- Co-authored-by: Ivo List <[email protected]>
1 parent 91e5751 commit 1b2714e

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ examples/py_proto_library/bazel-py_proto_library
2626
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
2727
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
2828
tests/integration/local_toolchains/bazel-local_toolchains
29+
tests/integration/py_cc_toolchain_registered/bazel-py_cc_toolchain_registered

examples/bzlmod/MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bzlmod/tests/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ sh_test(
163163
data = [":version_default"],
164164
env = {
165165
"VERSION_CHECK": "3.9", # The default defined in the WORKSPACE.
166-
"VERSION_PY_BINARY": "$(rootpath :version_default)",
166+
"VERSION_PY_BINARY": "$(rootpaths :version_default)",
167167
},
168168
)
169169

@@ -173,7 +173,7 @@ sh_test(
173173
data = [":version_3_9"],
174174
env = {
175175
"VERSION_CHECK": "3.9",
176-
"VERSION_PY_BINARY": "$(rootpath :version_3_9)",
176+
"VERSION_PY_BINARY": "$(rootpaths :version_3_9)",
177177
},
178178
)
179179

@@ -183,6 +183,6 @@ sh_test(
183183
data = [":version_3_10"],
184184
env = {
185185
"VERSION_CHECK": "3.10",
186-
"VERSION_PY_BINARY": "$(rootpath :version_3_10)",
186+
"VERSION_PY_BINARY": "$(rootpaths :version_3_10)",
187187
},
188188
)

examples/bzlmod/tests/version_test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
set -o errexit -o nounset -o pipefail
1818

19-
version_py_binary=$("${VERSION_PY_BINARY}")
19+
# VERSION_PY_BINARY is a space separate list of the executable and its main
20+
# py file. We just want the executable.
21+
bin=($VERSION_PY_BINARY)
22+
bin="${bin[@]//*.py}"
23+
version_py_binary=$($bin)
2024

2125
if [[ "${version_py_binary}" != "${VERSION_CHECK}" ]]; then
2226
echo >&2 "expected version '${VERSION_CHECK}' is different than returned '${version_py_binary}'"

0 commit comments

Comments
 (0)