Skip to content

Commit 1ee214a

Browse files
[llvm-cas] Teach the tool to read cache results
Complete the tool's ability to read and write ActionCache.
1 parent 3f96eff commit 1ee214a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

llvm/test/tools/llvm-cas/cache.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
RUN: rm -rf %t %t.cas
2+
RUN: mkdir %t
3+
4+
RUN: llvm-cas --cas %t.cas --make-blob \
5+
RUN: --data /dev/null > %t/empty.casid
6+
RUN: echo "abc" | \
7+
RUN: llvm-cas --cas %t.cas --make-blob \
8+
RUN: --data - >%t/abc.casid
9+
10+
RUN: llvm-cas --cas %t/cas --put-cache-key @%t/abc.casid @%t/empty.casid
11+
RUN: llvm-cas --cas %t/cas --get-cache-result @%t/abc.casid > %t/empty2.casid
12+
RUN: diff %t/empty.casid %t/empty2.casid
13+
14+
RUN: not llvm-cas --cas %t/cas --get-cache-result @%t/empty.casid

llvm/tools/llvm-cas/llvm-cas.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int import(ObjectStore &CAS, ObjectStore &UpstreamCAS,
5757
ArrayRef<std::string> Objects);
5858
static int putCacheKey(ObjectStore &CAS, ActionCache &AC,
5959
ArrayRef<std::string> Objects);
60+
static int getCacheResult(ObjectStore &CAS, ActionCache &AC, const CASID &ID);
6061
static int validateObject(ObjectStore &CAS, const CASID &ID);
6162

6263
int main(int Argc, char **Argv) {
@@ -90,6 +91,7 @@ int main(int Argc, char **Argv) {
9091
GetCASIDForFile,
9192
Import,
9293
PutCacheKey,
94+
GetCacheResult,
9395
Validate,
9496
};
9597
cl::opt<CommandKind> Command(
@@ -113,6 +115,8 @@ int main(int Argc, char **Argv) {
113115
clEnumValN(Import, "import", "import objects from another CAS"),
114116
clEnumValN(PutCacheKey, "put-cache-key",
115117
"set a value for a cache key"),
118+
clEnumValN(GetCacheResult, "get-cache-result",
119+
"get the result value from a cache key"),
116120
clEnumValN(Validate, "validate", "validate the object for CASID")),
117121
cl::init(CommandKind::Invalid));
118122

@@ -181,19 +185,24 @@ int main(int Argc, char **Argv) {
181185
return import(*CAS, *UpstreamCAS, Objects);
182186
}
183187

184-
if (Command == PutCacheKey) {
188+
if (Command == PutCacheKey || Command == GetCacheResult) {
185189
if (!AC)
186190
ExitOnErr(createStringError(inconvertibleErrorCode(),
187191
"no action-cache available"));
188-
return putCacheKey(*CAS, *AC, Objects);
189192
}
190193

194+
if (Command == PutCacheKey)
195+
return putCacheKey(*CAS, *AC, Objects);
196+
191197
// Remaining commands need exactly one CAS object.
192198
if (Objects.size() > 1)
193199
ExitOnErr(createStringError(inconvertibleErrorCode(),
194200
"too many <object>s, expected 1"));
195201
CASID ID = ExitOnErr(CAS->parseID(Objects.front()));
196202

203+
if (Command == GetCacheResult)
204+
return getCacheResult(*CAS, *AC, ID);
205+
197206
if (Command == TraverseGraph)
198207
return traverseGraph(*CAS, ID);
199208

@@ -577,6 +586,18 @@ static int putCacheKey(ObjectStore &CAS, ActionCache &AC,
577586
return 0;
578587
}
579588

589+
static int getCacheResult(ObjectStore &CAS, ActionCache &AC, const CASID &ID) {
590+
ExitOnError ExitOnErr("llvm-cas: get-cache-result: ");
591+
592+
auto Result = ExitOnErr(AC.get(ID));
593+
if (!Result) {
594+
outs() << "result not found\n";
595+
return 1;
596+
}
597+
outs() << *Result << "\n";
598+
return 0;
599+
}
600+
580601
int validateObject(ObjectStore &CAS, const CASID &ID) {
581602
ExitOnError ExitOnErr("llvm-cas: validate: ");
582603
ExitOnErr(CAS.validate(ID));

0 commit comments

Comments
 (0)