xref: /llvm-project/clang/test/ClangScanDeps/modules-context-hash-module-map-path.c (revision 71e32d5cf0053090aaad62d946fcfd00f1915f26)
1 // Ensure the path to the modulemap input is included in the module context hash
2 // irrespective of other TU command-line arguments, as it effects the canonical
3 // module build command. In this test we use the difference in spelling between
4 // module.modulemap and module.map, but it also applies to situations such as
5 // differences in case-insensitive paths if they are not canonicalized away.
6 
7 // RUN: rm -rf %t
8 // RUN: split-file %s %t
9 // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
10 
11 // RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
12 // RUN:   -format experimental-full > %t/deps.json
13 
14 // RUN: mv %t/module.modulemap %t/module.map
15 // RUN: echo 'AFTER_MOVE' >> %t/deps.json
16 
17 // RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
18 // RUN:   -format experimental-full >> %t/deps.json
19 
20 // RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
21 
22 // CHECK:      {
23 // CHECK-NEXT:   "modules": [
24 // CHECK:          {
25 // CHECK:            "command-line": [
26 // CHECK:              "{{.*}}module.modulemap"
27 // CHECK:            ]
28 // CHECK:            "context-hash": "[[HASH1:.*]]"
29 // CHECK:            "name": "Mod"
30 // CHECK-NEXT:     }
31 // CHECK-NEXT:   ]
32 // CHECK-NEXT:   "translation-units": [
33 // CHECK-NEXT:     {
34 // CHECK:            "clang-module-deps": [
35 // CHECK-NEXT:         {
36 // CHECK-NEXT:           "context-hash": "[[HASH1]]"
37 // CHECK-NEXT:            "module-name": "Mod"
38 // CHECK-NEXT:         }
39 // CHECK-NEXT:       ]
40 // CHECK-LABEL: AFTER_MOVE
41 // CHECK:      {
42 // CHECK-NEXT:   "modules": [
43 // CHECK:          {
44 // CHECK-NOT: [[HASH1]]
45 // CHECK:            "command-line": [
46 // CHECK:              "{{.*}}module.map"
47 // CHECK:            ]
48 // CHECK-NOT: [[HASH1]]
49 // CHECK:            "name": "Mod"
50 // CHECK-NEXT:     }
51 // CHECK-NEXT:   ]
52 // CHECK-NEXT:   "translation-units": [
53 // CHECK-NEXT:     {
54 // CHECK:            "clang-module-deps": [
55 // CHECK-NEXT:         {
56 // CHECK-NEXT:           "context-hash":
57 // CHECK-NOT: [[HASH1]]
58 // CHECK-NEXT:            "module-name": "Mod"
59 // CHECK-NEXT:         }
60 // CHECK-NEXT:       ]
61 
62 //--- cdb.json.template
63 [
64   {
65     "directory": "DIR",
66     "command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
67     "file": "DIR/tu.c"
68   }
69 ]
70 
71 //--- module.modulemap
72 module Mod { header "Mod.h" }
73 
74 //--- Mod.h
75 
76 //--- tu.c
77 #include "Mod.h"
78