Skip to content

Commit a0e8462

Browse files
authored
[compiler-rt][sanitizer_common] Improve handling of env vars for iOS simulator tests (#146721)
* Fix splitting of arguments such as `LSAN_OPTIONS=suppressions=lsan.supp` * Prevent environment variables set in parent process being overwritten * Replace hard-coded `env` with `%env` to allow overriding depending on target * Replace deprecated `pipes` usage with `shlex` * Run formatter over `iossim_env.py`
1 parent 53baee9 commit a0e8462

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

compiler-rt/test/sanitizer_common/ios_commands/iossim_env.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
idx = 1
77
for arg in sys.argv[1:]:
8-
if not "=" in arg:
9-
break
10-
idx += 1
11-
(argname, argval) = arg.split("=")
12-
os.environ["SIMCTL_CHILD_" + argname] = argval
8+
if not "=" in arg:
9+
break
10+
idx += 1
11+
(argname, argval) = arg.split("=", maxsplit=1)
12+
os.environ["SIMCTL_CHILD_" + argname] = argval
1313

1414
exitcode = subprocess.call(sys.argv[idx:])
1515
if exitcode > 125:
16-
exitcode = 126
16+
exitcode = 126
1717
sys.exit(exitcode)

compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
import glob, os, pipes, sys, subprocess
3+
import glob, os, shlex, sys, subprocess
44

55

66
device_id = os.environ.get("SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER")
@@ -21,8 +21,11 @@
2121
"ASAN_ACTIVATION_OPTIONS",
2222
"MallocNanoZone",
2323
]:
24-
if e in os.environ:
25-
os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
24+
simctl_version = "SIMCTL_CHILD_" + e
25+
# iossim_env.py might have already set these using arguments it was given
26+
# (and that we can't see from inside this script). Don't overwrite them!
27+
if e in os.environ and simctl_version not in os.environ:
28+
os.environ[simctl_version] = os.environ[e]
2629

2730
find_atos_cmd = "xcrun -sdk iphonesimulator -f atos"
2831
atos_path = (
@@ -49,8 +52,7 @@
4952
# Don't quote glob pattern
5053
rm_args.append(arg)
5154
else:
52-
# FIXME(dliew): pipes.quote() is deprecated
53-
rm_args.append(pipes.quote(arg))
55+
rm_args.append(shlex.quote(arg))
5456
rm_cmd_line = ["/bin/rm"] + rm_args
5557
rm_cmd_line_str = " ".join(rm_cmd_line)
5658
# We use `shell=True` so that any wildcard globs get expanded by the shell.

compiler-rt/test/sanitizer_common/lit.common.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def build_invocation(compile_flags):
8787
config.substitutions.append(("%tool_name", config.tool_name))
8888
config.substitutions.append(("%tool_options", tool_options))
8989
config.substitutions.append(
90-
("%env_tool_opts=", "env " + tool_options + "=" + default_tool_options_str)
90+
("%env_tool_opts=", "%env " + tool_options + "=" + default_tool_options_str)
9191
)
9292

9393
config.suffixes = [".c", ".cpp"]

0 commit comments

Comments
 (0)