Skip to content

Commit 1f3c92f

Browse files
author
Julian Lettner
committed
[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
1 parent 9670029 commit 1f3c92f

File tree

2 files changed

+40
-63
lines changed

2 files changed

+40
-63
lines changed

compiler-rt/test/asan/TestCases/initialization-bug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test to make sure basic initialization order errors are caught.
22

3-
// RUN: %clangxx_asan %macos_min_target_10_11 -O0 %s %p/Helpers/initialization-bug-extra2.cpp -o %t-INIT-ORDER-EXE
3+
// RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra2.cpp -o %t-INIT-ORDER-EXE
44
// RUN: %env_asan_opts=check_initialization_order=true not %run %t-INIT-ORDER-EXE 2>&1 | FileCheck %s
55

66
// Do not test with optimization -- the error may be optimized away.

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

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -264,52 +264,14 @@
264264

265265
lit.util.usePlatformSdkOnDarwin(config, lit_config)
266266

267-
# Maps a lit substitution name for the minimum target OS flag
268-
# to the macOS version that first contained the relevant feature.
269-
darwin_min_deployment_target_substitutions = {
270-
'%macos_min_target_10_11': '10.11',
271-
'%darwin_min_target_with_tls_support': '10.12', # TLS requires watchOS 3+ simulator
272-
}
267+
min_macos_deployment_target_substitutions = [
268+
(10, 11),
269+
(10, 12),
270+
]
271+
# TLS requires watchOS 3+
272+
config.substitutions.append( ('%darwin_min_target_with_tls_support', '%min_macos_deployment_target=10.12') )
273273

274274
if config.host_os == 'Darwin':
275-
def get_apple_platform_version_aligned_with(macos_version, apple_platform):
276-
"""
277-
Given a macOS version (`macos_version`) returns the corresponding version for
278-
the specified Apple platform if it exists.
279-
280-
`macos_version` - The macOS version as a string.
281-
`apple_platform` - The Apple platform name as a string.
282-
283-
Returns the corresponding version as a string if it exists, otherwise
284-
`None` is returned.
285-
"""
286-
m = re.match(r'^10\.(?P<min>\d+)(\.(?P<patch>\d+))?$', macos_version)
287-
if not m:
288-
raise Exception('Could not parse macOS version: "{}"'.format(macos_version))
289-
ver_min = int(m.group('min'))
290-
ver_patch = m.group('patch')
291-
if ver_patch:
292-
ver_patch = int(ver_patch)
293-
else:
294-
ver_patch = 0
295-
result_str = ''
296-
if apple_platform == 'osx':
297-
# Drop patch for now.
298-
result_str = '10.{}'.format(ver_min)
299-
elif apple_platform.startswith('ios') or apple_platform.startswith('tvos'):
300-
result_maj = ver_min - 2
301-
if result_maj < 1:
302-
return None
303-
result_str = '{}.{}'.format(result_maj, ver_patch)
304-
elif apple_platform.startswith('watch'):
305-
result_maj = ver_min - 9
306-
if result_maj < 1:
307-
return None
308-
result_str = '{}.{}'.format(result_maj, ver_patch)
309-
else:
310-
raise Exception('Unsuported apple platform "{}"'.format(apple_platform))
311-
return result_str
312-
313275
osx_version = (10, 0, 0)
314276
try:
315277
osx_version = subprocess.check_output(["sw_vers", "-productVersion"],
@@ -341,29 +303,44 @@ def get_apple_platform_version_aligned_with(macos_version, apple_platform):
341303
except:
342304
pass
343305

344-
def get_apple_min_deploy_target_flag_aligned_with_osx(version):
345-
min_os_aligned_with_osx_v = get_apple_platform_version_aligned_with(version, config.apple_platform)
346-
min_os_aligned_with_osx_v_flag = ''
347-
if min_os_aligned_with_osx_v:
348-
min_os_aligned_with_osx_v_flag = '{flag}={version}'.format(
349-
flag=config.apple_platform_min_deployment_target_flag,
350-
version=min_os_aligned_with_osx_v)
351-
else:
352-
lit_config.warning('Could not find a version of {} that corresponds with macOS {}'.format(
353-
config.apple_platform,
354-
version))
355-
return min_os_aligned_with_osx_v_flag
356-
357-
for substitution, osx_version in darwin_min_deployment_target_substitutions.items():
358-
config.substitutions.append( (substitution, get_apple_min_deploy_target_flag_aligned_with_osx(osx_version)) )
359-
360306
# 32-bit iOS simulator is deprecated and removed in latest Xcode.
361307
if config.apple_platform == "iossim":
362308
if config.target_arch == "i386":
363309
config.unsupported = True
310+
311+
def get_macos_aligned_version(macos_vers):
312+
platform = config.apple_platform
313+
if platform == 'osx':
314+
return macos_vers
315+
316+
macos_major, macos_minor = macos_vers
317+
assert macos_major >= 10
318+
319+
if macos_major == 10: # macOS 10.x
320+
major = macos_minor
321+
minor = 0
322+
else: # macOS 11+
323+
major = macos_major + 5
324+
minor = macos_minor
325+
326+
assert major >= 11
327+
328+
if platform.startswith('ios') or platform.startswith('tvos'):
329+
major -= 2
330+
elif platform.startswith('watch'):
331+
major -= 9
332+
else:
333+
lit_config.fatal("Unsupported apple platform '{}'".format(platform))
334+
335+
return (major, minor)
336+
337+
for vers in min_macos_deployment_target_substitutions:
338+
flag = config.apple_platform_min_deployment_target_flag
339+
major, minor = get_macos_aligned_version(vers)
340+
config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '{}={}.{}'.format(flag, major, minor)) )
364341
else:
365-
for substitution in darwin_min_deployment_target_substitutions.keys():
366-
config.substitutions.append( (substitution, "") )
342+
for vers in min_macos_deployment_target_substitutions:
343+
config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '') )
367344

368345
if config.android:
369346
env = os.environ.copy()

0 commit comments

Comments
 (0)