Skip to content

Commit f560e4a

Browse files
committed
[libclang][cas] Avoid using CachingOnDiskFileSystem when include-tree output is requested
It has overhead that is not needed for the include-tree mechanism. (cherry picked from commit 32bd17b)
1 parent fa6ed10 commit f560e4a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

clang/tools/libclang/CDependencies.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
2424
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
2525
#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
26+
#include "llvm/CAS/CASProvidingFileSystem.h"
2627
#include "llvm/CAS/CachingOnDiskFileSystem.h"
2728
#include "llvm/Support/Process.h"
2829

@@ -145,7 +146,7 @@ ScanningOutputFormat DependencyScannerServiceOptions::getFormat() const {
145146
return ScanningOutputFormat::FullTree;
146147

147148
// Note: default caching behaviour is currently cas-fs.
148-
return ConfiguredFormat;
149+
return ScanningOutputFormat::FullTree;
149150
}
150151

151152
CXDependencyScannerService
@@ -155,15 +156,18 @@ clang_experimental_DependencyScannerService_create_v1(
155156
std::shared_ptr<llvm::cas::ObjectStore> CAS = unwrap(Opts)->CAS;
156157
std::shared_ptr<llvm::cas::ActionCache> Cache = unwrap(Opts)->Cache;
157158
IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> FS;
158-
if (CAS && Cache) {
159+
ScanningOutputFormat Format = unwrap(Opts)->getFormat();
160+
bool IsCASFSOutput = Format == ScanningOutputFormat::Tree ||
161+
Format == ScanningOutputFormat::FullTree;
162+
if (CAS && Cache && IsCASFSOutput) {
159163
assert(unwrap(Opts)->CASOpts.getKind() != CASOptions::UnknownCAS &&
160164
"CAS and ActionCache must match CASOptions");
161165
FS = llvm::cantFail(
162166
llvm::cas::createCachingOnDiskFileSystem(CAS));
163167
}
164168
return wrap(new DependencyScanningService(
165-
ScanningMode::DependencyDirectivesScan, unwrap(Opts)->getFormat(),
166-
unwrap(Opts)->CASOpts, std::move(CAS), std::move(Cache), std::move(FS),
169+
ScanningMode::DependencyDirectivesScan, Format, unwrap(Opts)->CASOpts,
170+
std::move(CAS), std::move(Cache), std::move(FS),
167171
/*ReuseFilemanager=*/false));
168172
}
169173

@@ -195,8 +199,16 @@ void clang_experimental_FileDependenciesList_dispose(
195199

196200
CXDependencyScannerWorker clang_experimental_DependencyScannerWorker_create_v0(
197201
CXDependencyScannerService Service) {
198-
return wrap(new DependencyScanningWorker(
199-
*unwrap(Service), llvm::vfs::createPhysicalFileSystem()));
202+
ScanningOutputFormat Format = unwrap(Service)->getFormat();
203+
bool IsIncludeTreeOutput = Format == ScanningOutputFormat::IncludeTree ||
204+
Format == ScanningOutputFormat::FullIncludeTree;
205+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
206+
llvm::vfs::createPhysicalFileSystem();
207+
if (IsIncludeTreeOutput)
208+
FS = llvm::cas::createCASProvidingFileSystem(unwrap(Service)->getCAS(),
209+
std::move(FS));
210+
211+
return wrap(new DependencyScanningWorker(*unwrap(Service), FS));
200212
}
201213

202214
void clang_experimental_DependencyScannerWorker_dispose_v0(

0 commit comments

Comments
 (0)