diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/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 CurrentFiles = + Files ? Files : new FileManager(FileSystemOptions(), RealFS); + + // FIXME: Avoid this copy. + std::vector CompileCommands = CDB.getCompileCommands(Input); + const std::vector &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(); }); }