Skip to content

[libclang] Introduce an API to get the include-tree CASID #9001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions clang/include/clang-c/Dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,20 @@ CINDEX_LINKAGE CXCStringArray
CINDEX_LINKAGE CXCStringArray
clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule);

/**
* @returns the CASID of the include-tree for this module, if any.
*
* The string is only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE const char *
clang_experimental_DepGraphModule_getIncludeTreeID(CXDepGraphModule);

/**
* \returns the \c ActionCache key for this module, if any.
*
* The string is only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule);
Expand Down Expand Up @@ -596,6 +608,9 @@ CINDEX_LINKAGE CXCStringArray

/**
* \returns the \c ActionCache key for this translation unit, if any.
*
* The string is only valid to use while the \c CXDepGraphTUCommand object is
* valid.
*/
CINDEX_LINKAGE const char *
clang_experimental_DepGraphTUCommand_getCacheKey(CXDepGraphTUCommand);
Expand All @@ -619,6 +634,14 @@ CXCStringArray clang_experimental_DepGraph_getTUFileDeps(CXDepGraph);
CINDEX_LINKAGE
CXCStringArray clang_experimental_DepGraph_getTUModuleDeps(CXDepGraph);

/**
* @returns the CASID of the include-tree for this TU, if any.
*
* The string is only valid to use while the \c CXDepGraph object is valid.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraph_getTUIncludeTreeID(CXDepGraph);

/**
* \returns the context hash of the C++20 module this translation unit exports.
*
Expand Down
8 changes: 5 additions & 3 deletions clang/test/Index/Core/scan-deps-cas.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
// INCLUDE_TREE-NEXT: name: ModA
// INCLUDE_TREE-NEXT: context-hash: [[HASH_MOD_A:[A-Z0-9]+]]
// INCLUDE_TREE-NEXT: module-map-path: [[PREFIX]]/Inputs/module/module.modulemap
// INCLUDE_TREE-NEXT: include-tree-id: [[ModA_INCLUDE_TREE_ID:llvmcas://[[:xdigit:]]+]]
// INCLUDE_TREE-NEXT: cache-key: [[ModA_CACHE_KEY:llvmcas://[[:xdigit:]]+]]
// INCLUDE_TREE-NEXT: module-deps:
// INCLUDE_TREE-NEXT: file-deps:
Expand All @@ -81,12 +82,13 @@
// INCLUDE_TREE-NEXT: build-args:
// INCLUDE_TREE-SAME: -cc1
// INCLUDE_TREE-SAME: -fcas-path
// INCLUDE_TREE-SAME: -fcas-include-tree llvmcas://{{[[:xdigit:]]+}}
// INCLUDE_TREE-SAME: -fcas-include-tree [[ModA_INCLUDE_TREE_ID]]
// INCLUDE_TREE-SAME: -fcache-compile-job

// INCLUDE_TREE: dependencies:
// INCLUDE_TREE-NEXT: command 0:
// INCLUDE_TREE-NEXT: context-hash: [[HASH_TU:[A-Z0-9]+]]
// INCLUDE_TREE-NEXT: include-tree-id: [[INC_TU_INCLUDE_TREE_ID:llvmcas://[[:xdigit:]]+]]
// INCLUDE_TREE-NEXT: cache-key: [[INC_TU_CACHE_KEY:llvmcas://[[:xdigit:]]+]]
// INCLUDE_TREE-NEXT: module-deps:
// INCLUDE_TREE-NEXT: ModA:[[HASH_MOD_A]]
Expand All @@ -95,7 +97,7 @@
// INCLUDE_TREE-NEXT: build-args:
// INCLUDE_TREE-SAME: -cc1
// INCLUDE_TREE-SAME: -fcas-path
// INCLUDE_TREE-SAME: -fcas-include-tree llvmcas://{{[[:xdigit:]]+}}
// INCLUDE_TREE-SAME: -fcas-include-tree [[INC_TU_INCLUDE_TREE_ID]]
// INCLUDE_TREE-SAME: -fcache-compile-job
// INCLUDE_TREE-SAME: -fmodule-file-cache-key [[PCM:.*ModA_.*pcm]] [[ModA_CACHE_KEY]]
// INCLUDE_TREE-SAME: -fmodule-file={{(ModA=)?}}[[PCM]]
// INCLUDE_TREE-SAME: -fmodule-file={{(ModA=)?}}[[PCM]]
17 changes: 13 additions & 4 deletions clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,13 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
char *Output, size_t MaxLen)>(LookupOutput);

unsigned CommandIndex = 0;
auto HandleCommand = [&](const char *ContextHash, CXCStringArray ModuleDeps,
CXCStringArray FileDeps, CXCStringArray Args,
const char *CacheKey) {
auto HandleCommand = [&](const char *ContextHash, const char *IncludeTreeID,
CXCStringArray ModuleDeps, CXCStringArray FileDeps,
CXCStringArray Args, const char *CacheKey) {
llvm::outs() << " command " << CommandIndex++ << ":\n";
llvm::outs() << " context-hash: " << ContextHash << "\n";
if (IncludeTreeID)
llvm::outs() << " include-tree-id: " << IncludeTreeID << "\n";
if (CacheKey)
llvm::outs() << " cache-key: " << CacheKey << "\n";
llvm::outs() << " module-deps:\n";
Expand Down Expand Up @@ -805,6 +807,8 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
clang_experimental_DepGraphModule_getContextHash(Mod);
const char *ModuleMapPath =
clang_experimental_DepGraphModule_getModuleMapPath(Mod);
const char *ModuleIncludeTreeID =
clang_experimental_DepGraphModule_getIncludeTreeID(Mod);
const char *ModuleCacheKey =
clang_experimental_DepGraphModule_getCacheKey(Mod);
CXCStringArray ModuleDeps =
Expand All @@ -820,6 +824,8 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
<< " context-hash: " << ContextHash << "\n"
<< " module-map-path: "
<< (ModuleMapPath ? ModuleMapPath : "<none>") << "\n";
if (ModuleIncludeTreeID)
llvm::outs() << " include-tree-id: " << ModuleIncludeTreeID << "\n";
if (ModuleCacheKey)
llvm::outs() << " cache-key: " << ModuleCacheKey << "\n";
llvm::outs() << " module-deps:\n";
Expand All @@ -837,6 +843,8 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
}

llvm::outs() << "dependencies:\n";
const char *TUIncludeTreeID =
clang_experimental_DepGraph_getTUIncludeTreeID(Graph);
const char *TUContextHash =
clang_experimental_DepGraph_getTUContextHash(Graph);
CXCStringArray TUModuleDeps =
Expand All @@ -853,7 +861,8 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
clang_experimental_DepGraphTUCommand_getCacheKey(Cmd);
auto Dispose = llvm::make_scope_exit(
[&]() { clang_experimental_DepGraphTUCommand_dispose(Cmd); });
HandleCommand(TUContextHash, TUModuleDeps, TUFileDeps, Args, CacheKey);
HandleCommand(TUContextHash, TUIncludeTreeID, TUModuleDeps, TUFileDeps,
Args, CacheKey);
}
return 0;
}
Expand Down
15 changes: 15 additions & 0 deletions clang/tools/libclang/CDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule CXDepMod) {
ModDeps.getBuildArguments());
}

const char *
clang_experimental_DepGraphModule_getIncludeTreeID(CXDepGraphModule CXDepMod) {
ModuleDeps &ModDeps = *unwrap(CXDepMod)->ModDeps;
if (ModDeps.IncludeTreeID)
return ModDeps.IncludeTreeID->c_str();
return nullptr;
}

const char *
clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule CXDepMod) {
ModuleDeps &ModDeps = *unwrap(CXDepMod)->ModDeps;
Expand Down Expand Up @@ -653,6 +661,13 @@ CXCStringArray clang_experimental_DepGraph_getTUModuleDeps(CXDepGraph Graph) {
return unwrap(Graph)->StrMgr.createCStringsOwned(std::move(Modules));
}

const char *clang_experimental_DepGraph_getTUIncludeTreeID(CXDepGraph Graph) {
TranslationUnitDeps &TUDeps = unwrap(Graph)->TUDeps;
if (TUDeps.IncludeTreeID)
return TUDeps.IncludeTreeID->c_str();
return nullptr;
}

const char *clang_experimental_DepGraph_getTUContextHash(CXDepGraph Graph) {
TranslationUnitDeps &TUDeps = unwrap(Graph)->TUDeps;
return TUDeps.ID.ContextHash.c_str();
Expand Down
2 changes: 2 additions & 0 deletions clang/tools/libclang/libclang.map
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,14 @@ LLVM_16 {
clang_experimental_DepGraph_getTUCommand;
clang_experimental_DepGraph_getTUContextHash;
clang_experimental_DepGraph_getTUFileDeps;
clang_experimental_DepGraph_getTUIncludeTreeID;
clang_experimental_DepGraph_getTUModuleDeps;
clang_experimental_DepGraphModule_dispose;
clang_experimental_DepGraphModule_getBuildArguments;
clang_experimental_DepGraphModule_getCacheKey;
clang_experimental_DepGraphModule_getContextHash;
clang_experimental_DepGraphModule_getFileDeps;
clang_experimental_DepGraphModule_getIncludeTreeID;
clang_experimental_DepGraphModule_getModuleDeps;
clang_experimental_DepGraphModule_getModuleMapPath;
clang_experimental_DepGraphModule_getName;
Expand Down