[clang] 729f7b1 - [clang][deps] NFC: Remove CompilationDatabase from DependencyScanningWorker API

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 10 02:23:17 PDT 2021


Author: Jan Svoboda
Date: 2021-09-10T11:23:12+02:00
New Revision: 729f7b122081a078731a132cf4a8971c5c9fda8f

URL: https://github.com/llvm/llvm-project/commit/729f7b122081a078731a132cf4a8971c5c9fda8f
DIFF: https://github.com/llvm/llvm-project/commit/729f7b122081a078731a132cf4a8971c5c9fda8f.diff

LOG: [clang][deps] NFC: Remove CompilationDatabase from DependencyScanningWorker API

This patch simplifies the dependency scanner API. Depends on D108979.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D108980

Added: 
    

Modified: 
    clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
    clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
    clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index 8ede14bdc4f7..58f2f72da971 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -74,16 +74,15 @@ class DependencyScanningWorker {
 public:
   DependencyScanningWorker(DependencyScanningService &Service);
 
-  /// Run the dependency scanning tool for a given clang driver invocation (as
-  /// specified for the given Input in the CDB), and report the discovered
-  /// dependencies to the provided consumer. If \p ModuleName isn't empty, this
-  /// function reports the dependencies of module \p ModuleName.
+  /// Run the dependency scanning tool for a given clang driver command-line,
+  /// and report the discovered dependencies to the provided consumer. If \p
+  /// ModuleName isn't empty, this function reports the dependencies of module
+  /// \p ModuleName.
   ///
   /// \returns A \c StringError with the diagnostic output if clang errors
   /// occurred, success otherwise.
-  llvm::Error computeDependencies(const std::string &Input,
-                                  StringRef WorkingDirectory,
-                                  const CompilationDatabase &CDB,
+  llvm::Error computeDependencies(StringRef WorkingDirectory,
+                                  const std::vector<std::string> &CommandLine,
                                   DependencyConsumer &Consumer,
                                   llvm::Optional<StringRef> ModuleName = None);
 

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index a7969b358d9c..b083d09c8bff 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -110,11 +110,13 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
   // behavior.
   assert(Compilations.getAllCompileCommands().size() == 1 &&
          "Expected a compilation database with a single command!");
-  std::string Input = Compilations.getAllCompileCommands().front().Filename;
+  // FIXME: Avoid this copy.
+  std::vector<std::string> CommandLine =
+      Compilations.getAllCompileCommands().front().CommandLine;
 
   MakeDependencyPrinterConsumer Consumer;
-  auto Result = Worker.computeDependencies(Input, CWD, Compilations, Consumer,
-                                           ModuleName);
+  auto Result =
+      Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
   if (Result)
     return std::move(Result);
   std::string Output;
@@ -196,11 +198,13 @@ DependencyScanningTool::getFullDependencies(
   // behavior.
   assert(Compilations.getAllCompileCommands().size() == 1 &&
          "Expected a compilation database with a single command!");
-  std::string Input = Compilations.getAllCompileCommands().front().Filename;
+  // FIXME: Avoid this copy.
+  std::vector<std::string> CommandLine =
+      Compilations.getAllCompileCommands().front().CommandLine;
 
   FullDependencyPrinterConsumer Consumer(AlreadySeen);
-  llvm::Error Result = Worker.computeDependencies(Input, CWD, Compilations,
-                                                  Consumer, ModuleName);
+  llvm::Error Result =
+      Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
   if (Result)
     return std::move(Result);
   return Consumer.getFullDependencies();

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 4ee01df4f807..c8aa801ed5d6 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -318,9 +318,8 @@ static llvm::Error runWithDiags(
 }
 
 llvm::Error DependencyScanningWorker::computeDependencies(
-    const std::string &Input, StringRef WorkingDirectory,
-    const CompilationDatabase &CDB, DependencyConsumer &Consumer,
-    llvm::Optional<StringRef> ModuleName) {
+    StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
+    DependencyConsumer &Consumer, llvm::Optional<StringRef> ModuleName) {
   // Reset what might have been modified in the previous worker invocation.
   RealFS->setCurrentWorkingDirectory(WorkingDirectory);
   if (Files)
@@ -329,11 +328,6 @@ llvm::Error DependencyScanningWorker::computeDependencies(
   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;
-
   Optional<std::vector<std::string>> ModifiedCommandLine;
   if (ModuleName.hasValue()) {
     ModifiedCommandLine = CommandLine;


        


More information about the cfe-commits mailing list