[PATCH] D108979: [clang][deps] NFC: Stop going through ClangTool
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 10 02:02:46 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG146ec74a8382: [clang][deps] NFC: Stop going through ClangTool (authored by jansvoboda11).
Changed prior to commit:
https://reviews.llvm.org/D108979?vs=370545&id=371832#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108979/new/
https://reviews.llvm.org/D108979
Files:
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
@@ -321,31 +321,38 @@
const std::string &Input, StringRef WorkingDirectory,
const CompilationDatabase &CDB, DependencyConsumer &Consumer,
llvm::Optional<StringRef> ModuleName) {
+ // Reset what might have been modified in the previous worker invocation.
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
+ if (Files)
+ Files->setVirtualFileSystem(RealFS);
+
+ llvm::IntrusiveRefCntPtr<FileManager> CurrentFiles =
+ Files ? Files : new FileManager(FileSystemOptions(), RealFS);
+
+ // FIXME: Avoid this copy.
+ std::vector<CompileCommand> CompileCommands = CDB.getCompileCommands(Input);
+ const std::vector<std::string> &CommandLine =
+ CompileCommands.front().CommandLine;
+
+ Optional<std::vector<std::string>> ModifiedCommandLine;
+ if (ModuleName.hasValue()) {
+ ModifiedCommandLine = CommandLine;
+ InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
+ ModifiedCommandLine->emplace_back(*ModuleName);
+ }
+
+ const std::vector<std::string> &FinalCommandLine =
+ ModifiedCommandLine ? *ModifiedCommandLine : CommandLine;
+
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.
- tooling::ClangTool Tool(CDB,
- ModuleName.hasValue() ? ModuleName->str() : Input,
- PCHContainerOps, RealFS, Files);
- Tool.clearArgumentsAdjusters();
- Tool.setRestoreWorkingDir(false);
- Tool.setPrintErrorMessage(false);
- Tool.setDiagnosticConsumer(&DC);
DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
PPSkipMappings.get(), Format, ModuleName);
-
- if (ModuleName.hasValue()) {
- InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
- Tool.appendArgumentsAdjuster(
- [&](const tooling::CommandLineArguments &Args, StringRef FileName) {
- tooling::CommandLineArguments AdjustedArgs(Args);
- AdjustedArgs.emplace_back(*ModuleName);
- return AdjustedArgs;
- });
- }
-
- return !Tool.run(&Action);
+ // Create an invocation 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.
+ ToolInvocation Invocation(FinalCommandLine, &Action, CurrentFiles.get(),
+ PCHContainerOps);
+ Invocation.setDiagnosticConsumer(&DC);
+ return Invocation.run();
});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108979.371832.patch
Type: text/x-patch
Size: 2998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210910/3b1b1c66/attachment.bin>
More information about the cfe-commits
mailing list