mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CAS] Teach swift-cache-tool about plugin-cas
This commit is contained in:
@@ -15,3 +15,9 @@ def cache_tool_action: JoinedOrSeparate<["-"], "cache-tool-action">,
|
||||
|
||||
def cas_path: Separate<["-"], "cas-path">,
|
||||
HelpText<"Path to CAS">, MetaVarName<"<path>">;
|
||||
|
||||
def cas_plugin_path: Separate<["-"], "cas-plugin-path">,
|
||||
HelpText<"Path to CAS Plugin">, MetaVarName<"<path>">;
|
||||
|
||||
def cas_plugin_option: Separate<["-"], "cas-plugin-option">,
|
||||
HelpText<"Option pass to CAS Plugin">, MetaVarName<"<name>=<option>">;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
||||
#include "swift/Parse/ParseVersion.h"
|
||||
#include "clang/CAS/CASOptions.h"
|
||||
#include "llvm/CAS/ActionCache.h"
|
||||
#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
|
||||
#include "llvm/CAS/ObjectStore.h"
|
||||
@@ -87,7 +88,7 @@ private:
|
||||
CompilerInvocation Invocation;
|
||||
PrintingDiagnosticConsumer PDC;
|
||||
std::string MainExecutablePath;
|
||||
std::string CASPath;
|
||||
clang::CASOptions CASOpts;
|
||||
std::vector<std::string> Inputs;
|
||||
std::vector<std::string> FrontendArgs;
|
||||
SwiftCacheToolAction ActionKind = SwiftCacheToolAction::Invalid;
|
||||
@@ -124,8 +125,19 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
CASPath =
|
||||
ParsedArgs.getLastArgValue(OPT_cas_path, getDefaultOnDiskCASPath());
|
||||
if (const Arg* PluginPath = ParsedArgs.getLastArg(OPT_cas_plugin_path))
|
||||
CASOpts.PluginPath = PluginPath->getValue();
|
||||
if (const Arg* OnDiskPath = ParsedArgs.getLastArg(OPT_cas_path))
|
||||
CASOpts.CASPath = OnDiskPath->getValue();
|
||||
for (StringRef Opt : ParsedArgs.getAllArgValues(OPT_cas_plugin_option)) {
|
||||
StringRef Name, Value;
|
||||
std::tie(Name, Value) = Opt.split('=');
|
||||
CASOpts.PluginOptions.emplace_back(std::string(Name), std::string(Value));
|
||||
}
|
||||
|
||||
// Fallback to default path if not set.
|
||||
if (CASOpts.CASPath.empty() && CASOpts.PluginPath.empty())
|
||||
CASOpts.CASPath = getDefaultOnDiskCASPath();
|
||||
|
||||
Inputs = ParsedArgs.getAllArgValues(OPT_INPUT);
|
||||
FrontendArgs = ParsedArgs.getAllArgValues(OPT__DASH_DASH);
|
||||
@@ -186,8 +198,20 @@ private:
|
||||
|
||||
// Make sure CASPath is the same between invocation and cache-tool by
|
||||
// appending the cas-path since the option doesn't affect cache key.
|
||||
Args.emplace_back("-cas-path");
|
||||
Args.emplace_back(CASPath.c_str());
|
||||
if (!CASOpts.CASPath.empty()) {
|
||||
Args.emplace_back("-cas-path");
|
||||
Args.emplace_back(CASOpts.CASPath.c_str());
|
||||
}
|
||||
if (!CASOpts.PluginPath.empty()) {
|
||||
Args.emplace_back("-cas-plugin-path");
|
||||
Args.emplace_back(CASOpts.PluginPath.c_str());
|
||||
}
|
||||
std::vector<std::string> PluginJoinedOpts;
|
||||
for (const auto& Opt: CASOpts.PluginOptions) {
|
||||
PluginJoinedOpts.emplace_back(Opt.first + "=" + Opt.second);
|
||||
Args.emplace_back("-cas-plugin-option");
|
||||
Args.emplace_back(PluginJoinedOpts.back().c_str());
|
||||
}
|
||||
|
||||
if (Invocation.parseArgs(Args, Instance.getDiags(),
|
||||
&configurationFileBuffers, workingDirectory,
|
||||
@@ -336,7 +360,7 @@ readOutputEntriesFromFile(StringRef Path) {
|
||||
}
|
||||
|
||||
int SwiftCacheToolInvocation::validateOutputs() {
|
||||
auto DB = llvm::cas::createOnDiskUnifiedCASDatabases(CASPath);
|
||||
auto DB = CASOpts.getOrCreateDatabases();
|
||||
if (!DB)
|
||||
report_fatal_error(DB.takeError());
|
||||
|
||||
|
||||
@@ -44,27 +44,38 @@
|
||||
// RUN: %target-swift-frontend -cache-compile-job %s -emit-module -c -emit-dependencies \
|
||||
// RUN: -emit-tbd -emit-tbd-path %t/test.tbd -o %t/test.o -allow-unstable-cache-key-for-testing | %FileCheck %s
|
||||
|
||||
/// Test plugin CAS.
|
||||
// RUN: %cache-tool -cas-path %t/cas -cas-plugin-path %llvm_libs_dir/libCASPluginTest%llvm_plugin_ext \
|
||||
// RUN: -cas-plugin-option first-prefix=myfirst- -cache-tool-action print-output-keys -- \
|
||||
// RUN: %target-swift-frontend -cache-compile-job %s -emit-module -c -emit-dependencies \
|
||||
// RUN: -emit-tbd -emit-tbd-path %t/test.tbd -o %t/test.o -allow-unstable-cache-key-for-testing | %FileCheck %s --check-prefix=CHECK --check-prefix=PLUGIN
|
||||
|
||||
// CHECK: test.o
|
||||
// CHECK-NEXT: "OutputKind": "object"
|
||||
// CHECK-NEXT: "Input"
|
||||
// CHECK-NEXT: "CacheKey"
|
||||
// PLUGIN-SAME: myfirst-llvmcas://
|
||||
|
||||
// CHECK: test.swiftmodule
|
||||
// CHECK-NEXT: "OutputKind": "swiftmodule"
|
||||
// CHECK-NEXT: "Input"
|
||||
// CHECK-NEXT: "CacheKey"
|
||||
// PLUGIN-SAME: myfirst-llvmcas://
|
||||
|
||||
// CHECK: test.d
|
||||
// CHECK-NEXT: "OutputKind": "dependencies"
|
||||
// CHECK-NEXT: "Input"
|
||||
// CHECK-NEXT: "CacheKey"
|
||||
// PLUGIN-SAME: myfirst-llvmcas://
|
||||
|
||||
// CHECK: test.tbd
|
||||
// CHECK-NEXT: "OutputKind": "tbd"
|
||||
// CHECK-NEXT: "Input"
|
||||
// CHECK-NEXT: "CacheKey"
|
||||
// PLUGIN-SAME: myfirst-llvmcas://
|
||||
|
||||
// CHECK: <cached-diagnostics>
|
||||
// CHECK-NEXT: "OutputKind": "cached-diagnostics"
|
||||
// CHECK-NEXT: "Input": "<cached-diagnostics>"
|
||||
// CHECK-NEXT: "CacheKey"
|
||||
// PLUGIN-SAME: myfirst-llvmcas://
|
||||
|
||||
Reference in New Issue
Block a user