Skip to content

Commit 9c54eb6

Browse files
committed
[Macros] Small review changes
* New struct to store a pair of plugin search path and the server path * typo
1 parent 54884f0 commit 9c54eb6

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

include/swift/AST/ASTContext.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,15 @@ class ASTContext final {
14681468
Type getNamedSwiftType(ModuleDecl *module, StringRef name);
14691469

14701470
/// Lookup an executable plugin that is declared to handle \p moduleName
1471-
/// module by '-load-plugin-executable'. Note that the returned path might be
1472-
/// in the current VFS. i.e. use FS.getRealPath() to get the real path.
1471+
/// module by '-load-plugin-executable'.
1472+
/// The path is valid within the VFS, use `FS.getRealPath()` for the
1473+
/// underlying path.
14731474
Optional<StringRef> lookupExecutablePluginByModuleName(Identifier moduleName);
14741475

1475-
/// From paths '-external-plugin-path', look for dylib file that has
1476-
/// 'lib${moduleName}.dylib' (or equialent depending on the platform) and
1477-
/// return the found dylib path and the path to the "plugin server" for that.
1478-
/// Note that the returned path might be in the current VFS.
1476+
/// Look for dynamic libraries in paths from `-external-plugin-path` and
1477+
/// return a pair of `(library path, plugin server executable)` if found.
1478+
/// These paths are valid within the VFS, use `FS.getRealPath()` for their
1479+
/// underlying path.
14791480
Optional<std::pair<std::string, std::string>>
14801481
lookupExternalLibraryPluginByModuleName(Identifier moduleName);
14811482

include/swift/AST/SearchPathOptions.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ class ModuleSearchPathLookup {
174174
llvm::vfs::FileSystem *FS, bool IsOSDarwin);
175175
};
176176

177+
/// Pair of a plugin search path and the corresponding plugin server executable
178+
/// path.
179+
struct ExternalPluginSearchPathAndServerPath {
180+
std::string SearchPath;
181+
std::string ServerPath;
182+
};
183+
177184
/// Options for controlling search path behavior.
178185
class SearchPathOptions {
179186
/// To call \c addImportSearchPath and \c addFrameworkSearchPath from
@@ -382,10 +389,11 @@ class SearchPathOptions {
382389
/// macro implementations.
383390
std::vector<std::string> PluginSearchPaths;
384391

385-
/// Paths that contain compiler plugins and the path to the plugin server
386-
/// executable.
387-
/// e.g. '/path/to/usr/lib/swift/host/plugins#/path/to/usr/bin/plugin-server'.
388-
std::vector<std::string> ExternalPluginSearchPaths;
392+
/// Pairs of external compiler plugin search paths and the corresponding
393+
/// plugin server executables.
394+
/// e.g. {"/path/to/usr/lib/swift/host/plugins",
395+
/// "/path/to/usr/bin/plugin-server"}
396+
std::vector<ExternalPluginSearchPathAndServerPath> ExternalPluginSearchPaths;
389397

390398
/// Don't look in for compiler-provided modules.
391399
bool SkipRuntimeLibraryImportPaths = false;

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,7 @@ class LoadedCompilerPlugin {
40254025
}
40264026

40274027
void *getAsInProcessPlugin() const {
4028-
return kind == PluginKind::InProcess ? static_cast<void *>(ptr) : nullptr;
4028+
return kind == PluginKind::InProcess ? ptr : nullptr;
40294029
}
40304030
LoadedExecutablePlugin *getAsExecutablePlugin() const {
40314031
return kind == PluginKind::Executable

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6358,15 +6358,11 @@ Optional<std::pair<std::string, std::string>>
63586358
ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) {
63596359
auto fs = this->SourceMgr.getFileSystem();
63606360
for (auto &pair : SearchPathOpts.ExternalPluginSearchPaths) {
6361-
StringRef searchPath;
6362-
StringRef serverPath;
6363-
std::tie(searchPath, serverPath) = StringRef(pair).split('#');
6364-
6365-
SmallString<128> fullPath(searchPath);
6361+
SmallString<128> fullPath(pair.SearchPath);
63666362
llvm::sys::path::append(fullPath, "lib" + moduleName.str() + LTDL_SHLIB_EXT);
63676363

63686364
if (fs->exists(fullPath)) {
6369-
return {{std::string(fullPath), serverPath.str()}};
6365+
return {{std::string(fullPath), pair.ServerPath}};
63706366
}
63716367
}
63726368
return None;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,12 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
14941494

14951495
for (const Arg *A : Args.filtered(OPT_external_plugin_path)) {
14961496
// '<plugin directory>#<plugin server executable path>'.
1497+
// FIXME: '#' can be used in the paths.
14971498
StringRef dylibPath;
14981499
StringRef serverPath;
14991500
std::tie(dylibPath, serverPath) = StringRef(A->getValue()).split('#');
1500-
Opts.ExternalPluginSearchPaths.push_back(
1501-
resolveSearchPath(dylibPath) + "#" + resolveSearchPath(serverPath));
1501+
Opts.ExternalPluginSearchPaths.emplace_back(
1502+
resolveSearchPath(dylibPath), resolveSearchPath(serverPath));
15021503
}
15031504

15041505
for (const Arg *A : Args.filtered(OPT_L)) {

tools/swift-plugin-server/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (SWIFT_SWIFT_PARSER)
2-
# _swiftCSwiftPluginServer is just a C support library for wift-plugin-server
2+
# _swiftCSwiftPluginServer is just a C support library for swift-plugin-server
33
# Don't bother to create '.a' for that.
44
add_swift_host_library(_swiftCSwiftPluginServer OBJECT
55
Sources/CSwiftPluginServer/PluginServer.cpp

0 commit comments

Comments
 (0)