mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Caching] Encoding cache key for input file with index instead of path
Avoid path encoding difference (for example, real_path vs. path from symlink) by eliminating the path from cache key. Cache key is now encoded with the index of the input file from all the input files from the command-line, reguardless if those inputs will produce output or not. This is to ensure stable ordering even the batching is different. Add a new cache computation API that is preferred for using input index directly. Old API for cache key is deprecated but still updated to fallback to real_path comparsion if needed. As a result of swift scan API change, rename the feature in JSON file to avoid version confusion between swift-driver and libSwiftScan. rdar://119387650
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "swift-c/DependencyScan/DependencyScan.h"
|
||||
#include "swift/Basic/Defer.h"
|
||||
#include "swift/Basic/FileTypes.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/StringSaver.h"
|
||||
@@ -26,6 +27,7 @@ using namespace llvm;
|
||||
namespace {
|
||||
enum Actions {
|
||||
compute_cache_key,
|
||||
compute_cache_key_from_index,
|
||||
cache_query,
|
||||
replay_result,
|
||||
};
|
||||
@@ -35,11 +37,13 @@ llvm::cl::opt<std::string> CASPath("cas-path", llvm::cl::desc("<path>"),
|
||||
llvm::cl::cat(Category));
|
||||
llvm::cl::opt<std::string> CASID("id", llvm::cl::desc("<casid>"),
|
||||
llvm::cl::cat(Category));
|
||||
llvm::cl::opt<std::string> Input("input", llvm::cl::desc("<file>"),
|
||||
llvm::cl::opt<std::string> Input("input", llvm::cl::desc("<file|index>"),
|
||||
llvm::cl::cat(Category));
|
||||
llvm::cl::opt<Actions>
|
||||
Action("action", llvm::cl::desc("<action>"),
|
||||
llvm::cl::values(clEnumVal(compute_cache_key, "compute cache key"),
|
||||
clEnumVal(compute_cache_key_from_index,
|
||||
"compute cache key from index"),
|
||||
clEnumVal(cache_query, "cache query"),
|
||||
clEnumVal(replay_result, "replay result")),
|
||||
llvm::cl::cat(Category));
|
||||
@@ -78,6 +82,27 @@ static int action_compute_cache_key(swiftscan_cas_t cas, StringRef input,
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
action_compute_cache_key_from_index(swiftscan_cas_t cas, StringRef index,
|
||||
std::vector<const char *> &Args) {
|
||||
unsigned inputIndex = 0;
|
||||
if (!to_integer(index, inputIndex)) {
|
||||
llvm::errs() << "-input is not a number for compute_cache_key_from_index\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t err_msg;
|
||||
auto key = swiftscan_cache_compute_key_from_input_index(
|
||||
cas, Args.size(), Args.data(), inputIndex, &err_msg);
|
||||
if (key.length == 0)
|
||||
return printError(err_msg);
|
||||
|
||||
llvm::outs() << toString(key) << "\n";
|
||||
swiftscan_string_dispose(key);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int print_cached_compilation(swiftscan_cached_compilation_t comp,
|
||||
const char *key) {
|
||||
auto numOutput = swiftscan_cached_compilation_get_num_outputs(comp);
|
||||
@@ -194,6 +219,8 @@ int main(int argc, char *argv[]) {
|
||||
switch (Action) {
|
||||
case compute_cache_key:
|
||||
return action_compute_cache_key(cas, Input, Args);
|
||||
case compute_cache_key_from_index:
|
||||
return action_compute_cache_key_from_index(cas, Input, Args);
|
||||
case cache_query:
|
||||
return action_cache_query(cas, CASID.c_str());
|
||||
case replay_result:
|
||||
|
||||
Reference in New Issue
Block a user