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.
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
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
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: " +
}
}
- 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",
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;
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()) {
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()));
}
// 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()));
#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;