[clang] 65f9719 - Revert "[C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)"

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 10 01:56:29 PST 2023


Author: Chuanqi Xu
Date: 2023-02-10T17:56:02+08:00
New Revision: 65f9719913eca9c7c72d1abf4eddab767abaebf6

URL: https://github.com/llvm/llvm-project/commit/65f9719913eca9c7c72d1abf4eddab767abaebf6
DIFF: https://github.com/llvm/llvm-project/commit/65f9719913eca9c7c72d1abf4eddab767abaebf6.diff

LOG: Revert "[C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)"

This reverts commit e1354763b6e641e45cc2371270883fcd26edf705.

There is a build failure in m68k-linux testing bot
(https://lab.llvm.org/buildbot/#/builders/192/builds/267), which is
weird. Revert this for now and look at the reasons.

Added: 
    

Modified: 
    clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
    clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
    clang/test/ClangScanDeps/P1689.cppm
    clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index 961e383b10963..505137c539e6f 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -92,21 +92,9 @@ class DependencyScanningTool {
   llvm::Expected<std::string>
   getDependencyFile(const std::vector<std::string> &CommandLine, StringRef CWD);
 
-  /// Collect the module dependency in P1689 format for C++20 named modules.
-  ///
-  /// \param MakeformatOutput The output parameter for dependency information
-  /// in make format if the command line requires to generate make-format
-  /// dependency information by `-MD -MF <dep_file>`.
-  ///
-  /// \param MakeformatOutputPath The output parameter for the path to
-  /// \param MakeformatOutput.
-  ///
-  /// \returns A \c StringError with the diagnostic output if clang errors
-  /// occurred, P1689 dependency format rules otherwise.
   llvm::Expected<P1689Rule>
-  getP1689ModuleDependencyFile(
-      const clang::tooling::CompileCommand &Command, StringRef CWD,
-      std::string &MakeformatOutput, std::string &MakeformatOutputPath);
+  getP1689ModuleDependencyFile(const CompileCommand &Command,
+                               StringRef CWD);
 
   /// Given a Clang driver command-line for a translation unit, gather the
   /// modular dependencies and return the information needed for explicit build.

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index b5e336bc704cb..ded5684190221 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -19,68 +19,66 @@ DependencyScanningTool::DependencyScanningTool(
     llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
     : Worker(Service, std::move(FS)) {}
 
-namespace {
-/// Prints out all of the gathered dependencies into a string.
-class MakeDependencyPrinterConsumer : public DependencyConsumer {
-public:
-  void handleBuildCommand(Command) override {}
-
-  void
-  handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
-    this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
-  }
+llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
+    const std::vector<std::string> &CommandLine, StringRef CWD) {
+  /// Prints out all of the gathered dependencies into a string.
+  class MakeDependencyPrinterConsumer : public DependencyConsumer {
+  public:
+    void handleBuildCommand(Command) override {}
 
-  void handleFileDependency(StringRef File) override {
-    Dependencies.push_back(std::string(File));
-  }
+    void
+    handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
+      this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
+    }
 
-  void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
-    // Same as `handleModuleDependency`.
-  }
+    void handleFileDependency(StringRef File) override {
+      Dependencies.push_back(std::string(File));
+    }
 
-  void handleModuleDependency(ModuleDeps MD) override {
-    // These are ignored for the make format as it can't support the full
-    // set of deps, and handleFileDependency handles enough for implicitly
-    // built modules to work.
-  }
+    void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
+      // Same as `handleModuleDependency`.
+    }
 
-  void handleContextHash(std::string Hash) override {}
+    void handleModuleDependency(ModuleDeps MD) override {
+      // These are ignored for the make format as it can't support the full
+      // set of deps, and handleFileDependency handles enough for implicitly
+      // built modules to work.
+    }
 
-  std::string lookupModuleOutput(const ModuleID &ID,
-                                 ModuleOutputKind Kind) override {
-    llvm::report_fatal_error("unexpected call to lookupModuleOutput");
-  }
+    void handleContextHash(std::string Hash) override {}
 
-  void printDependencies(std::string &S) {
-    assert(Opts && "Handled dependency output options.");
-
-    class DependencyPrinter : public DependencyFileGenerator {
-    public:
-      DependencyPrinter(DependencyOutputOptions &Opts,
-                        ArrayRef<std::string> Dependencies)
-          : DependencyFileGenerator(Opts) {
-        for (const auto &Dep : Dependencies)
-          addDependency(Dep);
-      }
-
-      void printDependencies(std::string &S) {
-        llvm::raw_string_ostream OS(S);
-        outputDependencyFile(OS);
-      }
-    };
-
-    DependencyPrinter Generator(*Opts, Dependencies);
-    Generator.printDependencies(S);
-  }
+    std::string lookupModuleOutput(const ModuleID &ID,
+                                   ModuleOutputKind Kind) override {
+      llvm::report_fatal_error("unexpected call to lookupModuleOutput");
+    }
 
-protected:
-  std::unique_ptr<DependencyOutputOptions> Opts;
-  std::vector<std::string> Dependencies;
-};
-} // anonymous namespace
+    void printDependencies(std::string &S) {
+      assert(Opts && "Handled dependency output options.");
+
+      class DependencyPrinter : public DependencyFileGenerator {
+      public:
+        DependencyPrinter(DependencyOutputOptions &Opts,
+                          ArrayRef<std::string> Dependencies)
+            : DependencyFileGenerator(Opts) {
+          for (const auto &Dep : Dependencies)
+            addDependency(Dep);
+        }
+
+        void printDependencies(std::string &S) {
+          llvm::raw_string_ostream OS(S);
+          outputDependencyFile(OS);
+        }
+      };
+
+      DependencyPrinter Generator(*Opts, Dependencies);
+      Generator.printDependencies(S);
+    }
+
+  private:
+    std::unique_ptr<DependencyOutputOptions> Opts;
+    std::vector<std::string> Dependencies;
+  };
 
-llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
-    const std::vector<std::string> &CommandLine, StringRef CWD) {
   MakeDependencyPrinterConsumer Consumer;
   auto Result = Worker.computeDependencies(CWD, CommandLine, Consumer);
   if (Result)
@@ -91,10 +89,8 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
 }
 
 llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
-    const CompileCommand &Command, StringRef CWD,
-    std::string &MakeformatOutput, std::string &MakeformatOutputPath) {
-  class P1689ModuleDependencyPrinterConsumer
-      : public MakeDependencyPrinterConsumer {
+    const CompileCommand &Command, StringRef CWD) {
+  class P1689ModuleDependencyPrinterConsumer : public DependencyConsumer {
   public:
     P1689ModuleDependencyPrinterConsumer(P1689Rule &Rule,
                                          const CompileCommand &Command)
@@ -102,6 +98,17 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
       Rule.PrimaryOutput = Command.Output;
     }
 
+    void
+    handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {}
+    void handleFileDependency(StringRef File) override {}
+    void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {}
+    void handleModuleDependency(ModuleDeps MD) override {}
+    void handleContextHash(std::string Hash) override {}
+    std::string lookupModuleOutput(const ModuleID &ID,
+                                   ModuleOutputKind Kind) override {
+      llvm::report_fatal_error("unexpected call to lookupModuleOutput");
+    }
+
     void handleProvidedAndRequiredStdCXXModules(
         std::optional<P1689ModuleInfo> Provided,
         std::vector<P1689ModuleInfo> Requires) override {
@@ -111,12 +118,6 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
       Rule.Requires = Requires;
     }
 
-    StringRef getMakeFormatDependencyOutputPath() {
-      if (Opts->OutputFormat != DependencyOutputFormat::Make)
-        return {};
-      return Opts->OutputFile;
-    }
-
   private:
     StringRef Filename;
     P1689Rule &Rule;
@@ -127,10 +128,6 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
   auto Result = Worker.computeDependencies(CWD, Command.CommandLine, Consumer);
   if (Result)
     return std::move(Result);
-
-  MakeformatOutputPath = Consumer.getMakeFormatDependencyOutputPath();
-  if (!MakeformatOutputPath.empty())
-    Consumer.printDependencies(MakeformatOutput);
   return Rule;
 }
 

diff  --git a/clang/test/ClangScanDeps/P1689.cppm b/clang/test/ClangScanDeps/P1689.cppm
index eb1d8d108dc49..22d7721c2e9bf 100644
--- a/clang/test/ClangScanDeps/P1689.cppm
+++ b/clang/test/ClangScanDeps/P1689.cppm
@@ -1,8 +1,3 @@
-// It is annoying to handle 
diff erent slash direction
-// in the filesystem of Windows and Linux.
-// So we disable the test on Windows here.
-// REQUIRES: !system-windows
-//
 // RUN: rm -fr %t
 // RUN: mkdir -p %t
 // RUN: split-file %s %t
@@ -30,50 +25,42 @@
 // RUN: clang-scan-deps -format=p1689 \
 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/User.cpp -o %t/User.o \
 // RUN:   | FileCheck %t/User.cpp -DPREFIX=%/t
-//
-// Check we can generate the make-style dependencies as expected.
-// RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/impl_part.cppm -o %t/impl_part.o \
-// RUN:      -MT %t/impl_part.o.ddi -MD -MF %t/impl_part.dep
-// RUN:   cat %t/impl_part.dep | FileCheck %t/impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE
-//
-// Check that we can generate multiple make-style dependency information with compilation database.
-// RUN: cat %t/P1689.dep | FileCheck %t/Checks.cpp -DPREFIX=%/t --check-prefix=CHECK-MAKE
 
 //--- P1689.json.in
 [
 {
   "directory": "DIR",
-  "command": "clang++ -std=c++20 DIR/M.cppm -c -o DIR/M.o -MT DIR/M.o.ddi -MD -MF DIR/P1689.dep",
+  "command": "clang++ -std=c++20 DIR/M.cppm -c -o DIR/M.o",
   "file": "DIR/M.cppm",
   "output": "DIR/M.o"
 },
 {
   "directory": "DIR",
-  "command": "clang++ -std=c++20 DIR/Impl.cpp -c -o DIR/Impl.o -MT DIR/Impl.o.ddi -MD -MF DIR/P1689.dep",
+  "command": "clang++ -std=c++20 DIR/Impl.cpp -c -o DIR/Impl.o",
   "file": "DIR/Impl.cpp",
   "output": "DIR/Impl.o"
 },
 {
   "directory": "DIR",
-  "command": "clang++ -std=c++20 DIR/impl_part.cppm -c -o DIR/impl_part.o -MT DIR/impl_part.o.ddi -MD -MF DIR/P1689.dep",
+  "command": "clang++ -std=c++20 DIR/impl_part.cppm -c -o DIR/impl_part.o",
   "file": "DIR/impl_part.cppm",
   "output": "DIR/impl_part.o"
 },
 {
   "directory": "DIR",
-  "command": "clang++ -std=c++20 DIR/interface_part.cppm -c -o DIR/interface_part.o -MT DIR/interface_part.o.ddi -MD -MF DIR/P1689.dep",
+  "command": "clang++ -std=c++20 DIR/interface_part.cppm -c -o DIR/interface_part.o",
   "file": "DIR/interface_part.cppm",
   "output": "DIR/interface_part.o"
 },
 {
   "directory": "DIR",
-  "command": "clang++ -std=c++20 DIR/User.cpp -c -o DIR/User.o -MT DIR/User.o.ddi -MD -MF DIR/P1689.dep",
+  "command": "clang++ -std=c++20 DIR/User.cpp -c -o DIR/User.o",
   "file": "DIR/User.cpp",
   "output": "DIR/User.o"
 }
 ]
 
+
 //--- M.cppm
 export module M;
 export import :interface_part;
@@ -288,17 +275,4 @@ int main() {
 // CHECK-NEXT:   "version": 1
 // CHECK-NEXT: }
 
-// CHECK-MAKE-DAG: [[PREFIX]]/impl_part.o.ddi: \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/impl_part.cppm \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
-// CHECK-MAKE-DAG: [[PREFIX]]/interface_part.o.ddi: \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/interface_part.cppm
-// CHECK-MAKE-DAG: [[PREFIX]]/M.o.ddi: \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/M.cppm
-// CHECK-MAKE-DAG: [[PREFIX]]/User.o.ddi: \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/User.cpp
-// CHECK-MAKE-DAG: [[PREFIX]]/Impl.o.ddi: \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/Impl.cpp \
-// CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
-
 //--- header.mock

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 4cfb857c5b3b7..b22046574d13f 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -825,46 +825,10 @@ int main(int argc, const char **argv) {
                                              Errs))
             HadErrors = true;
         } else if (Format == ScanningOutputFormat::P1689) {
-          // It is useful to generate the make-format dependency output during
-          // the scanning for P1689. Otherwise the users need to scan again for
-          // it. We will generate the make-format dependency output if we find
-          // `-MF` in the command lines.
-          std::string MakeformatOutputPath;
-          std::string MakeformatOutput;
-
-          auto MaybeRule = WorkerTools[I]->getP1689ModuleDependencyFile(
-              *Input, CWD, MakeformatOutput, MakeformatOutputPath);
-          HadErrors =
-              handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs);
-
-          if (!MakeformatOutputPath.empty() && !MakeformatOutput.empty() &&
-              !HadErrors) {
-            static std::mutex Lock;
-            // With compilation database, we may open 
diff erent files
-            // concurrently or we may write the same file concurrently. So we
-            // use a map here to allow multiple compile commands to write to the
-            // same file. Also we need a lock here to avoid data race.
-            static llvm::StringMap<llvm::raw_fd_ostream> OSs;
-            std::unique_lock<std::mutex> LockGuard(Lock);
-
-            auto OSIter = OSs.find(MakeformatOutputPath);
-            if (OSIter == OSs.end()) {
-              std::error_code EC;
-              OSIter = OSs.try_emplace(MakeformatOutputPath,
-                                       MakeformatOutputPath, EC)
-                           .first;
-              if (EC)
-                llvm::errs()
-                    << "Failed to open P1689 make format output file \""
-                    << MakeformatOutputPath << "\" for " << EC.message()
-                    << "\n";
-            }
-
-            SharedStream MakeformatOS(OSIter->second);
-            llvm::Expected<std::string> MaybeOutput(MakeformatOutput);
-            HadErrors = handleMakeDependencyToolResult(Filename, MaybeOutput,
-                                                       MakeformatOS, Errs);
-          }
+          auto MaybeRule =
+              WorkerTools[I]->getP1689ModuleDependencyFile(*Input, CWD);
+          if (handleP1689DependencyToolResult(Filename, MaybeRule, PD, Errs))
+            HadErrors = true;
         } else if (MaybeModuleName) {
           auto MaybeModuleDepsGraph = WorkerTools[I]->getModuleDependencies(
               *MaybeModuleName, Input->CommandLine, CWD, AlreadySeenModules,


        


More information about the cfe-commits mailing list