Conversation
b64ea51 to
b602fbe
Compare
Szelethus
left a comment
There was a problem hiding this comment.
Bazel 7, during unittest, seems to prefer our own, while if included by another project, it seems to prefer the rules_python toolchain.
What does "prefer" mean? Does this mean that we are committing to supporting both WORKSPACE and Module system for bazel 7?
I want to know whether this is an actual requirement, because the way you explain it, this seems to be a non-trivial complexity. Would the code look significantly cleaner if we dropped WORKSPACE support for bazel 7?
src/common.bzl
Outdated
| elif hasattr(py_toolchain, "py3_runtime"): | ||
| py_runtime = py_toolchain.py3_runtime | ||
| python_path = py_runtime.interpreter_path | ||
| if python_path == None: # Bazel 8 |
There was a problem hiding this comment.
Thats a vague comment on its own.
src/common.bzl
Outdated
|
|
||
| def python_interpreter_tool(ctx): | ||
| """ | ||
| Returns version specific Python interpreter object in a list |
There was a problem hiding this comment.
Do we have to return a list?
| Returns version specific Python interpreter object in a list | |
| Returns version specific Python interpreter object that is appropriate for the Bazel version that is running |
There was a problem hiding this comment.
We don't have to return a list, but handling the case where there is no tool to return (Bazel 6) will become very ugly.
Now we have (removing unimportant parts):
ctx.actions.run(
executable = python_path(ctx),
tools = python_interpreter_tool(ctx),
arguments = [
...
],
use_default_shell_env = True,
)
This would look like:
ctx.actions.run(
executable = python_path(ctx),
tools = [python_interpreter_tool(ctx)] if python_interpreter_tool(ctx) != None else [],
arguments = [
...
],
use_default_shell_env = True,
)
or we calculate tools ahead of time:
tools = [python_interpreter_tool(ctx)] if python_interpreter_tool(ctx) != None else [],
ctx.actions.run(.....)
| #python = use_extension("@rules_python//python/extensions:python.bzl", "python") | ||
| #python.toolchain( | ||
| # python_version = "3.10", | ||
| # is_default = True, | ||
| #) |
There was a problem hiding this comment.
What is the story with these?
There was a problem hiding this comment.
I tried everything to leave the toolchain registration for the old toolchain in the MODULE file, and have rules_python have a higher priority, but I failed.
These options I have come across during that. (I left them in thinking they might be interesting)
|
My explanation might not been the best, mostly it was just noting my experience trying this change out in different environments. The strange behaviour, while I'm not completely sure I understand (which we should before merging), is most likely due to the way the rule is included in a project.
This theory holds up in FOSS tests:
This would also mean that Bazel 8 will fail on tests using WORKSPACE files (Bazel 8 can be forced to read WORKSPACE files) |
41f71ef to
e947e0b
Compare
e947e0b to
e11868f
Compare
Why:
Necessary for Bazel 8 support.
What:
rules_pythonas a dependencyMODULE.bazel; if left there, its priority would shadow the rules_python toolchain. Bazel 7, during unittest, seems to prefer our own, while if included by another project, it seems to prefer the rules_python toolchain. (Adding the following flag will reveal the process of toolchain selection:--toolchain_resolution_debug=.*)(The logic behind this:
MODULEfile, e.g., zlib-modules, it will use the rules_python toolchain. (My theory for this is that register_toolchains takes the highest precedence in the order of toolchain resolution, and in other projects, we don't register the toolchain))
use_default_shell_envis enabled, the path to an executable is accepted as executable.codechecker_test- I have no better idea of how I return an executable that, without any parameters, would execute the script using the interpreter, that maybe inside the sandbox, maybe not. I'm open to any better ideas. (The only idea I have is dropping the template expansion entirely, and using py_binary targets instead)Addresses:
#108