bazel-contrib / bazel-contrib/rules_python

Support incompatible_strict_action_env

オープン
#3,655 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
core-rules
主要言語
Starlark
スター
688
フォーク
721
平均マージ
15時間 7分
マージ済み PR(30日)
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)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、厳格なアクション環境を有効にした Bazel 9 で Windows のケースを再現します: data に py_binary を持つ sh_binary です。Bazel ランチャーの runfiles とインタープリター検索の動作を読み、その後、Python の直接実行および RunEnvironmentInfo アプローチと比較します。ネストされたバイナリが、PATH の継承や文書化された workaround を必要とせずに Python インタープリターを見つけられれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
build-system
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。