[C++20] [Modules] [ClangScanDeps] Ensure that we can mix the use of and clang modules
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 15 Feb 2023 02:59:07 +0000 (10:59 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 15 Feb 2023 03:00:03 +0000 (11:00 +0800)
Add a test to ensure that the clang-scan-deps won't crash due to the
unexpected use of clang modules.

clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/test/ClangScanDeps/P1689.cppm

index 03e996a..c15f6e7 100644 (file)
@@ -117,6 +117,12 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
       return Opts->OutputFile;
     }
 
+    // The lookupModuleOutput is for clang modules. P1689 format don't need it.
+    std::string lookupModuleOutput(const ModuleID &ID,
+                                 ModuleOutputKind Kind) override {
+      return "";
+    }
+
   private:
     StringRef Filename;
     P1689Rule &Rule;
index c9ef8f4..bbe9cc3 100644 (file)
 //
 // 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
+//
+// Check that we can mix the use of -format=p1689 and -fmodules.
+// RUN: clang-scan-deps -format=p1689 \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o %t/impl_part.o \
+// RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in
 [
@@ -299,4 +304,7 @@ int main() {
 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/Impl.cpp \
 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
 
+//--- module.modulemap
+module Mock { header "header.mock" }
+
 //--- header.mock