From 89bae852dddeb2b66a1843dbe5eea21184e54814 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 28 Mar 2024 19:07:22 -0700 Subject: [PATCH] [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 https://github.com/llvm/llvm-project/issues/75963 --- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel | 1 + utils/bazel/llvm-project-overlay/llvm/lit_test.bzl | 1 + 2 files changed, 2 insertions(+) diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel index 3c3e17bfec668..15e477351fe3c 100644 --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -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( diff --git a/utils/bazel/llvm-project-overlay/llvm/lit_test.bzl b/utils/bazel/llvm-project-overlay/llvm/lit_test.bzl index ce2a0a00c553a..f754a9fc7d5e4 100644 --- a/utils/bazel/llvm-project-overlay/llvm/lit_test.bzl +++ b/utils/bazel/llvm-project-overlay/llvm/lit_test.bzl @@ -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 )