aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2020-05-06 18:02:44 -0700
committerAdrian Prantl <aprantl@apple.com>2020-05-07 11:29:31 -0700
commitdec1c94e801f6fe1bae01c4679aca67abe0cb8a6 (patch)
tree214b7ac09c8b9149f4b3bf95b75f4faea02df8ab
parent8c0ff17c3bb44edf455a2964e6035f28be68c9f3 (diff)
downloadllvm-dec1c94e801f6fe1bae01c4679aca67abe0cb8a6.zip
llvm-dec1c94e801f6fe1bae01c4679aca67abe0cb8a6.tar.gz
llvm-dec1c94e801f6fe1bae01c4679aca67abe0cb8a6.tar.bz2
Add a function to detect whether an Xcode SDK supports Swift
Differential Revision: https://reviews.llvm.org/D79535
-rw-r--r--lldb/include/lldb/Utility/XcodeSDK.h3
-rw-r--r--lldb/source/Utility/XcodeSDK.cpp21
-rw-r--r--lldb/unittests/Utility/XcodeSDKTest.cpp11
3 files changed, 35 insertions, 0 deletions
diff --git a/lldb/include/lldb/Utility/XcodeSDK.h b/lldb/include/lldb/Utility/XcodeSDK.h
index e5a0e03..94a9728 100644
--- a/lldb/include/lldb/Utility/XcodeSDK.h
+++ b/lldb/include/lldb/Utility/XcodeSDK.h
@@ -71,7 +71,10 @@ public:
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.
diff --git a/lldb/source/Utility/XcodeSDK.cpp b/lldb/source/Utility/XcodeSDK.cpp
index c6f2dda0..0d9f98f 100644
--- a/lldb/source/Utility/XcodeSDK.cpp
+++ b/lldb/source/Utility/XcodeSDK.cpp
@@ -181,6 +181,27 @@ bool XcodeSDK::SDKSupportsModules(XcodeSDK::Type sdk_type,
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 Type::AppleTVSimulator:
+ case Type::AppleTVOS:
+ return info.version.empty() || info.version >= llvm::VersionTuple(9);
+ case Type::WatchSimulator:
+ case Type::watchOS:
+ return info.version.empty() || info.version >= llvm::VersionTuple(2);
+ case 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();
diff --git a/lldb/unittests/Utility/XcodeSDKTest.cpp b/lldb/unittests/Utility/XcodeSDKTest.cpp
index e89eac2e..d991719 100644
--- a/lldb/unittests/Utility/XcodeSDKTest.cpp
+++ b/lldb/unittests/Utility/XcodeSDKTest.cpp
@@ -86,6 +86,17 @@ TEST(XcodeSDKTest, SDKSupportsModules) {
}
#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;