[llvm] [lit] Fix to make "RUN: env PATH=..." work as intended (PR #165308)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 00:46:44 PDT 2025


https://github.com/bjope updated https://github.com/llvm/llvm-project/pull/165308

>From 45ff976775473c85e51de0d3eccaed8619014838 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Mon, 27 Oct 2025 16:20:17 +0100
Subject: [PATCH 1/3] [lit] Fix to make "RUN: env PATH=..." work as intended

There was a bug in llvm-lit related to setting PATH using env
in the internal shell.

The new PATH wasn't used when looking up the command to be executed.
So when doing things like this in a test case
  RUN: mkdir %t
  RUN: env PATH=%t program ...
the internal shell would search for "program" using the orignal PATH
and not the PATH set by env when preceeding the command.

It seems like this was a simple mistake in commit 57782eff31e9d454,
since the logic to pick a PATH from the cmd_shenv instead of shenv
actually was added in that patch, but the resulting path wasn't used.
---
 llvm/utils/lit/lit/TestRunner.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index f88314547bb3f..9fba96a1471a0 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -945,7 +945,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
             path = (
                 cmd_shenv.env["PATH"] if "PATH" in cmd_shenv.env else shenv.env["PATH"]
             )
-            executable = lit.util.which(args[0], shenv.env["PATH"])
+            executable = lit.util.which(args[0], path)
         if not executable:
             raise InternalShellError(j, "%r: command not found" % args[0])
 

>From 6722c4b293df94e9360f71be22a8830449c940ce Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Mon, 27 Oct 2025 23:05:17 +0100
Subject: [PATCH 2/3] Fixup: Add a regression test

---
 llvm/utils/lit/tests/Inputs/shtest-env-path/lit.cfg |  8 ++++++++
 .../utils/lit/tests/Inputs/shtest-env-path/path.txt |  8 ++++++++
 llvm/utils/lit/tests/Inputs/shtest-env-path/test.sh |  4 ++++
 llvm/utils/lit/tests/shtest-env-path.py             | 13 +++++++++++++
 4 files changed, 33 insertions(+)
 create mode 100644 llvm/utils/lit/tests/Inputs/shtest-env-path/lit.cfg
 create mode 100644 llvm/utils/lit/tests/Inputs/shtest-env-path/path.txt
 create mode 100755 llvm/utils/lit/tests/Inputs/shtest-env-path/test.sh
 create mode 100644 llvm/utils/lit/tests/shtest-env-path.py

diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-path/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-env-path/lit.cfg
new file mode 100644
index 0000000000000..36517f998530b
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-path/lit.cfg
@@ -0,0 +1,8 @@
+import lit.formats
+
+config.name = "shtest-env-path"
+config.suffixes = [".txt"]
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-path/path.txt b/llvm/utils/lit/tests/Inputs/shtest-env-path/path.txt
new file mode 100644
index 0000000000000..b36e861ec5632
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-path/path.txt
@@ -0,0 +1,8 @@
+## Tests env command for setting the PATH variable.
+
+## Check that test.sh can be found using the configured PATH.
+#
+# RUN: env PATH=%S test.sh | FileCheck --check-prefix=CHECK %s
+#
+
+# CHECK: TEST-ENV-PATH-123
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-path/test.sh b/llvm/utils/lit/tests/Inputs/shtest-env-path/test.sh
new file mode 100755
index 0000000000000..a1e46fc210d49
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-path/test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "TEST-ENV-PATH-123"
+
diff --git a/llvm/utils/lit/tests/shtest-env-path.py b/llvm/utils/lit/tests/shtest-env-path.py
new file mode 100644
index 0000000000000..d1b33470530cc
--- /dev/null
+++ b/llvm/utils/lit/tests/shtest-env-path.py
@@ -0,0 +1,13 @@
+## Tests env command for setting the PATH variable.
+
+# The test is using /bin/sh. Limit to system known to have /bin/sh.
+# REQUIRED: system-linux
+
+# RUN: %{lit} -a -v %{inputs}/shtest-env-path/path.txt \
+# RUN:   | FileCheck -match-full-lines %s
+#
+# END.
+
+# CHECK: -- Testing: 1 tests{{.*}}
+# CHECK: PASS: shtest-env-path :: path.txt (1 of 1)
+# CHECK: --

>From dec56d7324040ed2fa5b8d3289a5ea7e13992916 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Tue, 28 Oct 2025 08:46:19 +0100
Subject: [PATCH 3/3] Fix typo: REQUIRED -> REQUIRES

---
 llvm/utils/lit/tests/shtest-env-path.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/tests/shtest-env-path.py b/llvm/utils/lit/tests/shtest-env-path.py
index d1b33470530cc..bf459ae53fbc0 100644
--- a/llvm/utils/lit/tests/shtest-env-path.py
+++ b/llvm/utils/lit/tests/shtest-env-path.py
@@ -1,7 +1,7 @@
 ## Tests env command for setting the PATH variable.
 
 # The test is using /bin/sh. Limit to system known to have /bin/sh.
-# REQUIRED: system-linux
+# REQUIRES: system-linux
 
 # RUN: %{lit} -a -v %{inputs}/shtest-env-path/path.txt \
 # RUN:   | FileCheck -match-full-lines %s



More information about the llvm-commits mailing list