Skip to content

Commit

Permalink
[bazel] Fix lit tests with python 3.11+ (#87022)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keith committed Mar 29, 2024
1 parent 39e8137 commit 89bae85
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Expand Up @@ -4927,6 +4927,7 @@ py_binary(
name = "lit",
testonly = True,
srcs = ["utils/lit/lit.py"] + glob(["utils/lit/lit/**/*.py"]),
imports = ["utils/lit"],
)

py_binary(
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/llvm/lit_test.bzl
Expand Up @@ -35,6 +35,7 @@ def lit_test(
args = args + ["-v"] + ["$(execpath %s)" % src for src in srcs],
data = data + srcs,
legacy_create_init = False,
deps = [Label("//llvm:lit")],
**kwargs
)

Expand Down

0 comments on commit 89bae85

Please sign in to comment.