bazel-contrib / bazel-contrib/rules_python

Support incompatible_strict_action_env

未关闭
#3,655 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
core-rules
主要语言
Starlark
星标
688
派生
721
平均合并
15 小时 7 分钟
30 天内合并 PR
76

描述

As of Bazel 9, `--incompatible_strict_action_env=true` is the default.

Almost everything works with that set, the one exception is Windows in a particular case. That particular case appears to be when the python program is a data dep of another binary, e.g. an sh_binary with a py_binary in data. What happens is the Bazel launcher can't find the python interpreter in runfiles, so falls back to looking for `python.exe` on `PATH`. When strict action env is enabled, the outer PATH isn't inherited, so python.exe can't be found, and thus the launcher fails to execute.

A direct execution of a python program is ok, since the runfiles structure is present enough that the bazel launcher can find the interpreter.

Other than moving away from the Bazel launcher, I don't see a way to solve this. We've wanted to stop using the bazel launcher anyways, so this isn't a big deal, this case just add additional pressure to do so.

Fundamentally, when a binary is running within another binary's runfiles, the logic to find things is a bit more convoluted. We can use RunEnvironmentInfo so that tests auto-inherit PATH, but this only helps tests. binaries-in-binaries or binaries-run-by-actions wouldn't be affected.

There are two workarounds:

* Set `--incompatible_strict_action_env=false` (restore non-strict env behavior, which includes PATH)
* Set `--action_env=PATH` (only inherit PATH for actions)

贡献指南

打开贡献指南

调研方向

Start by reproducing the Windows case with Bazel 9 and strict action environment enabled: an sh_binary with a py_binary in data. Read the Bazel launcher’s runfiles and interpreter lookup behavior, then compare it with direct Python execution and the RunEnvironmentInfo approach. Done means the nested binary can locate its Python interpreter without requiring PATH inheritance or the documented workaround.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
build-system
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。