[compiler-rt] [compiler-rt][sanitizer_common] Improve handling of env vars for iOS simulator tests (PR #146721)

Dan Blackwell via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 09:01:56 PDT 2025


https://github.com/DanBlackwell updated https://github.com/llvm/llvm-project/pull/146721

>From 2e100dbca2db02a1f2875fa585c9a86043ef609e Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Wed, 2 Jul 2025 16:01:12 +0100
Subject: [PATCH 1/2] [compiler-rt][sanitizer_common] Improve handling of env
 vars for iOS simulator tests

---
 .../test/sanitizer_common/ios_commands/iossim_env.py |  2 +-
 .../test/sanitizer_common/ios_commands/iossim_run.py | 12 +++++++-----
 compiler-rt/test/sanitizer_common/lit.common.cfg.py  |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
index 57a01f3852b06..1bcd8e05033a5 100755
--- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
+++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
@@ -8,7 +8,7 @@
   if not "=" in arg:
     break
   idx += 1
-  (argname, argval) = arg.split("=")
+  (argname, argval) = arg.split("=", maxsplit=1)
   os.environ["SIMCTL_CHILD_" + argname] = argval
 
 exitcode = subprocess.call(sys.argv[idx:])
diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
index 5e977ea5ed908..ddb76f0b18d63 100755
--- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
+++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-import glob, os, pipes, sys, subprocess
+import glob, os, shlex, sys, subprocess
 
 
 device_id = os.environ.get("SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER")
@@ -21,8 +21,11 @@
     "ASAN_ACTIVATION_OPTIONS",
     "MallocNanoZone",
 ]:
-    if e in os.environ:
-        os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
+    simctl_version = "SIMCTL_CHILD_" + e 
+    # iossim_env.py might have already set these using arguments it was given
+    # (and that we can't see from inside this script). Don't overwrite them!
+    if e in os.environ and simctl_version not in os.environ:
+        os.environ[simctl_version] = os.environ[e]
 
 find_atos_cmd = "xcrun -sdk iphonesimulator -f atos"
 atos_path = (
@@ -49,8 +52,7 @@
             # Don't quote glob pattern
             rm_args.append(arg)
         else:
-            # FIXME(dliew): pipes.quote() is deprecated
-            rm_args.append(pipes.quote(arg))
+            rm_args.append(shlex.quote(arg))
     rm_cmd_line = ["/bin/rm"] + rm_args
     rm_cmd_line_str = " ".join(rm_cmd_line)
     # We use `shell=True` so that any wildcard globs get expanded by the shell.
diff --git a/compiler-rt/test/sanitizer_common/lit.common.cfg.py b/compiler-rt/test/sanitizer_common/lit.common.cfg.py
index c3c1336bacd53..88d3ea9bc5ad2 100644
--- a/compiler-rt/test/sanitizer_common/lit.common.cfg.py
+++ b/compiler-rt/test/sanitizer_common/lit.common.cfg.py
@@ -87,7 +87,7 @@ def build_invocation(compile_flags):
 config.substitutions.append(("%tool_name", config.tool_name))
 config.substitutions.append(("%tool_options", tool_options))
 config.substitutions.append(
-    ("%env_tool_opts=", "env " + tool_options + "=" + default_tool_options_str)
+    ("%env_tool_opts=", "%env " + tool_options + "=" + default_tool_options_str)
 )
 
 config.suffixes = [".c", ".cpp"]

>From 706c78ec3d6ed13163d1f59d24b93ceed340b4af Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Wed, 2 Jul 2025 17:01:37 +0100
Subject: [PATCH 2/2] Fixup: formatting

---
 .../test/sanitizer_common/ios_commands/iossim_env.py | 12 ++++++------
 .../test/sanitizer_common/ios_commands/iossim_run.py |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
index 1bcd8e05033a5..ddc260fa61644 100755
--- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
+++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py
@@ -5,13 +5,13 @@
 
 idx = 1
 for arg in sys.argv[1:]:
-  if not "=" in arg:
-    break
-  idx += 1
-  (argname, argval) = arg.split("=", maxsplit=1)
-  os.environ["SIMCTL_CHILD_" + argname] = argval
+    if not "=" in arg:
+        break
+    idx += 1
+    (argname, argval) = arg.split("=", maxsplit=1)
+    os.environ["SIMCTL_CHILD_" + argname] = argval
 
 exitcode = subprocess.call(sys.argv[idx:])
 if exitcode > 125:
-  exitcode = 126
+    exitcode = 126
 sys.exit(exitcode)
diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
index ddb76f0b18d63..ec394067dc7a5 100755
--- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
+++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py
@@ -21,7 +21,7 @@
     "ASAN_ACTIVATION_OPTIONS",
     "MallocNanoZone",
 ]:
-    simctl_version = "SIMCTL_CHILD_" + e 
+    simctl_version = "SIMCTL_CHILD_" + e
     # iossim_env.py might have already set these using arguments it was given
     # (and that we can't see from inside this script). Don't overwrite them!
     if e in os.environ and simctl_version not in os.environ:



More information about the llvm-commits mailing list