-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Plugin search options group #66650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
#include "swift/Basic/ArrayRefView.h" | ||
#include "swift/Basic/PathRemapper.h" | ||
#include "swift/Basic/TaggedUnion.h" | ||
#include "llvm/ADT/Hashing.h" | ||
#include "llvm/ADT/IntrusiveRefCntPtr.h" | ||
#include "llvm/ADT/StringMap.h" | ||
|
@@ -34,7 +35,6 @@ enum class ModuleSearchPathKind { | |
Framework, | ||
DarwinImplicitFramework, | ||
RuntimeLibrary, | ||
CompilerPlugin, | ||
}; | ||
|
||
/// A single module search path that can come from different sources, e.g. | ||
|
@@ -187,6 +187,26 @@ struct ExternalPluginSearchPathAndServerPath { | |
std::string ServerPath; | ||
}; | ||
|
||
namespace PluginSearchOption { | ||
struct LoadPluginLibrary { | ||
std::string LibraryPath; | ||
}; | ||
struct LoadPluginExecutable { | ||
std::string ExecutablePath; | ||
std::vector<std::string> ModuleNames; | ||
}; | ||
struct PluginPath { | ||
std::string SearchPath; | ||
}; | ||
struct ExternalPluginPath { | ||
std::string SearchPath; | ||
std::string ServerPath; | ||
}; | ||
|
||
using Value = TaggedUnion<LoadPluginLibrary, LoadPluginExecutable, PluginPath, | ||
ExternalPluginPath>; | ||
} // namespace PluginSearchOption | ||
|
||
/// Options for controlling search path behavior. | ||
class SearchPathOptions { | ||
/// To call \c addImportSearchPath and \c addFrameworkSearchPath from | ||
|
@@ -259,14 +279,6 @@ class SearchPathOptions { | |
ImportSearchPaths.size() - 1); | ||
} | ||
|
||
void addCompilerPluginLibraryPath(StringRef Path, llvm::vfs::FileSystem *FS) { | ||
CompilerPluginLibraryPaths.push_back(Path.str()); | ||
Lookup.searchPathAdded(FS, CompilerPluginLibraryPaths.back(), | ||
ModuleSearchPathKind::CompilerPlugin, | ||
/*isSystem=*/false, | ||
CompilerPluginLibraryPaths.size() - 1); | ||
} | ||
|
||
/// Add a single framework search path. Must only be called from | ||
/// \c ASTContext::addSearchPath. | ||
void addFrameworkSearchPath(FrameworkSearchPath NewPath, | ||
|
@@ -355,27 +367,6 @@ class SearchPathOptions { | |
Lookup.searchPathsDidChange(); | ||
} | ||
|
||
void setCompilerPluginLibraryPaths( | ||
std::vector<std::string> NewCompilerPluginLibraryPaths) { | ||
CompilerPluginLibraryPaths = NewCompilerPluginLibraryPaths; | ||
Lookup.searchPathsDidChange(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plugin search doesn't use |
||
} | ||
|
||
ArrayRef<std::string> getCompilerPluginLibraryPaths() const { | ||
return CompilerPluginLibraryPaths; | ||
} | ||
|
||
void setCompilerPluginExecutablePaths( | ||
std::vector<PluginExecutablePathAndModuleNames> &&newValue) { | ||
CompilerPluginExecutablePaths = std::move(newValue); | ||
Lookup.searchPathsDidChange(); | ||
} | ||
|
||
ArrayRef<PluginExecutablePathAndModuleNames> | ||
getCompilerPluginExecutablePaths() const { | ||
return CompilerPluginExecutablePaths; | ||
} | ||
|
||
/// Path(s) to virtual filesystem overlay YAML files. | ||
std::vector<std::string> VFSOverlayFiles; | ||
|
||
|
@@ -391,15 +382,8 @@ class SearchPathOptions { | |
/// preference. | ||
std::vector<std::string> RuntimeLibraryPaths; | ||
|
||
/// Paths that contain compiler plugins loaded on demand for, e.g., | ||
/// macro implementations. | ||
std::vector<std::string> PluginSearchPaths; | ||
|
||
/// Pairs of external compiler plugin search paths and the corresponding | ||
/// plugin server executables. | ||
/// e.g. {"/path/to/usr/lib/swift/host/plugins", | ||
/// "/path/to/usr/bin/plugin-server"} | ||
std::vector<ExternalPluginSearchPathAndServerPath> ExternalPluginSearchPaths; | ||
/// Plugin search path options. | ||
std::vector<PluginSearchOption::Value> PluginSearchOpts; | ||
|
||
/// Don't look in for compiler-provided modules. | ||
bool SkipRuntimeLibraryImportPaths = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,11 +103,10 @@ llvm::StringRef swift::getProtocolName(KnownProtocolKind kind) { | |
} | ||
|
||
namespace { | ||
enum class SearchPathKind : uint8_t { | ||
Import = 1 << 0, | ||
Framework = 1 << 1, | ||
CompilerPlugin = 1 << 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: |
||
}; | ||
enum class SearchPathKind : uint8_t { | ||
Import = 1 << 0, | ||
Framework = 1 << 1, | ||
}; | ||
} // end anonymous namespace | ||
|
||
using AssociativityCacheType = | ||
|
@@ -694,8 +693,6 @@ ASTContext::ASTContext( | |
getImpl().SearchPathsSet[path] |= SearchPathKind::Import; | ||
for (const auto &framepath : SearchPathOpts.getFrameworkSearchPaths()) | ||
getImpl().SearchPathsSet[framepath.Path] |= SearchPathKind::Framework; | ||
for (StringRef path : SearchPathOpts.getCompilerPluginLibraryPaths()) | ||
getImpl().SearchPathsSet[path] |= SearchPathKind::CompilerPlugin; | ||
|
||
// Register any request-evaluator functions available at the AST layer. | ||
registerAccessRequestFunctions(evaluator); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,14 @@ | |
using namespace swift; | ||
|
||
void PluginLoader::createModuleToExecutablePluginMap() { | ||
for (auto &arg : Ctx.SearchPathOpts.getCompilerPluginExecutablePaths()) { | ||
// Create a moduleName -> pluginPath mapping. | ||
assert(!arg.ExecutablePath.empty() && "empty plugin path"); | ||
StringRef pathStr = Ctx.AllocateCopy(arg.ExecutablePath); | ||
for (auto moduleName : arg.ModuleNames) { | ||
ExecutablePluginPaths[Ctx.getIdentifier(moduleName)] = pathStr; | ||
for (auto &elem : Ctx.SearchPathOpts.PluginSearchOpts) { | ||
if (auto *arg = elem.dyn_cast<PluginSearchOption::LoadPluginExecutable>()) { | ||
// Create a moduleName -> pluginPath mapping. | ||
assert(!arg->ExecutablePath.empty() && "empty plugin path"); | ||
StringRef pathStr = Ctx.AllocateCopy(arg->ExecutablePath); | ||
for (auto moduleName : arg->ModuleNames) { | ||
ExecutablePluginPaths[Ctx.getIdentifier(moduleName)] = pathStr; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -46,69 +48,59 @@ PluginRegistry *PluginLoader::getRegistry() { | |
return Registry; | ||
} | ||
|
||
llvm::Optional<std::string> | ||
PluginLoader::lookupExplicitLibraryPluginByModuleName(Identifier moduleName) { | ||
// Look for 'lib${module name}(.dylib|.so)'. | ||
SmallString<64> expectedBasename; | ||
expectedBasename.append("lib"); | ||
expectedBasename.append(moduleName.str()); | ||
expectedBasename.append(LTDL_SHLIB_EXT); | ||
|
||
// Try '-load-plugin-library'. | ||
for (const auto &libPath : | ||
Ctx.SearchPathOpts.getCompilerPluginLibraryPaths()) { | ||
if (llvm::sys::path::filename(libPath) == expectedBasename) { | ||
return libPath; | ||
} | ||
} | ||
return None; | ||
} | ||
std::pair<std::string, std::string> | ||
PluginLoader::lookupPluginByModuleName(Identifier moduleName) { | ||
auto fs = Ctx.SourceMgr.getFileSystem(); | ||
|
||
llvm::Optional<std::string> | ||
PluginLoader::lookupLibraryPluginInSearchPathByModuleName( | ||
Identifier moduleName) { | ||
// Look for 'lib${module name}(.dylib|.so)'. | ||
SmallString<64> expectedBasename; | ||
expectedBasename.append("lib"); | ||
expectedBasename.append(moduleName.str()); | ||
expectedBasename.append(LTDL_SHLIB_EXT); | ||
|
||
// Try '-plugin-path'. | ||
auto fs = Ctx.SourceMgr.getFileSystem(); | ||
for (const auto &searchPath : Ctx.SearchPathOpts.PluginSearchPaths) { | ||
SmallString<128> fullPath(searchPath); | ||
llvm::sys::path::append(fullPath, expectedBasename); | ||
if (fs->exists(fullPath)) { | ||
return std::string(fullPath); | ||
// FIXME: Shared library prefix might be different between platforms. | ||
SmallString<64> pluginLibBasename; | ||
pluginLibBasename.append("lib"); | ||
pluginLibBasename.append(moduleName.str()); | ||
pluginLibBasename.append(LTDL_SHLIB_EXT); | ||
|
||
// FIXME: Should we create a lookup table keyed by module name? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we create a lookup table for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to do the one scan rather than the continual |
||
for (auto &entry : Ctx.SearchPathOpts.PluginSearchOpts) { | ||
using namespace PluginSearchOption; | ||
// Try '-load-plugin-library'. | ||
if (auto *val = entry.dyn_cast<LoadPluginLibrary>()) { | ||
if (llvm::sys::path::filename(val->LibraryPath) == pluginLibBasename) { | ||
return {val->LibraryPath, ""}; | ||
} | ||
continue; | ||
} | ||
} | ||
|
||
return None; | ||
} | ||
|
||
Optional<std::pair<std::string, std::string>> | ||
PluginLoader::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { | ||
auto fs = Ctx.SourceMgr.getFileSystem(); | ||
// Try '-load-plugin-executable'. | ||
if (auto *v = entry.dyn_cast<LoadPluginExecutable>()) { | ||
auto found = ExecutablePluginPaths.find(moduleName); | ||
if (found != ExecutablePluginPaths.end()) { | ||
return {"", std::string(found->second)}; | ||
} | ||
continue; | ||
} | ||
|
||
for (auto &pair : Ctx.SearchPathOpts.ExternalPluginSearchPaths) { | ||
SmallString<128> fullPath(pair.SearchPath); | ||
llvm::sys::path::append(fullPath, | ||
"lib" + moduleName.str() + LTDL_SHLIB_EXT); | ||
// Try '-plugin-path'. | ||
if (auto *v = entry.dyn_cast<PluginPath>()) { | ||
SmallString<128> fullPath(v->SearchPath); | ||
llvm::sys::path::append(fullPath, pluginLibBasename); | ||
if (fs->exists(fullPath)) { | ||
return {std::string(fullPath), ""}; | ||
} | ||
continue; | ||
} | ||
|
||
if (fs->exists(fullPath)) { | ||
return {{std::string(fullPath), pair.ServerPath}}; | ||
// Try '-external-plugin-path'. | ||
if (auto *v = entry.dyn_cast<ExternalPluginPath>()) { | ||
SmallString<128> fullPath(v->SearchPath); | ||
llvm::sys::path::append(fullPath, pluginLibBasename); | ||
if (fs->exists(fullPath)) { | ||
return {std::string(fullPath), v->ServerPath}; | ||
} | ||
continue; | ||
} | ||
} | ||
return None; | ||
} | ||
|
||
Optional<StringRef> | ||
PluginLoader::lookupExecutablePluginByModuleName(Identifier moduleName) { | ||
auto &execPluginPaths = ExecutablePluginPaths; | ||
auto found = execPluginPaths.find(moduleName); | ||
if (found == execPluginPaths.end()) | ||
return None; | ||
return found->second; | ||
return {}; | ||
} | ||
|
||
LoadedLibraryPlugin *PluginLoader::loadLibraryPlugin(StringRef path) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModuleSearchPathKind::CompilePlugin
was incomplete (only set for-load-plugin-library
), and was not actually used.