xref: /llvm-project/clang/test/ClangScanDeps/modules-context-hash-outputs.c (revision 83902c403611af3a52453867cb8848fb3fd6a39c)
1 // If secondary output files such as .d are enabled, ensure it affects the
2 // module context hash since it may impact the resulting module build commands.
3 
4 // RUN: rm -rf %t
5 // RUN: split-file %s %t
6 // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
7 
8 // RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
9 // RUN:   -format experimental-full > %t/deps.json
10 // RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
11 
12 // CHECK:      {
13 // CHECK-NEXT:   "modules": [
14 // CHECK:          {
15 // CHECK:            "command-line": [
16 // CHECK:              "-dependency-file"
17 // CHECK:            ]
18 // CHECK:            "context-hash": "[[HASH1:.*]]"
19 // CHECK:            "name": "Mod"
20 // CHECK-NEXT:     }
21 // CHECK-NEXT:     {
22 // CHECK:            "command-line": [
23 // CHECK-NOT:          "-dependency-file"
24 // CHECK:            ]
25 // CHECK:            "context-hash": "[[HASH2:.*]]"
26 // CHECK:            "name": "Mod"
27 // CHECK-NEXT:     }
28 // CHECK-NEXT:   ]
29 // CHECK-NEXT:   "translation-units": [
30 // CHECK-NEXT:     {
31 // CHECK:            "clang-module-deps": [
32 // CHECK-NEXT:         {
33 // CHECK-NEXT:           "context-hash": "[[HASH1]]"
34 // CHECK-NEXT:            "module-name": "Mod"
35 // CHECK-NEXT:         }
36 // CHECK-NEXT:       ]
37 // CHECK-NEXT:       "command-line": [
38 // CHECK:              "-dependency-file"
39 // CHECK:            ]
40 // CHECK:            "input-file": "{{.*}}tu1.c"
41 // CHECK-NEXT:     }
42 // CHECK:          {
43 // CHECK:            "clang-module-deps": [
44 // CHECK-NEXT:         {
45 // CHECK-NEXT:           "context-hash": "[[HASH2]]"
46 // CHECK-NEXT:            "module-name": "Mod"
47 // CHECK-NEXT:         }
48 // CHECK-NEXT:       ]
49 // CHECK-NEXT:       "command-line": [
50 // CHECK-NOT:          "-MF"
51 // CHECK-NOT:          "-dependency-file"
52 // CHECK:            ]
53 // CHECK:            "input-file": "{{.*}}tu2.c"
54 
55 //--- cdb.json.template
56 [
57   {
58     "directory": "DIR",
59     "command": "clang -MD -MF DIR/tu1.d -fsyntax-only DIR/tu1.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
60     "file": "DIR/tu1.c"
61   },
62   {
63     "directory": "DIR",
64     "command": "clang -fsyntax-only DIR/tu2.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
65     "file": "DIR/tu2.c"
66   },
67 ]
68 
69 //--- module.modulemap
70 module Mod { header "Mod.h" }
71 
72 //--- Mod.h
73 
74 //--- tu1.c
75 #include "Mod.h"
76 
77 //--- tu2.c
78 #include "Mod.h"
79