This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2528fc49035: [clang][deps] Stop using `ClangTool` for
virtual files (authored by rovka, committed by jansvoboda11).
Changed prior to commit:
https://reviews.llvm.org/D109498?vs=371570&id=371817#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109498/new/
https://reviews.llvm.org/D109498
Files:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -141,11 +141,10 @@
StringRef WorkingDirectory, DependencyConsumer &Consumer,
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings,
- ScanningOutputFormat Format, llvm::Optional<StringRef> ModuleName = None,
- llvm::Optional<llvm::MemoryBufferRef> FakeMemBuffer = None)
+ ScanningOutputFormat Format, llvm::Optional<StringRef> ModuleName = None)
: WorkingDirectory(WorkingDirectory), Consumer(Consumer),
DepFS(std::move(DepFS)), PPSkipMappings(PPSkipMappings), Format(Format),
- ModuleName(ModuleName), FakeMemBuffer(FakeMemBuffer) {}
+ ModuleName(ModuleName) {}
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
FileManager *FileMgr,
@@ -215,16 +214,6 @@
.ExcludedConditionalDirectiveSkipMappings = PPSkipMappings;
}
- if (ModuleName.hasValue()) {
- SmallString<128> FullPath(*ModuleName);
- llvm::sys::fs::make_absolute(WorkingDirectory, FullPath);
- SourceManager &SrcMgr = Compiler.getSourceManager();
- FileMgr->getVirtualFile(FullPath.c_str(), FakeMemBuffer->getBufferSize(),
- 0);
- FileID MainFileID = SrcMgr.createFileID(*FakeMemBuffer);
- SrcMgr.setMainFileID(MainFileID);
- }
-
// Create the dependency collector that will collect the produced
// dependencies.
//
@@ -280,7 +269,6 @@
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
ScanningOutputFormat Format;
llvm::Optional<StringRef> ModuleName;
- llvm::Optional<llvm::MemoryBufferRef> FakeMemBuffer;
};
} // end anonymous namespace
@@ -298,7 +286,12 @@
PCHContainerOps->registerWriter(
std::make_unique<ObjectFilePCHContainerWriter>());
- RealFS = llvm::vfs::createPhysicalFileSystem();
+ auto OverlayFS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
+ llvm::vfs::createPhysicalFileSystem());
+ InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
+ OverlayFS->pushOverlay(InMemoryFS);
+ RealFS = OverlayFS;
+
if (Service.canSkipExcludedPPRanges())
PPSkipMappings =
std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
@@ -329,13 +322,10 @@
const CompilationDatabase &CDB, DependencyConsumer &Consumer,
llvm::Optional<StringRef> ModuleName) {
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
- std::unique_ptr<llvm::MemoryBuffer> FakeMemBuffer =
- ModuleName.hasValue() ? llvm::MemoryBuffer::getMemBuffer(" ") : nullptr;
return runWithDiags(DiagOpts.get(), [&](DiagnosticConsumer &DC) {
/// Create the tool that uses the underlying file system to ensure that any
/// file system requests that are made by the driver do not go through the
/// dependency scanning filesystem.
- SmallString<128> FullPath;
tooling::ClangTool Tool(CDB,
ModuleName.hasValue() ? ModuleName->str() : Input,
PCHContainerOps, RealFS, Files);
@@ -343,21 +333,15 @@
Tool.setRestoreWorkingDir(false);
Tool.setPrintErrorMessage(false);
Tool.setDiagnosticConsumer(&DC);
- DependencyScanningAction Action(
- WorkingDirectory, Consumer, DepFS, PPSkipMappings.get(), Format,
- ModuleName,
- FakeMemBuffer
- ? llvm::Optional<llvm::MemoryBufferRef>(*FakeMemBuffer.get())
- : None);
+ DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
+ PPSkipMappings.get(), Format, ModuleName);
if (ModuleName.hasValue()) {
- Tool.mapVirtualFile(*ModuleName, FakeMemBuffer->getBuffer());
- FullPath = *ModuleName;
- llvm::sys::fs::make_absolute(WorkingDirectory, FullPath);
+ InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
Tool.appendArgumentsAdjuster(
[&](const tooling::CommandLineArguments &Args, StringRef FileName) {
tooling::CommandLineArguments AdjustedArgs(Args);
- AdjustedArgs.push_back(std::string(FullPath));
+ AdjustedArgs.emplace_back(*ModuleName);
return AdjustedArgs;
});
}
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
===================================================================
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -92,7 +92,10 @@
std::shared_ptr<PCHContainerOperations> PCHContainerOps;
std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
+ /// The physical filesystem overlaid by `InMemoryFS`.
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS;
+ /// The in-memory filesystem laid on top the physical filesystem in `RealFS`.
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFS;
/// The file system that is used by each worker when scanning for
/// dependencies. This filesystem persists accross multiple compiler
/// invocations.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits