[llvm] [lit][bazel] Fall back to a default PATHEXT when the variable is unset (PR #217416)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 05:47:21 PDT 2026
https://github.com/UebelAndre updated https://github.com/llvm/llvm-project/pull/217416
>From be0e9c9b398bd6ccddb64b1a094e418b3f90ae98 Mon Sep 17 00:00:00 2001
From: UebelAndre <github at uebelandre.com>
Date: Thu, 20 Aug 2026 05:47:05 -0700
Subject: [PATCH] [lit][bazel] Fall back to a default PATHEXT when the variable
is unset
---
llvm/utils/lit/lit/util.py | 7 ++++++-
llvm/utils/lit/tests/use-llvm-tool.py | 8 ++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index 8ab109fe15d45..a1f8457395d84 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -130,7 +130,12 @@ def which(command, paths=None):
# Get suffixes to search.
# On Cygwin, 'PATHEXT' may exist but it should not be used.
if os.pathsep == ";":
- pathext = os.environ.get("PATHEXT", "").split(";")
+ # If PATHEXT was stripped from the environment (e.g. when
+ # running with a hermetic build system like Bazel) then
+ # use a sane fallback so binaries can still be located.
+ fallback = ".COM;.EXE;.BAT;.CMD"
+
+ pathext = os.environ.get("PATHEXT", fallback).split(";")
else:
pathext = [""]
diff --git a/llvm/utils/lit/tests/use-llvm-tool.py b/llvm/utils/lit/tests/use-llvm-tool.py
index 3e190a3e40f71..50a4e1cd48ef9 100644
--- a/llvm/utils/lit/tests/use-llvm-tool.py
+++ b/llvm/utils/lit/tests/use-llvm-tool.py
@@ -33,6 +33,14 @@
# CHECK-NEXT: note: using case9: {{.*}}search2{{[\\/]}}case9
# CHECK-NEXT: note: using case10: {{.*}}path{{[\\/]}}case10
+## Show that tools are still found when PATHEXT is unset, as can happen with
+## hermetic build systems (like Bazel) that strip environment variables.
+## Inputs provide both "case2" and "case2.exe", so match the extension
+## explicitly: without a fallback, lit finds the extension-less "case2".
+# RUN: %if system-windows %{ env -u PATHEXT %{lit} %{inputs}/use-llvm-tool 2>&1 | \
+# RUN: FileCheck %s --check-prefix=NO-PATHEXT %}
+# NO-PATHEXT: note: using case2: {{.*}}build{{[\\/]}}case2.exe
+
## Test that if required is True, lit errors if the tool is not found.
# RUN: not %{lit} %{inputs}/use-llvm-tool-required 2>&1 | \
# RUN: FileCheck %s --check-prefix=ERROR
More information about the llvm-commits
mailing list