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 @@ -83,8 +83,8 @@ /// \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, llvm::Optional ModuleName = None); + getDependencyFile(const std::vector &CommandLine, StringRef CWD, + llvm::Optional ModuleName = None); /// Collect the full module dependency graph for the input, ignoring any /// modules which have already been seen. If \p ModuleName isn't empty, this @@ -99,7 +99,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, llvm::Optional ModuleName = None); 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, llvm::Optional ModuleName) { /// Prints out all of the gathered dependencies into a string. class MakeDependencyPrinterConsumer : public DependencyConsumer { @@ -103,17 +103,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, ModuleName); @@ -126,7 +115,7 @@ llvm::Expected DependencyScanningTool::getFullDependencies( - const tooling::CompilationDatabase &Compilations, StringRef CWD, + const std::vector &CommandLine, StringRef CWD, const llvm::StringSet<> &AlreadySeen, llvm::Optional ModuleName) { class FullDependencyPrinterConsumer : public DependencyConsumer { @@ -191,17 +180,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, ModuleName); 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 @@ -513,10 +513,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; @@ -532,7 +530,7 @@ &DependencyOS, &Errs]() { llvm::StringSet<> AlreadySeenModules; while (true) { - const SingleCommandCompilationDatabase *Input; + const tooling::CompileCommand *Input; std::string Filename; std::string CWD; size_t LocalIndex; @@ -543,14 +541,13 @@ 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, + Input->CommandLine, CWD, ModuleName.empty() ? None : llvm::Optional(ModuleName.c_str())); @@ -559,7 +556,7 @@ HadErrors = true; } else { auto MaybeFullDeps = WorkerTools[I]->getFullDependencies( - *Input, CWD, AlreadySeenModules, + Input->CommandLine, CWD, AlreadySeenModules, ModuleName.empty() ? None : llvm::Optional(ModuleName.c_str()));