diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -264,6 +264,67 @@ config.darwin_osx_version = osx_version + # Get Target OS version + get_os_cmd = [] + run_wrapper = filter(lambda s: s[0] == '%run', config.substitutions)[0][1] + assert isinstance(run_wrapper, str) + if run_wrapper != "": + get_os_cmd.append(run_wrapper) + get_os_cmd.extend(['sw_vers', '-productVersion']) + apple_target_os_version_output = subprocess.check_output(get_os_cmd) + apple_target_os_tuple = None + for line in apple_target_os_version_output.split('\n'): + m = re.match(r'^(?P\d+)\.(?P\d+)(\.(?P\d+))?$', line) + if m: + apple_target_os_major_version = int(m.group('major')) + apple_target_os_minor_version = int(m.group('minor')) + apple_target_os_patch_version = 0 + if m.group('patch'): + apple_target_os_patch_version = int(m.group('patch')) + apple_target_os_tuple = ( + apple_target_os_major_version, + apple_target_os_minor_version, + apple_target_os_patch_version + ) + break + if not apple_target_os_tuple: + lit_config.fatal('Failed to determine OS version of {} target'.format( + config.apple_platform) + ) + lit_config.note( + 'Target Apple platform {} has version {}'.format( + config.apple_platform, + apple_target_os_tuple) + ) + # Create substitution for minimum deployment target matching target + if config.apple_platform == 'osx': + min_os_version_deployment_flag = '-mmacosx-version-min' + elif config.apple_platform == 'ios': + min_os_version_deployment_flag = '-miphoneos-version-min' + elif config.apple_platform == 'iossim': + min_os_version_deployment_flag = '-mios-simulator-version-min' + elif config.apple_platform == 'watchos': + min_os_version_deployment_flag = '-mwatchos-version-min' + elif config.apple_platform == 'watchossim': + min_os_version_deployment_flag = '-mwatchos-simulator-version-min' + elif config.apple_platform == 'tvos': + min_os_version_deployment_flag = '-mtvos-version-min' + elif config.apple_platform == 'tvossim': + min_os_version_deployment_flag = '-mtvos-simulator-version-min' + else: + lit_config.fatal('Unhandled Apple platform "{}"'.format( + config.apple_platform) + ) + # We do not use `apple_target_os_tuple[2]` here because dyld + # doesn't handle it properly. rdar://problem/57133776. + config.substitutions.append(('%match_min_os_deployment_version_to_target', + '{}={}.{}'.format( + min_os_version_deployment_flag, + apple_target_os_tuple[0], + apple_target_os_tuple[1], + )) + ) + # Detect x86_64h try: output = subprocess.check_output(["sysctl", "hw.cpusubtype"]) diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py --- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py +++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py @@ -29,6 +29,28 @@ rm_cmd_line_str = ' '.join(rm_cmd_line) # We use `shell=True` so that any wildcard globs get expanded by the shell. exitcode = subprocess.call(rm_cmd_line_str, shell=True) +elif prog == 'sw_vers': + args = sys.argv[2:] + if len(args) == 0: + print("Argument must be provided") + sys.exit(1) + if args[0] != '-productVersion': + print("Only -productVersion is supported") + sys.exit(1) + # sw_vers is not shipped in the simulator runtime so try to emulate `sw_vers + # -productVersion` by inspecting the environment of the simulator. + exitcode = subprocess.call( + [ + "xcrun", + "simctl", + "spawn", + device_id, + 'bin/bash', + '-c', + 'echo $SIMULATOR_RUNTIME_VERSION' + ] + ) + sys.exit(exitcode) else: exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:]) if exitcode > 125: