Skip to content

Commit

Permalink
Add a function to detect whether an Xcode SDK supports Swift
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D79535

(cherry picked from commit dec1c94)
  • Loading branch information
adrian-prantl committed May 7, 2020
1 parent 2faf071 commit 3b63c79
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lldb/include/lldb/Utility/XcodeSDK.h
Expand Up @@ -70,7 +70,10 @@ class XcodeSDK {
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.
Expand Down
21 changes: 21 additions & 0 deletions lldb/source/Utility/XcodeSDK.cpp
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions lldb/unittests/Utility/XcodeSDKTest.cpp
Expand Up @@ -84,6 +84,17 @@ TEST(XcodeSDKTest, SDKSupportsModules) {
FileSpec(base + "MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk")));
}

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;
Expand Down

0 comments on commit 3b63c79

Please sign in to comment.