[compiler-rt][Darwin] Refactor minimum deployment target substitutions

* Support macOS 11+ version scheme
* Standardize substitution name `%min_deployment_target=x.y`
* Remove unneeded error cases (the input version is hard-coded)
* Specify version as tuple instead of string; no need to parse it

These changes should also facilitate a future addition of a substitution
that expands to "set deployment target to current target version"
(https://reviews.llvm.org/D70151).

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D85925
This commit is contained in:
Julian Lettner 2020-08-12 15:02:42 -07:00
parent 9670029b6b
commit 1f3c92f968
2 changed files with 40 additions and 63 deletions

View File

@ -1,6 +1,6 @@
// Test to make sure basic initialization order errors are caught.
// RUN: %clangxx_asan %macos_min_target_10_11 -O0 %s %p/Helpers/initialization-bug-extra2.cpp -o %t-INIT-ORDER-EXE
// RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra2.cpp -o %t-INIT-ORDER-EXE
// RUN: %env_asan_opts=check_initialization_order=true not %run %t-INIT-ORDER-EXE 2>&1 | FileCheck %s
// Do not test with optimization -- the error may be optimized away.

View File

@ -264,52 +264,14 @@ if config.gwp_asan:
lit.util.usePlatformSdkOnDarwin(config, lit_config)
# Maps a lit substitution name for the minimum target OS flag
# to the macOS version that first contained the relevant feature.
darwin_min_deployment_target_substitutions = {
'%macos_min_target_10_11': '10.11',
'%darwin_min_target_with_tls_support': '10.12', # TLS requires watchOS 3+ simulator
}
min_macos_deployment_target_substitutions = [
(10, 11),
(10, 12),
]
# TLS requires watchOS 3+
config.substitutions.append( ('%darwin_min_target_with_tls_support', '%min_macos_deployment_target=10.12') )
if config.host_os == 'Darwin':
def get_apple_platform_version_aligned_with(macos_version, apple_platform):
"""
Given a macOS version (`macos_version`) returns the corresponding version for
the specified Apple platform if it exists.
`macos_version` - The macOS version as a string.
`apple_platform` - The Apple platform name as a string.
Returns the corresponding version as a string if it exists, otherwise
`None` is returned.
"""
m = re.match(r'^10\.(?P<min>\d+)(\.(?P<patch>\d+))?$', macos_version)
if not m:
raise Exception('Could not parse macOS version: "{}"'.format(macos_version))
ver_min = int(m.group('min'))
ver_patch = m.group('patch')
if ver_patch:
ver_patch = int(ver_patch)
else:
ver_patch = 0
result_str = ''
if apple_platform == 'osx':
# Drop patch for now.
result_str = '10.{}'.format(ver_min)
elif apple_platform.startswith('ios') or apple_platform.startswith('tvos'):
result_maj = ver_min - 2
if result_maj < 1:
return None
result_str = '{}.{}'.format(result_maj, ver_patch)
elif apple_platform.startswith('watch'):
result_maj = ver_min - 9
if result_maj < 1:
return None
result_str = '{}.{}'.format(result_maj, ver_patch)
else:
raise Exception('Unsuported apple platform "{}"'.format(apple_platform))
return result_str
osx_version = (10, 0, 0)
try:
osx_version = subprocess.check_output(["sw_vers", "-productVersion"],
@ -341,29 +303,44 @@ if config.host_os == 'Darwin':
except:
pass
def get_apple_min_deploy_target_flag_aligned_with_osx(version):
min_os_aligned_with_osx_v = get_apple_platform_version_aligned_with(version, config.apple_platform)
min_os_aligned_with_osx_v_flag = ''
if min_os_aligned_with_osx_v:
min_os_aligned_with_osx_v_flag = '{flag}={version}'.format(
flag=config.apple_platform_min_deployment_target_flag,
version=min_os_aligned_with_osx_v)
else:
lit_config.warning('Could not find a version of {} that corresponds with macOS {}'.format(
config.apple_platform,
version))
return min_os_aligned_with_osx_v_flag
for substitution, osx_version in darwin_min_deployment_target_substitutions.items():
config.substitutions.append( (substitution, get_apple_min_deploy_target_flag_aligned_with_osx(osx_version)) )
# 32-bit iOS simulator is deprecated and removed in latest Xcode.
if config.apple_platform == "iossim":
if config.target_arch == "i386":
config.unsupported = True
def get_macos_aligned_version(macos_vers):
platform = config.apple_platform
if platform == 'osx':
return macos_vers
macos_major, macos_minor = macos_vers
assert macos_major >= 10
if macos_major == 10: # macOS 10.x
major = macos_minor
minor = 0
else: # macOS 11+
major = macos_major + 5
minor = macos_minor
assert major >= 11
if platform.startswith('ios') or platform.startswith('tvos'):
major -= 2
elif platform.startswith('watch'):
major -= 9
else:
lit_config.fatal("Unsupported apple platform '{}'".format(platform))
return (major, minor)
for vers in min_macos_deployment_target_substitutions:
flag = config.apple_platform_min_deployment_target_flag
major, minor = get_macos_aligned_version(vers)
config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '{}={}.{}'.format(flag, major, minor)) )
else:
for substitution in darwin_min_deployment_target_substitutions.keys():
config.substitutions.append( (substitution, "") )
for vers in min_macos_deployment_target_substitutions:
config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '') )
if config.android:
env = os.environ.copy()