diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h @@ -82,8 +82,7 @@ /// \returns A \c StringError with the diagnostic output if clang errors /// occurred, dependency file contents otherwise. llvm::Expected - getDependencyFile(const tooling::CompilationDatabase &Compilations, - StringRef CWD); + getDependencyFile(const std::vector &CommandLine, StringRef CWD); /// Collect the full module dependency graph for the input, ignoring any /// modules which have already been seen. @@ -97,7 +96,7 @@ /// \returns a \c StringError with the diagnostic output if clang errors /// occurred, \c FullDependencies otherwise. llvm::Expected - getFullDependencies(const tooling::CompilationDatabase &Compilations, + getFullDependencies(const std::vector &CommandLine, StringRef CWD, const llvm::StringSet<> &AlreadySeen); private: diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h @@ -14,7 +14,6 @@ #include "clang/Basic/LLVM.h" #include "clang/Frontend/PCHContainerOperations.h" #include "clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h" -#include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/DependencyScanning/DependencyScanningService.h" #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h" #include "llvm/Support/Error.h" @@ -30,24 +29,6 @@ class DependencyScanningWorkerFilesystem; -/// Compilation database that holds and reports a single compile command. -class SingleCommandCompilationDatabase : public CompilationDatabase { - CompileCommand Command; - -public: - SingleCommandCompilationDatabase(CompileCommand Cmd) - : Command(std::move(Cmd)) {} - - std::vector - getCompileCommands(StringRef FilePath) const override { - return {Command}; - } - - std::vector getAllCompileCommands() const override { - return {Command}; - } -}; - class DependencyConsumer { public: virtual ~DependencyConsumer() {} diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -50,7 +50,7 @@ : Worker(Service) {} llvm::Expected DependencyScanningTool::getDependencyFile( - const tooling::CompilationDatabase &Compilations, StringRef CWD) { + const std::vector &CommandLine, StringRef CWD) { /// Prints out all of the gathered dependencies into a string. class MakeDependencyPrinterConsumer : public DependencyConsumer { public: @@ -102,17 +102,6 @@ std::vector Dependencies; }; - // We expect a single command here because if a source file occurs multiple - // times in the original CDB, then `computeDependencies` would run the - // `DependencyScanningAction` once for every time the input occured in the - // CDB. Instead we split up the CDB into single command chunks to avoid this - // behavior. - assert(Compilations.getAllCompileCommands().size() == 1 && - "Expected a compilation database with a single command!"); - // FIXME: Avoid this copy. - std::vector CommandLine = - Compilations.getAllCompileCommands().front().CommandLine; - MakeDependencyPrinterConsumer Consumer; auto Result = Worker.computeDependencies(CWD, CommandLine, Consumer); if (Result) @@ -124,7 +113,7 @@ llvm::Expected DependencyScanningTool::getFullDependencies( - const tooling::CompilationDatabase &Compilations, StringRef CWD, + const std::vector &CommandLine, StringRef CWD, const llvm::StringSet<> &AlreadySeen) { class FullDependencyPrinterConsumer : public DependencyConsumer { public: @@ -188,17 +177,6 @@ const llvm::StringSet<> &AlreadySeen; }; - // We expect a single command here because if a source file occurs multiple - // times in the original CDB, then `computeDependencies` would run the - // `DependencyScanningAction` once for every time the input occured in the - // CDB. Instead we split up the CDB into single command chunks to avoid this - // behavior. - assert(Compilations.getAllCompileCommands().size() == 1 && - "Expected a compilation database with a single command!"); - // FIXME: Avoid this copy. - std::vector CommandLine = - Compilations.getAllCompileCommands().front().CommandLine; - FullDependencyPrinterConsumer Consumer(AlreadySeen); llvm::Error Result = Worker.computeDependencies(CWD, CommandLine, Consumer); if (Result) diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -508,10 +508,8 @@ for (unsigned I = 0; I < Pool.getThreadCount(); ++I) WorkerTools.push_back(std::make_unique(Service)); - std::vector Inputs; - for (tooling::CompileCommand Cmd : - AdjustingCompilations->getAllCompileCommands()) - Inputs.emplace_back(Cmd); + std::vector Inputs = + AdjustingCompilations->getAllCompileCommands(); std::atomic HadErrors(false); FullDeps FD; @@ -527,7 +525,7 @@ &DependencyOS, &Errs]() { llvm::StringSet<> AlreadySeenModules; while (true) { - const SingleCommandCompilationDatabase *Input; + const tooling::CompileCommand *Input; std::string Filename; std::string CWD; size_t LocalIndex; @@ -538,19 +536,19 @@ return; LocalIndex = Index; Input = &Inputs[Index++]; - tooling::CompileCommand Cmd = Input->getAllCompileCommands()[0]; - Filename = std::move(Cmd.Filename); - CWD = std::move(Cmd.Directory); + Filename = std::move(Input->Filename); + CWD = std::move(Input->Directory); } // Run the tool on it. if (Format == ScanningOutputFormat::Make) { - auto MaybeFile = WorkerTools[I]->getDependencyFile(*Input, CWD); + auto MaybeFile = + WorkerTools[I]->getDependencyFile(Input->CommandLine, CWD); if (handleMakeDependencyToolResult(Filename, MaybeFile, DependencyOS, Errs)) HadErrors = true; } else { auto MaybeFullDeps = WorkerTools[I]->getFullDependencies( - *Input, CWD, AlreadySeenModules); + Input->CommandLine, CWD, AlreadySeenModules); if (handleFullDependencyToolResult(Filename, MaybeFullDeps, FD, LocalIndex, DependencyOS, Errs)) HadErrors = true;