[llvm] [lit] Export env vars in script to avoid pruning (PR #105759)

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 17:57:57 PDT 2024


https://github.com/keith created https://github.com/llvm/llvm-project/pull/105759

On macOS the dynamic loader prunes dyld specific environment variables such as `DYLD_INSERT_LIBRARIES`, `DYLD_LIBRARY_PATH`, etc. If these are set in the lit config it's safe to assume that the user actually wanted their subprocesses to run with these variables, versus the python interpreter that gets executed with them before they are pruned. This change exports all known variables in the shell script instead of relying on them being passed through.

>From 09671451af93ebe468971bc3e3b9882d09b7f354 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Thu, 22 Aug 2024 17:55:50 -0700
Subject: [PATCH] [lit] Export env vars in script to avoid pruning

On macOS the dynamic loader prunes dyld specific environment variables
such as `DYLD_INSERT_LIBRARIES`, `DYLD_LIBRARY_PATH`, etc. If these are
set in the lit config it's safe to assume that the user actually wanted
their subprocesses to run with these variables, versus the python
interpreter that gets executed with them before they are pruned. This
change exports all known variables in the shell script instead of
relying on them being passed through.
---
 llvm/utils/lit/lit/TestRunner.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index da7fa86fd39173..7ea9fb9594cc32 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1223,6 +1223,11 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
         if test.config.pipefail:
             f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
         f.write(b"set -x;" if mode == "wb" else "set -x;")
+
+        env_str = "\n".join("export {}={};".format(k, shlex.quote(v))
+                            for k, v in test.config.environment.items())
+        f.write(bytes(env_str, "utf-8") if mode == "wb" else env_str)
+
         if sys.version_info > (3, 0) and mode == "wb":
             f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))
         else:



More information about the llvm-commits mailing list