[Lldb-commits] [PATCH] D79535: Add a function to detect whether an Xcode SDK supports Swift

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu May 7 11:20:25 PDT 2020


aprantl updated this revision to Diff 262699.
aprantl marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79535/new/

https://reviews.llvm.org/D79535

Files:
  lldb/include/lldb/Utility/XcodeSDK.h
  lldb/source/Utility/XcodeSDK.cpp
  lldb/unittests/Utility/XcodeSDKTest.cpp


Index: lldb/unittests/Utility/XcodeSDKTest.cpp
===================================================================
--- lldb/unittests/Utility/XcodeSDKTest.cpp
+++ lldb/unittests/Utility/XcodeSDKTest.cpp
@@ -85,6 +85,17 @@
 }
 #endif
 
+TEST(XcodeSDKTest, SDKSupportsSwift) {
+  EXPECT_TRUE(XcodeSDK("iPhoneSimulator12.0.sdk").SupportsSwift());
+  EXPECT_TRUE(XcodeSDK("iPhoneSimulator12.0.Internal.sdk").SupportsSwift());
+  EXPECT_FALSE(XcodeSDK("iPhoneSimulator7.2.sdk").SupportsSwift());
+  EXPECT_TRUE(XcodeSDK("MacOSX10.10.sdk").SupportsSwift());
+  EXPECT_FALSE(XcodeSDK("MacOSX10.9.sdk").SupportsSwift());
+  EXPECT_TRUE(XcodeSDK("Linux.sdk").SupportsSwift());
+  EXPECT_TRUE(XcodeSDK("MacOSX.sdk").SupportsSwift());
+  EXPECT_FALSE(XcodeSDK("EverythingElse.sdk").SupportsSwift());
+}
+
 TEST(XcodeSDKTest, GetCanonicalName) {
   XcodeSDK::Info info;
   info.type = XcodeSDK::Type::MacOSX;
Index: lldb/source/Utility/XcodeSDK.cpp
===================================================================
--- lldb/source/Utility/XcodeSDK.cpp
+++ lldb/source/Utility/XcodeSDK.cpp
@@ -178,6 +178,27 @@
   return false;
 }
 
+bool XcodeSDK::SupportsSwift() const {
+  XcodeSDK::Info info = Parse();
+  switch (info.type) {
+  case Type::MacOSX:
+    return info.version.empty() || info.version >= llvm::VersionTuple(10, 10);
+  case Type::iPhoneOS:
+  case Type::iPhoneSimulator:
+    return info.version.empty() || info.version >= llvm::VersionTuple(8);
+  case XcodeSDK::Type::AppleTVSimulator:
+  case XcodeSDK::Type::AppleTVOS:
+    return info.version.empty() || info.version >= llvm::VersionTuple(9);
+  case XcodeSDK::Type::WatchSimulator:
+  case XcodeSDK::Type::watchOS:
+    return info.version.empty() || info.version >= llvm::VersionTuple(2);
+  case XcodeSDK::Type::Linux:
+    return true;
+  default:
+    return false;
+  }
+}
+
 bool XcodeSDK::SDKSupportsModules(XcodeSDK::Type desired_type,
                                   const FileSpec &sdk_path) {
   ConstString last_path_component = sdk_path.GetLastPathComponent();
Index: lldb/include/lldb/Utility/XcodeSDK.h
===================================================================
--- lldb/include/lldb/Utility/XcodeSDK.h
+++ lldb/include/lldb/Utility/XcodeSDK.h
@@ -67,7 +67,10 @@
   llvm::VersionTuple GetVersion() const;
   Type GetType() const;
   llvm::StringRef GetString() const;
+  /// Whether this Xcode SDK supports Swift.
+  bool SupportsSwift() const;
 
+  /// Whether LLDB feels confident importing Clang modules from this SDK.
   static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
   static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
   /// Return the canonical SDK name, such as "macosx" for the macOS SDK.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79535.262699.patch
Type: text/x-patch
Size: 2739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200507/1ca834b1/attachment.bin>


More information about the lldb-commits mailing list