-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Python 2 tools in exec configuration don't work in Bazel 6.x #16935
Description
Description of the bug:
When depending on a py_binary tool in exec configuration that uses python_version to specify "PY2", it somehow still tries to run in PY3 configuration and causes a build failure. This issue is not present in Bazel 5.3.0.
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
-
Create empty files
WORKSPACEandtest.py -
Put the following content in
BUILD
genrule(
name = "gen",
outs = ["out.txt"],
cmd = "echo hi > $@",
exec_tools = [":test"],
)
py_binary(
name = "test",
srcs = ["test.py"],
python_version = "PY2",
srcs_version = "PY2ONLY",
)- Run
bazel build //:gen
ERROR: /tmp/bazeltest/BUILD:24:10: Reporting failed target //:test located at /tmp/bazeltest/BUILD:24:10 [for tool] failed: //:test: This target is being built for Python 3 but (transitively) includes Python 2-only sources. You can get diagnostic information about which dependencies introduce this version requirement by running the `find_requirements` aspect. For more info see the documentation for the `srcs_version` attribute: https://bazel.build/reference/be/python#py_binary.srcs_version caused by //:test
Target //:gen failed to build
Note that bazel run //:test works just fine since it doesn't involve an exec configuration, and inserting an sh_binary rule in between the genrule and py_binary reveals that the issue is the failure of py_binary to apply an incoming edge transition (which it does apply correctly with Bazel 5.x).
Which operating system are you running Bazel on?
No response
What is the output of bazel info release?
release 6.0.0rc4
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
I'm pretty surprised that this issue leaked through this close to 6.x releasing, so it's possible I'm missing something obvious or misunderstanding how this is supposed to work.
Tagging @fmeum and @gregestren in case this is caused by other configuration transition changes in the 6.x window.