Skip to content

Commit c82e17a

Browse files
authored
Merge pull request #63695 from rintaro/options-load-plugin-executable
[Option] Add compiler option to specify executable plugins
2 parents 9bdbd38 + bf0a62f commit c82e17a

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

include/swift/AST/SearchPathOptions.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ class SearchPathOptions {
234234
/// Compiler plugin library search paths.
235235
std::vector<std::string> CompilerPluginLibraryPaths;
236236

237+
/// Compiler plugin executable paths and providing module names.
238+
/// Format: '<path>#<module names>'
239+
std::vector<std::string> CompilerPluginExecutablePaths;
240+
237241
/// Add a single import search path. Must only be called from
238242
/// \c ASTContext::addSearchPath.
239243
void addImportSearchPath(StringRef Path, llvm::vfs::FileSystem *FS) {
@@ -324,6 +328,16 @@ class SearchPathOptions {
324328
return CompilerPluginLibraryPaths;
325329
}
326330

331+
void setCompilerPluginExecutablePaths(
332+
std::vector<std::string> NewCompilerPluginExecutablePaths) {
333+
CompilerPluginExecutablePaths = NewCompilerPluginExecutablePaths;
334+
Lookup.searchPathsDidChange();
335+
}
336+
337+
ArrayRef<std::string> getCompilerPluginExecutablePaths() const {
338+
return CompilerPluginExecutablePaths;
339+
}
340+
327341
/// Path(s) to virtual filesystem overlay YAML files.
328342
std::vector<std::string> VFSOverlayFiles;
329343

include/swift/Option/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,4 +1753,11 @@ def load_plugin_library:
17531753
"macros">,
17541754
MetaVarName<"<path>">;
17551755

1756+
def load_plugin_executable:
1757+
Separate<["-"], "load-plugin-executable">,
1758+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
1759+
HelpText<"Path to an executable compiler plugins and providing module names "
1760+
"such as macros">,
1761+
MetaVarName<"<path>#<module-names>">;
1762+
17561763
include "FrontendOptions.td"

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
306306
inputArgs.AddLastArg(arguments, options::OPT_enable_bare_slash_regex);
307307
inputArgs.AddLastArg(arguments, options::OPT_enable_experimental_cxx_interop);
308308
inputArgs.AddLastArg(arguments, options::OPT_load_plugin_library);
309+
inputArgs.AddLastArg(arguments, options::OPT_load_plugin_executable);
309310

310311
// Pass on any build config options
311312
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,15 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
14741474
}
14751475
Opts.setCompilerPluginLibraryPaths(CompilerPluginLibraryPaths);
14761476

1477+
std::vector<std::string> CompilerPluginExecutablePaths(
1478+
Opts.getCompilerPluginExecutablePaths());
1479+
for (const Arg *A : Args.filtered(OPT_load_plugin_executable)) {
1480+
// NOTE: The value has '#<module names>' after the path.
1481+
// But resolveSearchPath() works as long as the value starts with a path.
1482+
CompilerPluginExecutablePaths.push_back(resolveSearchPath(A->getValue()));
1483+
}
1484+
Opts.setCompilerPluginExecutablePaths(CompilerPluginExecutablePaths);
1485+
14771486
return false;
14781487
}
14791488

0 commit comments

Comments
 (0)