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