|
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"
|
29 | 30 | #include "llvm/Option/OptTable.h"
|
| 31 | +#include "llvm/Support/Allocator.h" |
30 | 32 | #include "llvm/Support/Error.h"
|
31 | 33 | #include "llvm/Support/JSON.h"
|
32 | 34 | #include "llvm/Support/MemoryBuffer.h"
|
| 35 | +#include "llvm/Support/StringSaver.h" |
33 | 36 | #include <memory>
|
34 | 37 |
|
35 | 38 | using namespace swift;
|
@@ -87,7 +90,7 @@ class SwiftCacheToolInvocation {
|
87 | 90 | CompilerInvocation Invocation;
|
88 | 91 | PrintingDiagnosticConsumer PDC;
|
89 | 92 | std::string MainExecutablePath;
|
90 |
| - std::string CASPath; |
| 93 | + clang::CASOptions CASOpts; |
91 | 94 | std::vector<std::string> Inputs;
|
92 | 95 | std::vector<std::string> FrontendArgs;
|
93 | 96 | SwiftCacheToolAction ActionKind = SwiftCacheToolAction::Invalid;
|
@@ -124,8 +127,19 @@ class SwiftCacheToolInvocation {
|
124 | 127 | return 0;
|
125 | 128 | }
|
126 | 129 |
|
127 |
| - CASPath = |
128 |
| - ParsedArgs.getLastArgValue(OPT_cas_path, getDefaultOnDiskCASPath()); |
| 130 | + if (const Arg* PluginPath = ParsedArgs.getLastArg(OPT_cas_plugin_path)) |
| 131 | + CASOpts.PluginPath = PluginPath->getValue(); |
| 132 | + if (const Arg* OnDiskPath = ParsedArgs.getLastArg(OPT_cas_path)) |
| 133 | + CASOpts.CASPath = OnDiskPath->getValue(); |
| 134 | + for (StringRef Opt : ParsedArgs.getAllArgValues(OPT_cas_plugin_option)) { |
| 135 | + StringRef Name, Value; |
| 136 | + std::tie(Name, Value) = Opt.split('='); |
| 137 | + CASOpts.PluginOptions.emplace_back(std::string(Name), std::string(Value)); |
| 138 | + } |
| 139 | + |
| 140 | + // Fallback to default path if not set. |
| 141 | + if (CASOpts.CASPath.empty() && CASOpts.PluginPath.empty()) |
| 142 | + CASOpts.CASPath = getDefaultOnDiskCASPath(); |
129 | 143 |
|
130 | 144 | Inputs = ParsedArgs.getAllArgValues(OPT_INPUT);
|
131 | 145 | FrontendArgs = ParsedArgs.getAllArgValues(OPT__DASH_DASH);
|
@@ -186,8 +200,21 @@ class SwiftCacheToolInvocation {
|
186 | 200 |
|
187 | 201 | // Make sure CASPath is the same between invocation and cache-tool by
|
188 | 202 | // 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()); |
| 203 | + if (!CASOpts.CASPath.empty()) { |
| 204 | + Args.emplace_back("-cas-path"); |
| 205 | + Args.emplace_back(CASOpts.CASPath.c_str()); |
| 206 | + } |
| 207 | + if (!CASOpts.PluginPath.empty()) { |
| 208 | + Args.emplace_back("-cas-plugin-path"); |
| 209 | + Args.emplace_back(CASOpts.PluginPath.c_str()); |
| 210 | + } |
| 211 | + llvm::BumpPtrAllocator Alloc; |
| 212 | + llvm::StringSaver Saver(Alloc); |
| 213 | + for (const auto& Opt: CASOpts.PluginOptions) { |
| 214 | + StringRef OptValue = Saver.save(Opt.first + "=" + Opt.second); |
| 215 | + Args.emplace_back("-cas-plugin-option"); |
| 216 | + Args.emplace_back(OptValue.str().c_str()); |
| 217 | + } |
191 | 218 |
|
192 | 219 | if (Invocation.parseArgs(Args, Instance.getDiags(),
|
193 | 220 | &configurationFileBuffers, workingDirectory,
|
@@ -336,7 +363,7 @@ readOutputEntriesFromFile(StringRef Path) {
|
336 | 363 | }
|
337 | 364 |
|
338 | 365 | int SwiftCacheToolInvocation::validateOutputs() {
|
339 |
| - auto DB = llvm::cas::createOnDiskUnifiedCASDatabases(CASPath); |
| 366 | + auto DB = CASOpts.getOrCreateDatabases(); |
340 | 367 | if (!DB)
|
341 | 368 | report_fatal_error(DB.takeError());
|
342 | 369 |
|
|
0 commit comments