Skip to content

Commit

Permalink
tests: use $(rootpaths) to get executable files paths for Bazel 8 com…
Browse files Browse the repository at this point in the history
…patibility (#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 #2378

---------

Co-authored-by: Ivo List <[email protected]>
  • Loading branch information
rickeylev and comius authored Nov 12, 2024
1 parent 91e5751 commit 1b2714e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ examples/py_proto_library/bazel-py_proto_library
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
tests/integration/local_toolchains/bazel-local_toolchains
tests/integration/py_cc_toolchain_registered/bazel-py_cc_toolchain_registered
6 changes: 3 additions & 3 deletions examples/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/bzlmod/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ sh_test(
data = [":version_default"],
env = {
"VERSION_CHECK": "3.9", # The default defined in the WORKSPACE.
"VERSION_PY_BINARY": "$(rootpath :version_default)",
"VERSION_PY_BINARY": "$(rootpaths :version_default)",
},
)

Expand All @@ -173,7 +173,7 @@ sh_test(
data = [":version_3_9"],
env = {
"VERSION_CHECK": "3.9",
"VERSION_PY_BINARY": "$(rootpath :version_3_9)",
"VERSION_PY_BINARY": "$(rootpaths :version_3_9)",
},
)

Expand All @@ -183,6 +183,6 @@ sh_test(
data = [":version_3_10"],
env = {
"VERSION_CHECK": "3.10",
"VERSION_PY_BINARY": "$(rootpath :version_3_10)",
"VERSION_PY_BINARY": "$(rootpaths :version_3_10)",
},
)
6 changes: 5 additions & 1 deletion examples/bzlmod/tests/version_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

set -o errexit -o nounset -o pipefail

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

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

0 comments on commit 1b2714e

Please sign in to comment.