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

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 16:23:20 PDT 2020


Author: Julian Lettner
Date: 2020-08-20T16:22:56-07:00
New Revision: 1f3c92f968edb8892ca7c152ca756f771a7f476d

URL: https://github.com/llvm/llvm-project/commit/1f3c92f968edb8892ca7c152ca756f771a7f476d
DIFF: https://github.com/llvm/llvm-project/commit/1f3c92f968edb8892ca7c152ca756f771a7f476d.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/test/asan/TestCases/initialization-bug.cpp
    compiler-rt/test/lit.common.cfg.py

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/asan/TestCases/initialization-bug.cpp b/compiler-rt/test/asan/TestCases/initialization-bug.cpp
index bcf0715c3e08..54adb3450eb9 100644
--- a/compiler-rt/test/asan/TestCases/initialization-bug.cpp
+++ b/compiler-rt/test/asan/TestCases/initialization-bug.cpp
@@ -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.

diff  --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 53b0a47f11a9..e72794d4534f 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -264,52 +264,14 @@
 
 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 @@ def get_apple_platform_version_aligned_with(macos_version, apple_platform):
   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()


        


More information about the llvm-commits mailing list