Skip to content

Commit 89bae85

Browse files
authored
[bazel] Fix lit tests with python 3.11+ (#87022)
In python3.11 there is a new environment variable PYTHONSAFEPATH which stops python from setting the current directory as the first entry in sys.path. Bazel started setting this to ensure that python targets don't accidentally access things that aren't in their dependency tree. This resulted in lit tests breaking because sys.path didn't include the directory to the lit source files. This is fixed by adding the lit binary to the dependency tree and propagating the import path from it. Fixes #75963
1 parent 39e8137 commit 89bae85

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4927,6 +4927,7 @@ py_binary(
49274927
name = "lit",
49284928
testonly = True,
49294929
srcs = ["utils/lit/lit.py"] + glob(["utils/lit/lit/**/*.py"]),
4930+
imports = ["utils/lit"],
49304931
)
49314932

49324933
py_binary(

utils/bazel/llvm-project-overlay/llvm/lit_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def lit_test(
3535
args = args + ["-v"] + ["$(execpath %s)" % src for src in srcs],
3636
data = data + srcs,
3737
legacy_create_init = False,
38+
deps = [Label("//llvm:lit")],
3839
**kwargs
3940
)
4041

0 commit comments

Comments
 (0)