|
23 | 23 | #include "swift/Frontend/Frontend.h"
|
24 | 24 | #include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
25 | 25 | #include "swift/Parse/ParseVersion.h"
|
| 26 | +#include "clang/CAS/CASOptions.h" |
26 | 27 | #include "llvm/CAS/ActionCache.h"
|
27 | 28 | #include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
|
28 | 29 | #include "llvm/CAS/ObjectStore.h"
|
@@ -87,7 +88,7 @@ class SwiftCacheToolInvocation {
|
87 | 88 | CompilerInvocation Invocation;
|
88 | 89 | PrintingDiagnosticConsumer PDC;
|
89 | 90 | std::string MainExecutablePath;
|
90 |
| - std::string CASPath; |
| 91 | + clang::CASOptions CASOpts; |
91 | 92 | std::vector<std::string> Inputs;
|
92 | 93 | std::vector<std::string> FrontendArgs;
|
93 | 94 | SwiftCacheToolAction ActionKind = SwiftCacheToolAction::Invalid;
|
@@ -124,8 +125,19 @@ class SwiftCacheToolInvocation {
|
124 | 125 | return 0;
|
125 | 126 | }
|
126 | 127 |
|
127 |
| - CASPath = |
128 |
| - ParsedArgs.getLastArgValue(OPT_cas_path, getDefaultOnDiskCASPath()); |
| 128 | + if (const Arg* PluginPath = ParsedArgs.getLastArg(OPT_cas_plugin_path)) |
| 129 | + CASOpts.PluginPath = PluginPath->getValue(); |
| 130 | + if (const Arg* OnDiskPath = ParsedArgs.getLastArg(OPT_cas_path)) |
| 131 | + CASOpts.CASPath = OnDiskPath->getValue(); |
| 132 | + for (StringRef Opt : ParsedArgs.getAllArgValues(OPT_cas_plugin_option)) { |
| 133 | + StringRef Name, Value; |
| 134 | + std::tie(Name, Value) = Opt.split('='); |
| 135 | + CASOpts.PluginOptions.emplace_back(std::string(Name), std::string(Value)); |
| 136 | + } |
| 137 | + |
| 138 | + // Fallback to default path if not set. |
| 139 | + if (CASOpts.CASPath.empty() && CASOpts.PluginPath.empty()) |
| 140 | + CASOpts.CASPath = getDefaultOnDiskCASPath(); |
129 | 141 |
|
130 | 142 | Inputs = ParsedArgs.getAllArgValues(OPT_INPUT);
|
131 | 143 | FrontendArgs = ParsedArgs.getAllArgValues(OPT__DASH_DASH);
|
@@ -186,8 +198,20 @@ class SwiftCacheToolInvocation {
|
186 | 198 |
|
187 | 199 | // Make sure CASPath is the same between invocation and cache-tool by
|
188 | 200 | // appending the cas-path since the option doesn't affect cache key.
|
189 |
| - Args.emplace_back("-cas-path"); |
190 |
| - Args.emplace_back(CASPath.c_str()); |
| 201 | + if (!CASOpts.CASPath.empty()) { |
| 202 | + Args.emplace_back("-cas-path"); |
| 203 | + Args.emplace_back(CASOpts.CASPath.c_str()); |
| 204 | + } |
| 205 | + if (!CASOpts.PluginPath.empty()) { |
| 206 | + Args.emplace_back("-cas-plugin-path"); |
| 207 | + Args.emplace_back(CASOpts.PluginPath.c_str()); |
| 208 | + } |
| 209 | + std::vector<std::string> PluginJoinedOpts; |
| 210 | + for (const auto& Opt: CASOpts.PluginOptions) { |
| 211 | + PluginJoinedOpts.emplace_back(Opt.first + "=" + Opt.second); |
| 212 | + Args.emplace_back("-cas-plugin-option"); |
| 213 | + Args.emplace_back(PluginJoinedOpts.back().c_str()); |
| 214 | + } |
191 | 215 |
|
192 | 216 | if (Invocation.parseArgs(Args, Instance.getDiags(),
|
193 | 217 | &configurationFileBuffers, workingDirectory,
|
@@ -336,7 +360,7 @@ readOutputEntriesFromFile(StringRef Path) {
|
336 | 360 | }
|
337 | 361 |
|
338 | 362 | int SwiftCacheToolInvocation::validateOutputs() {
|
339 |
| - auto DB = llvm::cas::createOnDiskUnifiedCASDatabases(CASPath); |
| 363 | + auto DB = CASOpts.getOrCreateDatabases(); |
340 | 364 | if (!DB)
|
341 | 365 | report_fatal_error(DB.takeError());
|
342 | 366 |
|
|
0 commit comments