Author: Saleem Abdulrasool Date: 2023-04-28T09:30:59-07:00 New Revision: ade3c6a6a88ed3a9b06c076406f196da9d3cc1b9
URL: https://github.com/llvm/llvm-project/commit/ade3c6a6a88ed3a9b06c076406f196da9d3cc1b9 DIFF: https://github.com/llvm/llvm-project/commit/ade3c6a6a88ed3a9b06c076406f196da9d3cc1b9.diff LOG: Host: generalise `GetXcodeSDKPath` This generalises the GetXcodeSDKPath hook to a GetSDKRoot path which will be re-used for the Windows support to compute a language specific SDK path on the platform. Because there may be other options that we wish to use to compute the SDK path, sink the XcodeSDK parameter into a structure which can pass a disaggregated set of options. Furthermore, optionalise the parameter as Xcode is not available for all platforms. Differential Revision: https://reviews.llvm.org/D149397 Reviewed By: JDevlieghere Added: Modified: lldb/include/lldb/Host/HostInfoBase.h lldb/include/lldb/Host/macosx/HostInfoMacOSX.h lldb/source/Core/Module.cpp lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp lldb/unittests/Host/HostInfoTest.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h index 42f71d91f9bf9..28f809398d5b4 100644 --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -31,6 +31,23 @@ struct SharedCacheImageInfo { lldb::DataBufferSP data_sp; }; +namespace { +struct HostInfoError : public llvm::ErrorInfo<HostInfoError> { + static char ID; + const std::string message_; + + HostInfoError(const std::string message) : message_(std::move(message)) {} + + void log(llvm::raw_ostream &OS) const override { OS << "HostInfoError"; } + + std::error_code convertToErrorCode() const override { + return llvm::inconvertibleErrorCode(); + } +}; + +char HostInfoError::ID = 0; +} // namespace + class HostInfoBase { private: // Static class, unconstructable. @@ -108,10 +125,14 @@ class HostInfoBase { static FileSpec GetXcodeContentsDirectory() { return {}; } static FileSpec GetXcodeDeveloperDirectory() { return {}; } - - /// Return the directory containing a specific Xcode SDK. - static llvm::Expected<llvm::StringRef> GetXcodeSDKPath(XcodeSDK sdk) { - return ""; + + struct SDKOptions { + std::optional<XcodeSDK> XcodeSDK; + }; + + /// Return the directory containing something like a SDK (reused for Swift). + static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) { + return llvm::make_error<HostInfoError>("cannot determine SDK root"); } /// Return information about module \p image_name if it is loaded in diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h index 0402509cfa261..74d979d965a73 100644 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -31,7 +31,7 @@ class HostInfoMacOSX : public HostInfoPosix { static FileSpec GetXcodeDeveloperDirectory(); /// Query xcrun to find an Xcode SDK directory. - static llvm::Expected<llvm::StringRef> GetXcodeSDKPath(XcodeSDK sdk); + static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options); /// Shared cache utilities static SharedCacheImageInfo diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 17d8043852ab7..6293cc7853f53 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1607,8 +1607,8 @@ std::optional<std::string> Module::RemapSourceFile(llvm::StringRef path) const { void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) { - XcodeSDK sdk(sdk_name.str()); - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(sdk); + auto sdk_path_or_err = + HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index 5a39ed370747a..6569013044513 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -338,7 +338,8 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) { } } - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()); + auto sdk_path_or_err = + HostInfo::GetSDKRoot(SDKOptions{XcodeSDK::GetAnyMacOS()}); if (!sdk_path_or_err) { Log *log = GetLog(LLDBLog::Host); LLDB_LOGF(log, "Error while searching for Xcode SDK: %s", @@ -519,7 +520,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) { return path; } -llvm::Expected<llvm::StringRef> HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) { +llvm::Expected<llvm::StringRef> HostInfoMacOSX::GetSDKRoot(SDKOptions options) { struct ErrorOrPath { std::string str; bool is_error; @@ -530,6 +531,11 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) { std::lock_guard<std::mutex> guard(g_sdk_path_mutex); LLDB_SCOPED_TIMER(); + if (!options.XcodeSDK) + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "XCodeSDK not specified"); + XcodeSDK sdk = *options.XcodeSDK; + auto key = sdk.GetString(); auto it = g_sdk_path.find(key); if (it != g_sdk_path.end()) { diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp index 7501f3edd24ff..7044426e17b50 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -284,7 +284,8 @@ static llvm::StringRef GetXcodeSDKDir(std::string preferred, std::string secondary) { llvm::StringRef sdk; auto get_sdk = [&](std::string sdk) -> llvm::StringRef { - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(sdk))); + auto sdk_path_or_err = + HostInfo::GetSDKRoot(HostInfo::SDKOptions{XcodeSDK(std::move(sdk))}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + toString(sdk_path_or_err.takeError())); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp index 25b821d12a314..ba412da62e57b 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -124,7 +124,8 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) { } // Use the default SDK as a fallback. - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()); + auto sdk_path_or_err = + HostInfo::GetSDKRoot(HostInfo::SDKOptions{XcodeSDK::GetAnyMacOS()}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + toString(sdk_path_or_err.takeError())); diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp index b6c8edd74154f..322675c7f485a 100644 --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -57,7 +57,8 @@ TEST_F(HostInfoTest, GetHostname) { #if defined(__APPLE__) TEST_F(HostInfoTest, GetXcodeSDK) { auto get_sdk = [](std::string sdk, bool error = false) -> llvm::StringRef { - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(sdk))); + auto sdk_path_or_err = + HostInfo::GetSDKRoot(HostInfo::SDKOptions{XcodeSDK(std::move(sdk))}); if (!error) { EXPECT_TRUE((bool)sdk_path_or_err); return *sdk_path_or_err; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits