Skip to content

Commit 1dbd3c4

Browse files
Merge pull request #7242 from adrian-prantl/112122752-5.9
Prepopulate the CompilerInvocation with the host plugin search path.
2 parents 71b6f8f + ff16a8d commit 1dbd3c4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,10 @@ SwiftASTContextForModule::~SwiftASTContextForModule() {
10321032

10331033
/// This code comes from CompilerInvocation.cpp (setRuntimeResourcePath).
10341034
static void ConfigureResourceDirs(swift::CompilerInvocation &invocation,
1035-
FileSpec resource_dir, llvm::Triple triple) {
1035+
StringRef resource_dir, llvm::Triple triple) {
10361036
// Make sure the triple is right:
10371037
invocation.setTargetTriple(triple.str());
1038-
invocation.setRuntimeResourcePath(resource_dir.GetPath().c_str());
1038+
invocation.setRuntimeResourcePath(resource_dir);
10391039
}
10401040

10411041
static const char *getImportFailureString(swift::serialization::Status status) {
@@ -1930,8 +1930,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
19301930

19311931
std::string resource_dir =
19321932
HostInfo::GetSwiftResourceDir(triple, swift_ast_sp->GetPlatformSDKPath());
1933-
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(),
1934-
FileSpec(resource_dir), triple);
1933+
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(), resource_dir,
1934+
triple);
19351935

19361936
// Apply the working directory to all relative paths.
19371937
std::vector<std::string> DeserializedArgs = swift_ast_sp->GetClangArguments();
@@ -2390,8 +2390,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23902390
llvm::Triple triple = swift_ast_sp->GetTriple();
23912391
std::string resource_dir = HostInfo::GetSwiftResourceDir(
23922392
triple, swift_ast_sp->GetPlatformSDKPath());
2393-
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(),
2394-
FileSpec(resource_dir), triple);
2393+
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(), resource_dir,
2394+
triple);
23952395
const bool discover_implicit_search_paths =
23962396
target.GetSwiftDiscoverImplicitSearchPaths();
23972397

@@ -2813,8 +2813,7 @@ void SwiftASTContext::InitializeSearchPathOptions(
28132813
llvm::Triple triple(GetTriple());
28142814
std::string resource_dir =
28152815
HostInfo::GetSwiftResourceDir(triple, GetPlatformSDKPath());
2816-
ConfigureResourceDirs(GetCompilerInvocation(), FileSpec(resource_dir),
2817-
triple);
2816+
ConfigureResourceDirs(GetCompilerInvocation(), resource_dir, triple);
28182817

28192818
std::string sdk_path = GetPlatformSDKPath().str();
28202819
if (TargetSP target_sp = GetTargetWP().lock())
@@ -2855,6 +2854,20 @@ void SwiftASTContext::InitializeSearchPathOptions(
28552854
lpaths.insert(lpaths.begin(), "/usr/lib/swift");
28562855
}
28572856

2857+
// Set the default host plugin paths.
2858+
llvm::SmallString<256> plugin_path;
2859+
llvm::sys::path::append(plugin_path, resource_dir, "host", "plugins");
2860+
if (!FileSystem::Instance().Exists(plugin_path)) {
2861+
LOG_PRINTF(GetLog(LLDBLog::Types), "Host plugin path %s does not exist",
2862+
plugin_path.str().str().c_str());
2863+
} else {
2864+
std::string server = SwiftASTContext::GetPluginServer(plugin_path);
2865+
if (!server.empty() && FileSystem::Instance().Exists(server))
2866+
invocation.getSearchPathOptions().PluginSearchOpts.emplace_back(
2867+
swift::PluginSearchOption::ExternalPluginPath{plugin_path.str().str(),
2868+
server});
2869+
}
2870+
28582871
llvm::StringMap<bool> processed;
28592872
std::vector<std::string> invocation_import_paths(
28602873
invocation.getSearchPathOptions().getImportSearchPaths());

0 commit comments

Comments
 (0)