[PATCH] D108979: [clang][deps] NFC: Stop going through ClangTool
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 31 02:42:05 PDT 2021
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The dependency scanner currently uses `ClangTool` to invoke the dependency scanning action.
However, `ClangTool` seems to be the wrong level of abstraction. It's intended to be run over a collection of compile commands, which we actively avoid via `SingleCommandCompilationDatabase`. It automatically injects `-fsyntax-only` and other flags, which we avoid by calling `clearArgumentsAdjusters()`. It deduces the resource directory based on the current executable path, which we'd like to change to deducing from `argv[0]`.
Internally, `ClangTool` uses `ToolInvocation` which seems to be more in line with what the dependency scanner tries to achieve. This patch switches to directly using `ToolInvocation` instead. NFC.
Repository:
rG LLVM Github Monorepo
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
@@ -309,17 +309,24 @@
const std::string &Input, StringRef WorkingDirectory,
const CompilationDatabase &CDB, DependencyConsumer &Consumer) {
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
+
+ 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;
+
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, Input, PCHContainerOps, RealFS, Files);
- Tool.clearArgumentsAdjusters();
- Tool.setRestoreWorkingDir(false);
- Tool.setPrintErrorMessage(false);
- Tool.setDiagnosticConsumer(&DC);
DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
PPSkipMappings.get(), Format);
- 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(CommandLine, &Action, CurrentFiles.get(),
+ PCHContainerOps);
+ Invocation.setDiagnosticConsumer(&DC);
+ return Invocation.run();
});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108979.369661.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210831/daed70f2/attachment.bin>
More information about the cfe-commits
mailing list