1#!/usr/bin/env python3 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 [ 11 "ASAN_OPTIONS", 12 "TSAN_OPTIONS", 13 "UBSAN_OPTIONS", 14 "APPLE_ASAN_INIT_FOR_DLOPEN", 15 "ASAN_ACTIVATION_OPTIONS", 16 "MallocNanoZone", 17]: 18 if e in os.environ: 19 os.environ["SIMCTL_CHILD_" + e] = os.environ[e] 20 21prog = sys.argv[1] 22exit_code = None 23if prog == 'rm': 24 # The simulator and host actually share the same file system so we can just 25 # execute directly on the host. 26 rm_args = [] 27 for arg in sys.argv[2:]: 28 if '*' in arg or '?' in arg: 29 # Don't quote glob pattern 30 rm_args.append(arg) 31 else: 32 # FIXME(dliew): pipes.quote() is deprecated 33 rm_args.append(pipes.quote(arg)) 34 rm_cmd_line = ["/bin/rm"] + rm_args 35 rm_cmd_line_str = ' '.join(rm_cmd_line) 36 # We use `shell=True` so that any wildcard globs get expanded by the shell. 37 exitcode = subprocess.call(rm_cmd_line_str, shell=True) 38else: 39 exitcode = subprocess.call(["xcrun", "simctl", "spawn", "--standalone", device_id] + sys.argv[1:]) 40if exitcode > 125: 41 exitcode = 126 42sys.exit(exitcode) 43