Index: lldb/include/lldb/Utility/XcodeSDK.h =================================================================== --- lldb/include/lldb/Utility/XcodeSDK.h +++ lldb/include/lldb/Utility/XcodeSDK.h @@ -50,7 +50,8 @@ bool operator==(XcodeSDK other); /// Return parsed SDK number, and SDK version number. - std::tuple Parse() const; + std::tuple Parse() const; + bool IsAppleInternalSDK() const; llvm::VersionTuple GetVersion() const; Type GetType() const; llvm::StringRef GetString() const; Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm =================================================================== --- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -298,8 +298,9 @@ } std::string HostInfoMacOSX::GetXcodeSDK(XcodeSDK sdk) { - std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + - XcodeSDK::GetSDKNameForType(sdk.GetType()).str(); + auto sdk_tuple = sdk.Parse(); + auto sdk_name = XcodeSDK::GetSDKNameForType(std::get<0>(sdk_tuple)); + std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + sdk_name.str(); llvm::VersionTuple version = sdk.GetVersion(); if (!version.empty()) xcrun_cmd += version.getAsString(); @@ -327,6 +328,17 @@ if (last_newline != llvm::StringRef::npos) output = output.substr(last_newline + 1); + bool internal = std::get<2>(sdk_tuple); + if (internal) { + // xcrun doesn't support searching for an internal SDK with a version. + if (output.endswith(".sdk")) { + std::string internal_sdk = + output.drop_back(4).str() + std::string(".Internal.sdk"); + if (FileSystem::Instance().Exists(internal_sdk)) + return internal_sdk; + } + } + // Whatever is left in output should be a valid path. if (!FileSystem::Instance().Exists(output)) return {}; Index: lldb/source/Utility/XcodeSDK.cpp =================================================================== --- lldb/source/Utility/XcodeSDK.cpp +++ lldb/source/Utility/XcodeSDK.cpp @@ -64,13 +64,24 @@ return version; } +static bool ParseAppleInternalSDK(llvm::StringRef &name) { + return name.consume_front("Internal."); +} -std::tuple XcodeSDK::Parse() const { +std::tuple XcodeSDK::Parse() const { llvm::StringRef input(m_name); XcodeSDK::Type sdk = ParseSDKName(input); llvm::VersionTuple version = ParseSDKVersion(input); + bool internal = ParseAppleInternalSDK(input); return std::make_tuple( - std::move(sdk), std::move(version)); + std::move(sdk), std::move(version), internal); +} + +bool XcodeSDK::IsAppleInternalSDK() const { + llvm::StringRef input(m_name); + ParseSDKName(input); + ParseSDKVersion(input); + return ParseAppleInternalSDK(input); } llvm::VersionTuple XcodeSDK::GetVersion() const { @@ -88,8 +99,17 @@ void XcodeSDK::Merge(XcodeSDK other) { // The "bigger" SDK always wins. - if (Parse() < other.Parse()) + auto l = Parse(); + auto r = other.Parse(); + if (l < r) *this = other; + else { + // The Internal flag always wins. + if (llvm::StringRef(m_name).endswith(".sdk")) + if (!std::get<2>(l) && std::get<2>(r)) + m_name = + m_name.substr(0, m_name.size() - 3) + std::string("Internal.sdk"); + } } llvm::StringRef XcodeSDK::GetSDKNameForType(XcodeSDK::Type type) { @@ -153,6 +173,7 @@ auto version_part = sdk_name.drop_front(sdk_string.size()); version_part.consume_back(".sdk"); + version_part.consume_back(".Internal"); llvm::VersionTuple version; if (version.tryParse(version_part)) Index: lldb/unittests/Utility/XcodeSDKTest.cpp =================================================================== --- lldb/unittests/Utility/XcodeSDKTest.cpp +++ lldb/unittests/Utility/XcodeSDKTest.cpp @@ -30,6 +30,10 @@ EXPECT_EQ(XcodeSDK("MacOSX.sdk").GetVersion(), llvm::VersionTuple()); EXPECT_EQ(XcodeSDK("MacOSX10.9.sdk").GetVersion(), llvm::VersionTuple(10, 9)); EXPECT_EQ(XcodeSDK("MacOSX10.15.4.sdk").GetVersion(), llvm::VersionTuple(10, 15)); + EXPECT_EQ(XcodeSDK("MacOSX.sdk").IsAppleInternalSDK(), false); + EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetType(), XcodeSDK::MacOSX); + EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetVersion(), llvm::VersionTuple(10, 15)); + EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").IsAppleInternalSDK(), true); EXPECT_EQ(XcodeSDK().GetType(), XcodeSDK::unknown); EXPECT_EQ(XcodeSDK().GetVersion(), llvm::VersionTuple()); } @@ -46,6 +50,12 @@ EXPECT_EQ(sdk.GetVersion(), llvm::VersionTuple(1, 1)); sdk.Merge(XcodeSDK("WatchOS2.0.sdk")); EXPECT_EQ(sdk.GetVersion(), llvm::VersionTuple(2, 0)); + sdk.Merge(XcodeSDK("WatchOS1.1.Internal.sdk")); + EXPECT_EQ(sdk.GetVersion(), llvm::VersionTuple(2, 0)); + EXPECT_EQ(sdk.IsAppleInternalSDK(), true); + XcodeSDK empty; + empty.Merge(XcodeSDK("MacOSX10.14.Internal.sdk")); + EXPECT_EQ(empty.GetString(), llvm::StringRef("MacOSX10.14.Internal.sdk")); } TEST(XcodeSDKTest, SDKSupportsModules) { @@ -55,6 +65,10 @@ FileSpec( base + "iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.0.sdk"))); + EXPECT_TRUE(XcodeSDK::SDKSupportsModules( + XcodeSDK::Type::iPhoneSimulator, + FileSpec(base + "iPhoneSimulator.platform/Developer/SDKs/" + "iPhoneSimulator12.0.Internal.sdk"))); EXPECT_FALSE(XcodeSDK::SDKSupportsModules( XcodeSDK::Type::iPhoneSimulator, FileSpec(