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

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 24 09:20:18 PDT 2024


Author: Keith Smiley
Date: 2024-08-24T09:20:14-07:00
New Revision: 65b7cbbd8735b90933369364153b982d498f649a

URL: https://github.com/llvm/llvm-project/commit/65b7cbbd8735b90933369364153b982d498f649a
DIFF: https://github.com/llvm/llvm-project/commit/65b7cbbd8735b90933369364153b982d498f649a.diff

LOG: [lit] Export env vars in script to avoid pruning (#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.

Added: 
    

Modified: 
    llvm/utils/lit/lit/TestRunner.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 2d9af9fbbb3634..4dad1412436d93 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1226,6 +1226,16 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
                     commands[i] += f" && {{ {command}; }}"
         if test.config.pipefail:
             f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
+
+        # Manually export any DYLD_* variables used by dyld on macOS because
+        # otherwise they are lost when the shell executable is run, before the
+        # lit test is executed.
+        env_str = "\n".join(
+            "export {}={};".format(k, shlex.quote(v))
+            for k, v in test.config.environment.items()
+            if k.startswith("DYLD_")
+        )
+        f.write(bytes(env_str, "utf-8") if mode == "wb" else env_str)
         f.write(b"set -x;" if mode == "wb" else "set -x;")
         if sys.version_info > (3, 0) and mode == "wb":
             f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))


        


More information about the llvm-commits mailing list