Skip to content

Commit 59b1687

Browse files
authored
Merge pull request #6736 from compnerd/sdkroot
Host: introduce `GetSDKPath` extension point for Windows
2 parents 3aa4d0c + b22393f commit 59b1687

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lldb/include/lldb/Host/windows/HostInfoWindows.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ class HostInfoWindows : public HostInfoBase {
3232
static bool GetHostname(std::string &s);
3333
static FileSpec GetProgramFileSpec();
3434
static FileSpec GetDefaultShell();
35+
36+
static bool GetEnvironmentVar(const std::string &var_name, std::string &var);
37+
3538
#ifdef LLDB_ENABLE_SWIFT
3639
static FileSpec GetSwiftResourceDir();
3740
static std::string GetSwiftResourceDir(llvm::Triple triple,
3841
llvm::StringRef platform_sdk_path);
3942
static bool ComputeSwiftResourceDirectory(FileSpec &lldb_shlib_spec,
4043
FileSpec &file_spec, bool verify);
44+
static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options);
4145
#endif
4246

43-
static bool GetEnvironmentVar(const std::string &var_name, std::string &var);
44-
4547
private:
4648
static FileSpec m_program_filespec;
4749
};

lldb/source/Host/windows/HostInfoWindowsSwift.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "lldb/Utility/FileSpec.h"
1414
#include "lldb/Utility/LLDBLog.h"
1515
#include "lldb/Utility/Log.h"
16+
#include <llvm/Support/ConvertUTF.h>
1617

1718
#include <string>
1819

@@ -43,3 +44,13 @@ HostInfoWindows::GetSwiftResourceDir(llvm::Triple triple,
4344
llvm::StringRef platform_sdk_path) {
4445
return GetSwiftResourceDir().GetPath();
4546
}
47+
48+
llvm::Expected<llvm::StringRef> HostInfoWindows::GetSDKRoot(SDKOptions options) {
49+
std::string buffer;
50+
if (wchar_t *path = _wgetenv(L"SDKROOT"))
51+
if (llvm::convertUTF16ToUTF8String(
52+
llvm::ArrayRef{reinterpret_cast<llvm::UTF16 *>(path), wcslen(path)},
53+
buffer))
54+
return buffer;
55+
return llvm::make_error<HostInfoError>("`SDKROOT` is unset");
56+
}

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,16 +1419,16 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
14191419
static std::string GetSDKPath(std::string m_description, XcodeSDK sdk) {
14201420
auto sdk_path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
14211421
if (!sdk_path_or_err) {
1422-
Debugger::ReportError("Error while searching for Xcode SDK: " +
1422+
Debugger::ReportError("Error while searching for SDK: " +
14231423
toString(sdk_path_or_err.takeError()));
1424-
HEALTH_LOG_PRINTF("Error while searching for Xcode SDK %s.",
1424+
HEALTH_LOG_PRINTF("Error while searching for SDK (XcodeSDK: %s)",
14251425
sdk.GetString().str().c_str());
14261426
return {};
14271427
}
14281428

14291429
std::string sdk_path = sdk_path_or_err->str();
1430-
LOG_PRINTF(GetLog(LLDBLog::Types), "Host SDK path for sdk %s is %s.",
1431-
sdk.GetString().str().c_str(), sdk_path.c_str());
1430+
LOG_PRINTF(GetLog(LLDBLog::Types), "Host SDK path: `%s` (XcodeSDK: %s)",
1431+
sdk_path.c_str(), sdk.GetString().str().c_str());
14321432
return sdk_path;
14331433
}
14341434

0 commit comments

Comments
 (0)