[PATCH] D70152: [Darwin] Add lit features for comparison against target OS version.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 17:40:21 PST 2019


delcypher created this revision.
delcypher added reviewers: yln, kubamracek.
Herald added projects: Sanitizers, LLVM.
Herald added a subscriber: Sanitizers.
delcypher added a parent revision: D70151: Add `%match_min_os_deployment_version_to_target` lit substitution..

The patch adds lit features that can be used to make tests
only supported if the target OS is new enough. Example:

  REQUIRES: apple_osx_geq_10_15_0 || apple_ios_geq_13_0_0 || \
            apple_watchos_geq_6_0_0 || apple_tvos_geq_13_0_0

Or if the target OS is sufficiently old. Example:

  REQUIRES: apple_osx_lt_10_15_0 || apple_ios_lt_13_0_0 || \
            apple_watchos_lt_6_0_0 || apple_tvos_lt_13_0_0

The implementation includes greater-than (`gt`) and less-than-or-equal-to
(`leq) feature variants too for completeness.

This implementation does not add features exhaustively.  Instead the
implementation requires specific (i.e. important) OS versions to be
explicitly stated.  This patch just adds macOS 10.15.0 and the aligned
OS versions. We can easily add other OS versions in the future if they
become important.

rdar://problem/57127970


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70152

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


Index: compiler-rt/test/lit.common.cfg.py
===================================================================
--- compiler-rt/test/lit.common.cfg.py
+++ compiler-rt/test/lit.common.cfg.py
@@ -325,6 +325,69 @@
     ))
   )
 
+  # Create features comparing the target OS against those listed below.
+  # Versions listed here can in the following forms:
+  #
+  # 1) (<major>, <minor>)
+  # 2) (<major>, <minor>, <patch>)
+  #
+  # NOTE: For form 1) `<patch>` is inferred to be `0`.
+  os_versions_to_compare_with = {
+    'osx': [
+      (10,15)
+    ],
+    'ios': [
+      (13,0)
+    ],
+    'watchos': [
+      (6,0)
+    ],
+    'tvos': [
+      (13,0)
+    ]
+  }
+  canonical_platform_name = config.apple_platform
+  if canonical_platform_name.endswith('sim'):
+    canonical_platform_name = canonical_platform_name[:-3]
+  if canonical_platform_name in os_versions_to_compare_with:
+    for version_tuple in os_versions_to_compare_with[canonical_platform_name]:
+      version_triplet = version_tuple
+      if len(version_triplet) == 2:
+        version_triplet = (version_tuple[0], version_tuple[1], 0)
+      assert len(version_triplet) == 3
+      # >= feature
+      if apple_target_os_tuple >= version_triplet:
+        geq_feature = 'apple_{platform}_geq_{major}_{minor}_{patch}'.format(
+            platform=canonical_platform_name,
+            major=version_triplet[0],
+            minor=version_triplet[1],
+            patch=version_triplet[2])
+        config.available_features.add(geq_feature)
+      # > feature
+      if apple_target_os_tuple > version_triplet:
+        gt_feature = 'apple_{platform}_gt_{major}_{minor}_{patch}'.format(
+            platform=canonical_platform_name,
+            major=version_triplet[0],
+            minor=version_triplet[1],
+            patch=version_triplet[2])
+        config.available_features.add(gt_feature)
+      # <= feature
+      if apple_target_os_tuple <= version_triplet:
+        geq_feature = 'apple_{platform}_leq_{major}_{minor}_{patch}'.format(
+            platform=canonical_platform_name,
+            major=version_triplet[0],
+            minor=version_triplet[1],
+            patch=version_triplet[2])
+        config.available_features.add(geq_feature)
+      # < feature
+      if apple_target_os_tuple < version_triplet:
+        geq_feature = 'apple_{platform}_lt_{major}_{minor}_{patch}'.format(
+            platform=canonical_platform_name,
+            major=version_triplet[0],
+            minor=version_triplet[1],
+            patch=version_triplet[2])
+        config.available_features.add(geq_feature)
+
   # Detect x86_64h
   try:
     output = subprocess.check_output(["sysctl", "hw.cpusubtype"])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70152.228986.patch
Type: text/x-patch
Size: 2704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191113/0f1531cc/attachment.bin>


More information about the llvm-commits mailing list