Skip to content

Commit 8250a14

Browse files
Merge pull request #7097 from adrian-prantl/112122752-5.9
Support Swift plugin server paths without plugin names.
2 parents 53b62ee + 61fcce8 commit 8250a14

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,15 @@ void SwiftASTContext::DiagnoseWarnings(Process &process, Module &module) const {
11271127
/// by converting ${toolchain}/usr/(local)?/lib/swift/host/plugins
11281128
/// into ${toolchain}/usr/bin/swift-plugin-server
11291129
/// FIXME: move this to Host, it may be platform-specific.
1130-
static std::string GetPluginServer(llvm::StringRef plugin_library_path) {
1131-
llvm::StringRef path = llvm::sys::path::parent_path(plugin_library_path);
1132-
if (llvm::sys::path::filename(path) != "plugins")
1133-
return {};
1130+
std::string
1131+
SwiftASTContext::GetPluginServer(llvm::StringRef plugin_library_path) {
1132+
llvm::StringRef path = plugin_library_path;
1133+
if (llvm::sys::path::filename(path) != "plugins") {
1134+
// Strip off a plugin name.
1135+
path = llvm::sys::path::parent_path(plugin_library_path);
1136+
if (llvm::sys::path::filename(path) != "plugins")
1137+
return {};
1138+
}
11341139
path = llvm::sys::path::parent_path(path);
11351140
if (llvm::sys::path::filename(path) != "host")
11361141
return {};
@@ -1145,10 +1150,7 @@ static std::string GetPluginServer(llvm::StringRef plugin_library_path) {
11451150
path = llvm::sys::path::parent_path(path);
11461151
llvm::SmallString<256> server(path);
11471152
llvm::sys::path::append(server, "bin", "swift-plugin-server");
1148-
std::string result(server);
1149-
if (FileSystem::Instance().Exists(result))
1150-
return result;
1151-
return {};
1153+
return std::string(server);
11521154
}
11531155

11541156
static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
@@ -1325,8 +1327,12 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13251327
// Rewrite them to go through an ABI-compatible swift-plugin-server.
13261328
if (known_plugin_search_paths.insert(path).second) {
13271329
if (known_external_plugin_search_paths.insert(path).second) {
1328-
std::string server = get_plugin_server(
1329-
path, [&]() { return GetPluginServer(path); });
1330+
std::string server = get_plugin_server(path, [&]() {
1331+
std::string server = SwiftASTContext::GetPluginServer(path);
1332+
if (!server.empty() && !FileSystem::Instance().Exists(server))
1333+
server.clear();
1334+
return server;
1335+
});
13301336
if (server.empty())
13311337
continue;
13321338
if (exists(path))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class SwiftASTContext : public TypeSystemSwift {
261261
void AddExtraClangArgs(const std::vector<std::string> &ExtraArgs);
262262
static void AddExtraClangArgs(const std::vector<std::string>& source,
263263
std::vector<std::string>& dest);
264+
static std::string GetPluginServer(llvm::StringRef plugin_library_path);
264265

265266
/// Add the target's swift-extra-clang-flags to the ClangImporter options.
266267
void AddUserClangArgs(TargetProperties &props);

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
167167
EXPECT_EQ(dot_dot_path, llvm::SmallString<128>("-iquote."));
168168
}
169169

170+
TEST_F(TestSwiftASTContext, PluginPath) {
171+
llvm::StringRef path(
172+
"/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/"
173+
"lib/swift/host/plugins/libFoo.dylib");
174+
llvm::StringRef local_path(
175+
"/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/"
176+
"local/lib/swift/host/plugins/libFoo.dylib");
177+
std::string server("/Xcode.app/Contents/Developer/Toolchains/"
178+
"XcodeDefault.xctoolchain/usr/bin/swift-plugin-server");
179+
EXPECT_EQ(SwiftASTContext::GetPluginServer(path), server);
180+
EXPECT_EQ(
181+
SwiftASTContext::GetPluginServer(llvm::sys::path::parent_path(path)),
182+
server);
183+
EXPECT_EQ(SwiftASTContext::GetPluginServer(local_path), server);
184+
EXPECT_EQ(
185+
SwiftASTContext::GetPluginServer(llvm::sys::path::parent_path(local_path)),
186+
server);
187+
}
188+
170189
namespace {
171190
const std::vector<std::string> duplicated_flags = {
172191
"-DMACRO1",

0 commit comments

Comments
 (0)