xref: /llvm-project/clang/test/ClangScanDeps/modules-pch-common-via-submodule.c (revision 9d4837f47c48c634d4a0ac799188e1f5332495ef)
106d4a763SSteven Wan // Unsupported on AIX because we don't support the requisite "__clangast"
206d4a763SSteven Wan // section in XCOFF yet.
364e4d03cSPaul Robinson // UNSUPPORTED: target={{.*}}-aix{{.*}}
406d4a763SSteven Wan 
5be795ee1SJan Svoboda // Check that we discover dependency on a precompiled module when it's imported
6be795ee1SJan Svoboda // by a **submodule** instead of a top-level module.
783c633eaSJan Svoboda 
883c633eaSJan Svoboda // RUN: rm -rf %t && mkdir %t
983c633eaSJan Svoboda // RUN: cp %S/Inputs/modules-pch-common-via-submodule/* %t
1083c633eaSJan Svoboda 
1183c633eaSJan Svoboda // Scan dependencies of the PCH:
1283c633eaSJan Svoboda //
1383c633eaSJan Svoboda // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-via-submodule/cdb_pch.json > %t/cdb.json
1483c633eaSJan Svoboda // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
1571e32d5cSJan Svoboda // RUN:   -module-files-dir %t/build > %t/result_pch.json
16c4b13f7aSJan Svoboda // RUN: cat %t/result_pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
1783c633eaSJan Svoboda //
18c4b13f7aSJan Svoboda // CHECK-PCH:      {
1983c633eaSJan Svoboda // CHECK-PCH-NEXT:   "modules": [
2083c633eaSJan Svoboda // CHECK-PCH-NEXT:     {
2183c633eaSJan Svoboda // CHECK-PCH-NEXT:       "clang-module-deps": [],
2283c633eaSJan Svoboda // CHECK-PCH-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
2383c633eaSJan Svoboda // CHECK-PCH-NEXT:       "command-line": [
2483c633eaSJan Svoboda // CHECK-PCH:            ],
2583c633eaSJan Svoboda // CHECK-PCH-NEXT:       "context-hash": "[[HASH_MOD_COMMON:.*]]",
2683c633eaSJan Svoboda // CHECK-PCH-NEXT:       "file-deps": [
27*9d4837f4SJan Svoboda // CHECK-PCH-NEXT:         "[[PREFIX]]/module.modulemap",
28*9d4837f4SJan Svoboda // CHECK-PCH-NEXT:         "[[PREFIX]]/mod_common.h"
2983c633eaSJan Svoboda // CHECK-PCH-NEXT:       ],
3068eb3b20SArtem Chikin // CHECK-PCH-NEXT:       "link-libraries": [],
3183c633eaSJan Svoboda // CHECK-PCH-NEXT:       "name": "ModCommon"
3283c633eaSJan Svoboda // CHECK-PCH-NEXT:     }
3383c633eaSJan Svoboda // CHECK-PCH-NEXT:   ],
3483c633eaSJan Svoboda // CHECK-PCH-NEXT:   "translation-units": [
3583c633eaSJan Svoboda // CHECK-PCH-NEXT:     {
3683902c40SBen Langmuir // CHECK-PCH:            "clang-context-hash": "[[HASH_PCH:.*]]",
3783c633eaSJan Svoboda // CHECK-PCH-NEXT:       "clang-module-deps": [
3883c633eaSJan Svoboda // CHECK-PCH-NEXT:         {
3983c633eaSJan Svoboda // CHECK-PCH-NEXT:           "context-hash": "[[HASH_MOD_COMMON]]",
4083c633eaSJan Svoboda // CHECK-PCH-NEXT:           "module-name": "ModCommon"
4183c633eaSJan Svoboda // CHECK-PCH-NEXT:         }
4283c633eaSJan Svoboda // CHECK-PCH-NEXT:       ],
4383c633eaSJan Svoboda // CHECK-PCH-NEXT:       "command-line": [
44be795ee1SJan Svoboda // CHECK-PCH:            ],
4583902c40SBen Langmuir // CHECK-PCH:            "file-deps": [
4683c633eaSJan Svoboda // CHECK-PCH-NEXT:         "[[PREFIX]]/pch.h"
4783c633eaSJan Svoboda // CHECK-PCH-NEXT:       ],
4883c633eaSJan Svoboda // CHECK-PCH-NEXT:       "input-file": "[[PREFIX]]/pch.h"
4983c633eaSJan Svoboda // CHECK-PCH-NEXT:     }
5083c633eaSJan Svoboda 
5183c633eaSJan Svoboda // Explicitly build the PCH:
5283c633eaSJan Svoboda //
5326053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon > %t/mod_common.cc1.rsp
5426053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
5583c633eaSJan Svoboda //
5683c633eaSJan Svoboda // RUN: %clang @%t/mod_common.cc1.rsp
5719017c24SJan Svoboda // RUN: %clang @%t/pch.rsp
5883c633eaSJan Svoboda 
5983c633eaSJan Svoboda // Scan dependencies of the TU:
6083c633eaSJan Svoboda //
6183c633eaSJan Svoboda // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-via-submodule/cdb_tu.json > %t/cdb.json
6283c633eaSJan Svoboda // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
6371e32d5cSJan Svoboda // RUN:   -module-files-dir %t/build > %t/result_tu.json
64c4b13f7aSJan Svoboda // RUN: cat %t/result_tu.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-TU
6583c633eaSJan Svoboda //
66c4b13f7aSJan Svoboda // CHECK-TU:      {
6783c633eaSJan Svoboda // CHECK-TU-NEXT:   "modules": [
6883c633eaSJan Svoboda // CHECK-TU-NEXT:     {
6983c633eaSJan Svoboda // CHECK-TU-NEXT:       "clang-module-deps": [],
7083c633eaSJan Svoboda // CHECK-TU-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
7183c633eaSJan Svoboda // CHECK-TU-NEXT:       "command-line": [
7283c633eaSJan Svoboda // CHECK-TU:            ],
7383c633eaSJan Svoboda // CHECK-TU-NEXT:       "context-hash": "[[HASH_MOD_TU:.*]]",
7483c633eaSJan Svoboda // CHECK-TU-NEXT:       "file-deps": [
75*9d4837f4SJan Svoboda // CHECK-TU-NEXT:         "[[PREFIX]]/module.modulemap",
7683c633eaSJan Svoboda // CHECK-TU-NEXT:         "[[PREFIX]]/mod_tu.h",
77*9d4837f4SJan Svoboda // CHECK-TU-NEXT:         "[[PREFIX]]/mod_tu_sub.h"
7883c633eaSJan Svoboda // CHECK-TU-NEXT:       ],
7968eb3b20SArtem Chikin // CHECK-TU-NEXT:       "link-libraries": [],
8083c633eaSJan Svoboda // CHECK-TU-NEXT:       "name": "ModTU"
8183c633eaSJan Svoboda // CHECK-TU-NEXT:     }
8283c633eaSJan Svoboda // CHECK-TU-NEXT:   ],
8383c633eaSJan Svoboda // CHECK-TU-NEXT:   "translation-units": [
8483c633eaSJan Svoboda // CHECK-TU-NEXT:     {
8583902c40SBen Langmuir // CHECK-TU:            "clang-context-hash": "[[HASH_TU:.*]]",
8683c633eaSJan Svoboda // CHECK-TU-NEXT:       "clang-module-deps": [
8783c633eaSJan Svoboda // CHECK-TU-NEXT:         {
8883c633eaSJan Svoboda // CHECK-TU-NEXT:           "context-hash": "[[HASH_MOD_TU]]"
8983c633eaSJan Svoboda // CHECK-TU-NEXT:           "module-name": "ModTU"
9083c633eaSJan Svoboda // CHECK-TU-NEXT:         }
9183c633eaSJan Svoboda // CHECK-TU-NEXT:       ],
9283c633eaSJan Svoboda // CHECK-TU-NEXT:       "command-line": [
93be795ee1SJan Svoboda // CHECK-TU:            ],
9483902c40SBen Langmuir // CHECK-TU:            "file-deps": [
9583c633eaSJan Svoboda // CHECK-TU-NEXT:         "[[PREFIX]]/tu.c",
96f726da11SFangrui Song // CHECK-TU-NEXT:         "[[PREFIX]]/pch.h.pch"
9783c633eaSJan Svoboda // CHECK-TU-NEXT:       ],
9883c633eaSJan Svoboda // CHECK-TU-NEXT:       "input-file": "[[PREFIX]]/tu.c"
9983c633eaSJan Svoboda // CHECK-TU-NEXT:     }
10083c633eaSJan Svoboda 
10183c633eaSJan Svoboda // Explicitly build the TU:
10283c633eaSJan Svoboda //
10326053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result_tu.json --module-name=ModTU > %t/mod_tu.cc1.rsp
10426053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result_tu.json --tu-index=0 > %t/tu.rsp
10583c633eaSJan Svoboda //
10683c633eaSJan Svoboda // RUN: %clang @%t/mod_tu.cc1.rsp
10719017c24SJan Svoboda // RUN: %clang @%t/tu.rsp
108