Skip to content

Commit 45db9fb

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 45db9fb

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

include/swift/AST/SearchPathOptions.h

+12-4
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

+1-1
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

+2-6
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

+3-2
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

+1-1
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)