bazel-contrib / bazel-contrib/rules_python
precompiling results in action output conflicts
- 主要语言
- Starlark
- 星标
- 688
- 派生
- 721
- 平均合并
- 15 小时 7 分钟
- 30 天内合并 PR
- 76
描述
# 🐞 bug report
### Affected Rule
```bzl
load("@rules_python//python:defs.bzl", "py_test")
py_test(
name = "first",
srcs = ["foo.py"],
main = "foo.py",
)
py_test(
name = "second",
srcs = ["foo.py"],
exec_properties = {"foo": "bar"},
main = "foo.py",
)
```
With this BUILD file, where 2 python rules include the same file, building both of these targets results in:
```
ERROR: file '__pycache__/foo.cpython-311.pyc' is generated by these conflicting actions:
Label: //:second, //:first
RuleClass: py_test rule
JavaActionClass: class com.google.devtools.build.lib.analysis.actions.StarlarkAction
Configuration: 8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1
Mnemonic: PyCompile
Action key: aa843bb97b9c08aba98aa87861cf3bba7f6f80370dcc227a3aa766a618449a45, d8983143b0af1168a9ab184492ac6ef78a440269bfd600178f4e6d984e208bf7
Progress message: Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Action describeKey: Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Environment variable: PYTHONHASHSEED=0
Environment variable: PYTHONNOUSERSITE=1
Environment variable: PYTHONSAFEPATH=1
Argument: bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python~/python/private/python3
Argument: bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python~/tools/precompiler/precompiler
Argument: --invalidation_mode
Argument: checked_hash
Argument: --src
Argument: foo.py
Argument: --src_name
Argument: foo.py
Argument: --pyc
Argument: bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Argument: --optimize
Argument: 0
Argument: --python_version
Argument: 3.11
Output paths mode: OFF
PrimaryInput: File:[/Users/ksmiley/Downloads/repro[source]]foo.py
PrimaryOutput: File:[[]bazel-out/darwin_arm64-fastbuild/bin]__pycache__/foo.cpython-311.pyc
Owner information: ConfiguredTargetKey{label=//:second, config=BuildConfigurationKey[8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1]}, ConfiguredTargetKey{label=//:first, config=BuildConfigurationKey[8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1]}
MandatoryInputs: are equal
Outputs: are equal
Use --verbose_failures to see the command lines of failed build steps.
ERROR: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for __pycache__/foo.cpython-311.pyc, previous action: action 'Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc', attempted action: action 'Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc'
```
### Is this a regression?
I bisected to https://github.com/bazelbuild/rules_python/commit/eb2225c31a20a7ee361054b088bcef8cd9434b74, we hit it when updating from 0.36.0 to 0.40.0
## 🔬 Minimal Reproduction
Build in this repo: [repro.zip](https://github.com/user-attachments/files/17926786/repro.zip)
贡献指南
调研方向
从 repro.zip 中的 BUILD 文件开始,通过同时构建第一个和第二个 py_test 目标来重现冲突。检查 commit eb2225c31a20a7ee361054b088bcef8cd9434b74 引入的回归,并追踪预编译输出路径;当两个目标都能在共享 foo.py 文件不产生操作冲突的情况下完成构建时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100