Skip to content

Commit d371822

Browse files
authored
Merge pull request #6582 from akyrtzi/pr/stable/libclang-cache-keys
[stable][libclang][cas] Expose the module and TU cache keys from the libclang dep-scan API
2 parents f5c0e15 + 458881b commit d371822

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

clang/include/clang-c/Dependencies.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ CINDEX_LINKAGE CXCStringArray
525525
CINDEX_LINKAGE CXCStringArray
526526
clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule);
527527

528+
/**
529+
* \returns the \c ActionCache key for this module, if any.
530+
*/
531+
CINDEX_LINKAGE
532+
const char *clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule);
533+
528534
/**
529535
* \returns the number \c CXDepGraphTUCommand objects in the graph.
530536
*/
@@ -563,6 +569,12 @@ CINDEX_LINKAGE const char *
563569
CINDEX_LINKAGE CXCStringArray
564570
clang_experimental_DepGraphTUCommand_getBuildArguments(CXDepGraphTUCommand);
565571

572+
/**
573+
* \returns the \c ActionCache key for this translation unit, if any.
574+
*/
575+
CINDEX_LINKAGE const char *
576+
clang_experimental_DepGraphTUCommand_getCacheKey(CXDepGraphTUCommand);
577+
566578
/**
567579
* \returns the list of files which this translation unit directly depends on.
568580
*

clang/test/Index/Core/scan-deps-cas.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// CHECK-NEXT: name: ModA
3434
// CHECK-NEXT: context-hash: [[HASH_MOD_A:[A-Z0-9]+]]
3535
// CHECK-NEXT: module-map-path: [[PREFIX]]/Inputs/module/module.modulemap
36+
// CHECK-NEXT: cache-key: [[CASFS_MODA_CACHE_KEY:llvmcas://[[:xdigit:]]+]]
3637
// CHECK-NEXT: module-deps:
3738
// CHECK-NEXT: file-deps:
3839
// CHECK-NEXT: [[PREFIX]]/Inputs/module/ModA.h
@@ -51,6 +52,7 @@
5152
// CHECK-NEXT: dependencies:
5253
// CHECK-NEXT: command 0:
5354
// CHECK-NEXT: context-hash: [[HASH_TU:[A-Z0-9]+]]
55+
// CHECK-NEXT: cache-key: [[CASFS_TU_CACHE_KEY:llvmcas://[[:xdigit:]]+]]
5456
// CHECK-NEXT: module-deps:
5557
// CHECK-NEXT: ModA:[[HASH_MOD_A]]
5658
// CHECK-NEXT: file-deps:
@@ -66,6 +68,7 @@
6668
// INCLUDE_TREE: dependencies:
6769
// INCLUDE_TREE-NEXT: command 0:
6870
// INCLUDE_TREE-NEXT: context-hash: [[HASH_TU:[A-Z0-9]+]]
71+
// INCLUDE_TREE-NEXT: cache-key: [[INC_TU_CACHE_KEY:llvmcas://[[:xdigit:]]+]]
6972
// INCLUDE_TREE-NEXT: module-deps:
7073
// INCLUDE_TREE-NEXT: file-deps:
7174
// INCLUDE_TREE-NEXT: [[PREFIX]]/scan-deps-cas.m

clang/tools/c-index-test/core_main.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,13 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
753753

754754
unsigned CommandIndex = 0;
755755
auto HandleCommand = [&](const char *ContextHash, CXCStringArray ModuleDeps,
756-
CXCStringArray FileDeps, CXCStringArray Args) {
756+
CXCStringArray FileDeps, CXCStringArray Args,
757+
const char *CacheKey) {
757758
llvm::outs() << " command " << CommandIndex++ << ":\n";
758-
llvm::outs() << " context-hash: " << ContextHash << "\n"
759-
<< " module-deps:\n";
759+
llvm::outs() << " context-hash: " << ContextHash << "\n";
760+
if (CacheKey)
761+
llvm::outs() << " cache-key: " << CacheKey << "\n";
762+
llvm::outs() << " module-deps:\n";
760763
for (const auto &ModuleName :
761764
llvm::makeArrayRef(ModuleDeps.Strings, ModuleDeps.Count))
762765
llvm::outs() << " " << ModuleName << "\n";
@@ -794,6 +797,8 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
794797
clang_experimental_DepGraphModule_getContextHash(Mod);
795798
const char *ModuleMapPath =
796799
clang_experimental_DepGraphModule_getModuleMapPath(Mod);
800+
const char *ModuleCacheKey =
801+
clang_experimental_DepGraphModule_getCacheKey(Mod);
797802
CXCStringArray ModuleDeps =
798803
clang_experimental_DepGraphModule_getModuleDeps(Mod);
799804
CXCStringArray FileDeps =
@@ -806,8 +811,10 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
806811
<< " name: " << Name << "\n"
807812
<< " context-hash: " << ContextHash << "\n"
808813
<< " module-map-path: "
809-
<< (ModuleMapPath ? ModuleMapPath : "<none>") << "\n"
810-
<< " module-deps:\n";
814+
<< (ModuleMapPath ? ModuleMapPath : "<none>") << "\n";
815+
if (ModuleCacheKey)
816+
llvm::outs() << " cache-key: " << ModuleCacheKey << "\n";
817+
llvm::outs() << " module-deps:\n";
811818
for (const auto &ModuleName :
812819
ArrayRef(ModuleDeps.Strings, ModuleDeps.Count))
813820
llvm::outs() << " " << ModuleName << "\n";
@@ -834,9 +841,11 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
834841
clang_experimental_DepGraph_getTUCommand(Graph, I);
835842
CXCStringArray Args =
836843
clang_experimental_DepGraphTUCommand_getBuildArguments(Cmd);
844+
const char *CacheKey =
845+
clang_experimental_DepGraphTUCommand_getCacheKey(Cmd);
837846
auto Dispose = llvm::make_scope_exit(
838847
[&]() { clang_experimental_DepGraphTUCommand_dispose(Cmd); });
839-
HandleCommand(TUContextHash, TUModuleDeps, TUFileDeps, Args);
848+
HandleCommand(TUContextHash, TUModuleDeps, TUFileDeps, Args, CacheKey);
840849
}
841850
return 0;
842851
}

clang/tools/libclang/CDependencies.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@ clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule CXDepMod) {
546546
return unwrap(CXDepMod)->StrMgr.createCStringsRef(ModDeps.BuildArguments);
547547
}
548548

549+
const char *
550+
clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule CXDepMod) {
551+
ModuleDeps &ModDeps = *unwrap(CXDepMod)->ModDeps;
552+
if (ModDeps.ModuleCacheKey)
553+
return ModDeps.ModuleCacheKey->c_str();
554+
return nullptr;
555+
}
556+
549557
size_t clang_experimental_DepGraph_getNumTUCommands(CXDepGraph Graph) {
550558
TranslationUnitDeps &TUDeps = unwrap(Graph)->TUDeps;
551559
return TUDeps.Commands.size();
@@ -573,6 +581,14 @@ CXCStringArray clang_experimental_DepGraphTUCommand_getBuildArguments(
573581
return unwrap(CXCmd)->StrMgr.createCStringsRef(TUCmd.Arguments);
574582
}
575583

584+
const char *
585+
clang_experimental_DepGraphTUCommand_getCacheKey(CXDepGraphTUCommand CXCmd) {
586+
Command &TUCmd = *unwrap(CXCmd)->TUCmd;
587+
if (TUCmd.TUCacheKey)
588+
return TUCmd.TUCacheKey->c_str();
589+
return nullptr;
590+
}
591+
576592
CXCStringArray clang_experimental_DepGraph_getTUFileDeps(CXDepGraph Graph) {
577593
TranslationUnitDeps &TUDeps = unwrap(Graph)->TUDeps;
578594
return unwrap(Graph)->StrMgr.createCStringsRef(TUDeps.FileDeps);

clang/tools/libclang/libclang.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,15 @@ LLVM_16 {
503503
clang_experimental_DepGraph_getTUModuleDeps;
504504
clang_experimental_DepGraphModule_dispose;
505505
clang_experimental_DepGraphModule_getBuildArguments;
506+
clang_experimental_DepGraphModule_getCacheKey;
506507
clang_experimental_DepGraphModule_getContextHash;
507508
clang_experimental_DepGraphModule_getFileDeps;
508509
clang_experimental_DepGraphModule_getModuleDeps;
509510
clang_experimental_DepGraphModule_getModuleMapPath;
510511
clang_experimental_DepGraphModule_getName;
511512
clang_experimental_DepGraphTUCommand_dispose;
512513
clang_experimental_DepGraphTUCommand_getBuildArguments;
514+
clang_experimental_DepGraphTUCommand_getCacheKey;
513515
clang_experimental_DepGraphTUCommand_getExecutable;
514516
clang_getUnqualifiedType;
515517
clang_getNonReferenceType;

0 commit comments

Comments
 (0)