Skip to content

Commit 65b7cbb

Browse files
authored
[lit] Export env vars in script to avoid pruning (llvm#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.
1 parent 08acc3f commit 65b7cbb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,16 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
12261226
commands[i] += f" && {{ {command}; }}"
12271227
if test.config.pipefail:
12281228
f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
1229+
1230+
# Manually export any DYLD_* variables used by dyld on macOS because
1231+
# otherwise they are lost when the shell executable is run, before the
1232+
# lit test is executed.
1233+
env_str = "\n".join(
1234+
"export {}={};".format(k, shlex.quote(v))
1235+
for k, v in test.config.environment.items()
1236+
if k.startswith("DYLD_")
1237+
)
1238+
f.write(bytes(env_str, "utf-8") if mode == "wb" else env_str)
12291239
f.write(b"set -x;" if mode == "wb" else "set -x;")
12301240
if sys.version_info > (3, 0) and mode == "wb":
12311241
f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))

0 commit comments

Comments
 (0)