• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import glob, os, pipes, sys, subprocess
4
5
6device_id = os.environ.get('SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER')
7if not device_id:
8  raise EnvironmentError("Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use.")
9
10for e in ["ASAN_OPTIONS", "TSAN_OPTIONS", "UBSAN_OPTIONS", "APPLE_ASAN_INIT_FOR_DLOPEN", "ASAN_ACTIVATION_OPTIONS"]:
11  if e in os.environ:
12    os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
13
14prog = sys.argv[1]
15exit_code = None
16if prog == 'rm':
17  # The simulator and host actually share the same file system so we can just
18  # execute directly on the host.
19  rm_args = []
20  for arg in sys.argv[2:]:
21    if '*' in arg or '?' in arg:
22      # Don't quote glob pattern
23      rm_args.append(arg)
24    else:
25      # FIXME(dliew): pipes.quote() is deprecated
26      rm_args.append(pipes.quote(arg))
27  rm_cmd_line = ["/bin/rm"] + rm_args
28  rm_cmd_line_str = ' '.join(rm_cmd_line)
29  # We use `shell=True` so that any wildcard globs get expanded by the shell.
30  exitcode = subprocess.call(rm_cmd_line_str, shell=True)
31else:
32  exitcode = subprocess.call(["xcrun", "simctl", "spawn", "--standalone", device_id] + sys.argv[1:])
33if exitcode > 125:
34  exitcode = 126
35sys.exit(exitcode)
36