Skip to content

Commit 37f3217

Browse files
akyrtzibenlangmuir
authored andcommitted
[clang-cas-test] Support using the CAS plugin mechanism
(cherry picked from commit be12a51)
1 parent 81e936c commit 37f3217

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

clang/test/CAS/print-compile-job-cache-key.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@
5858
// RUN: -e "s/\" .*$//" > %t/include-tree-id
5959

6060
// RUN: clang-cas-test -print-include-tree -cas %t/cas @%t/include-tree-id | FileCheck %s -check-prefix=INCLUDE_TREE -DSRC_FILE=%s
61+
62+
// Print key from plugin CAS.
63+
// RUN: llvm-cas --cas plugin://%llvmshlibdir/libCASPluginTest%pluginext?ondisk-path=%t/cas-plugin --ingest --data %s > %t/casid-plugin
64+
// RUN: %clang -cc1 -triple x86_64-apple-macos11 \
65+
// RUN: -fcas-path %t/cas-plugin -fcas-fs @%t/casid-plugin -fcache-compile-job \
66+
// RUN: -fcas-plugin-path %llvmshlibdir/libCASPluginTest%pluginext \
67+
// RUN: -Rcompile-job-cache-miss -emit-obj -o %t/output.o %s 2> %t/output-plugin.txt
68+
// RUN: cat %t/output-plugin.txt | sed \
69+
// RUN: -e "s/^.*miss for '//" \
70+
// RUN: -e "s/' .*$//" > %t/cache-key-plugin
71+
// RUN: clang-cas-test -print-compile-job-cache-key -cas %t/cas @%t/cache-key-plugin \
72+
// RUN: -fcas-plugin-path %llvmshlibdir/libCASPluginTest%pluginext | FileCheck %s

clang/tools/clang-cas-test/ClangCASTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ int main(int Argc, const char **Argv) {
5353

5454
cl::opt<std::string> CASPath("cas", cl::desc("On-disk CAS path"),
5555
cl::value_desc("path"));
56+
cl::opt<std::string> CASPluginPath("fcas-plugin-path",
57+
cl::desc("Path to plugin CAS library"),
58+
cl::value_desc("path"));
59+
cl::list<std::string> CASPluginOpts("fcas-plugin-option",
60+
cl::desc("Plugin CAS Options"));
5661
cl::list<std::string> Inputs(cl::Positional, cl::desc("<input>..."));
5762

5863
cl::ParseCommandLineOptions(Argc, Argv, "clang-cas-test");
@@ -69,6 +74,13 @@ int main(int Argc, const char **Argv) {
6974
// Printing a cache key only makes sense in an existing CAS, so default to
7075
// on-disk instead of in-memory if no --cas path is specified.
7176
Opts.CASPath = CASPath.empty() ? std::string("auto") : CASPath;
77+
if (!CASPluginPath.empty()) {
78+
Opts.PluginPath = CASPluginPath;
79+
for (const auto &PluginOpt : CASPluginOpts) {
80+
auto [Name, Val] = StringRef(PluginOpt).split('=');
81+
Opts.PluginOptions.push_back({std::string(Name), std::string(Val)});
82+
}
83+
}
7284

7385
auto CAS =
7486
Opts.getOrCreateDatabases(*Diags, /*CreateEmptyCASOnFailure=*/false)

llvm/tools/libCASPluginTest/libCASPluginTest.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ struct CASWrapper {
115115
/// Load the object, potentially "downloading" it from upstream.
116116
Expected<std::optional<ondisk::ObjectHandle>> loadObject(ObjectID ID);
117117

118-
/// "Uploads" the full object node graph.
119-
Expected<ObjectID> upstreamNode(ObjectID Node);
120-
/// "Downloads" only a single object node. The rest of the nodes in the graph
121-
/// will be "downloaded" lazily as they are visited.
122-
Expected<ObjectID> downstreamNode(ObjectID Node);
123-
124118
/// "Uploads" a key the associated full node graph.
125119
Error upstreamKey(ArrayRef<uint8_t> Key, ObjectID Value);
126120
/// "Downloads" the single root node that is associated with the key. The rest
@@ -133,6 +127,13 @@ struct CASWrapper {
133127
Fn(errs());
134128
errs().flush();
135129
}
130+
131+
private:
132+
/// "Uploads" the full object node graph.
133+
Expected<ObjectID> upstreamNode(ObjectID Node);
134+
/// "Downloads" only a single object node. The rest of the nodes in the graph
135+
/// will be "downloaded" lazily as they are visited.
136+
Expected<ObjectID> downstreamNode(ObjectID Node);
136137
};
137138

138139
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(CASWrapper, llcas_cas_t)
@@ -208,6 +209,8 @@ Expected<ObjectID> CASWrapper::downstreamNode(ObjectID Node) {
208209
}
209210

210211
Error CASWrapper::upstreamKey(ArrayRef<uint8_t> Key, ObjectID Value) {
212+
if (!UpstreamDB)
213+
return Error::success();
211214
Expected<ObjectID> UpstreamVal = upstreamNode(Value);
212215
if (!UpstreamVal)
213216
return UpstreamVal.takeError();
@@ -220,6 +223,8 @@ Error CASWrapper::upstreamKey(ArrayRef<uint8_t> Key, ObjectID Value) {
220223

221224
Expected<std::optional<ObjectID>>
222225
CASWrapper::downstreamKey(ArrayRef<uint8_t> Key) {
226+
if (!UpstreamDB)
227+
return std::nullopt;
223228
std::optional<ObjectID> UpstreamValue;
224229
if (Error E = UpstreamDB->KVGet(Key).moveInto(UpstreamValue))
225230
return std::move(E);

0 commit comments

Comments
 (0)