Skip to content

Commit bbc7ed4

Browse files
committed
Add C API
1 parent 7d702e4 commit bbc7ed4

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

clang/include/clang-c/Dependencies.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ CINDEX_DEPRECATED CINDEX_LINKAGE void
161161
clang_experimental_DependencyScannerServiceOptions_setActionCache(
162162
CXDependencyScannerServiceOptions Opts, CXCASActionCache Cache);
163163

164+
/**
165+
* Set if negative stat caching is enabled or disabled. If this is not called
166+
* the default value is used.
167+
*
168+
* The default is false unless the environment variable
169+
* `CLANG_SCAN_CACHE_NEGATIVE_STATS` is set to empty or "1".
170+
*/
171+
CINDEX_LINKAGE void
172+
clang_experimental_DependencyScannerServiceOptions_setCacheNegativeStats(
173+
CXDependencyScannerServiceOptions Opts, bool CacheNegativeStats);
174+
164175
/**
165176
* Create a \c CXDependencyScannerService object.
166177
* Must be disposed with \c

clang/tools/libclang/CDependencies.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct DependencyScannerServiceOptions {
3838
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default;
3939
std::shared_ptr<cas::ObjectStore> CAS;
4040
std::shared_ptr<cas::ActionCache> Cache;
41+
std::optional<bool> CacheNegativeStats;
4142

4243
ScanningOutputFormat getFormat() const;
4344
};
@@ -161,6 +162,11 @@ void clang_experimental_DependencyScannerServiceOptions_setActionCache(
161162
unwrap(Opts)->CASOpts.CASPath = cas::unwrap(Cache)->CachePath;
162163
}
163164

165+
void clang_experimental_DependencyScannerServiceOptions_setCacheNegativeStats(
166+
CXDependencyScannerServiceOptions Opts, bool CacheNegativeStats) {
167+
unwrap(Opts)->CacheNegativeStats = CacheNegativeStats;
168+
}
169+
164170
CXDependencyScannerService
165171
clang_experimental_DependencyScannerService_create_v0(CXDependencyMode Format) {
166172
// FIXME: Pass default CASOpts and nullptr as CachingOnDiskFileSystem now.
@@ -207,7 +213,10 @@ clang_experimental_DependencyScannerService_create_v1(
207213
return wrap(new DependencyScanningService(
208214
ScanningMode::DependencyDirectivesScan, Format, unwrap(Opts)->CASOpts,
209215
std::move(CAS), std::move(Cache), std::move(FS),
210-
unwrap(Opts)->OptimizeArgs));
216+
unwrap(Opts)->OptimizeArgs, /*EagerLoadModules=*/false,
217+
/*TraceVFS=*/false, llvm::sys::toTimeT(std::chrono::system_clock::now()),
218+
unwrap(Opts)->CacheNegativeStats ? *unwrap(Opts)->CacheNegativeStats
219+
: shouldNegativeStatCacheDefault()));
211220
}
212221

213222
void clang_experimental_DependencyScannerService_dispose_v0(

clang/tools/libclang/libclang.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ LLVM_21 {
609609
clang_experimental_DepGraphModuleLinkLibrary_isFramework;
610610
};
611611

612+
LLVM_22 {
613+
global:
614+
clang_experimental_DependencyScannerServiceOptions_setCacheNegativeStats;
615+
};
616+
612617
# Example of how to add a new symbol version entry. If you do add a new symbol
613618
# version, please update the example to depend on the version you added.
614619
# LLVM_X {

clang/unittests/libclang/DependencyScanningCAPITests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ TEST(DependencyScanningCAPITests, DependencyScanningFSCacheOutOfDate) {
2222

2323
CXDependencyScannerServiceOptions ServiceOptions =
2424
clang_experimental_DependencyScannerServiceOptions_create();
25+
clang_experimental_DependencyScannerServiceOptions_setCacheNegativeStats(
26+
ServiceOptions, true);
2527
CXDependencyScannerService Service =
2628
clang_experimental_DependencyScannerService_create_v1(ServiceOptions);
2729
CXDependencyScannerWorker Worker =

0 commit comments

Comments
 (0)