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(); }); }
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(); }); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits