Debian Codegraph @

clang/test/ClangScanDeps/modules-header-sharing.m

raw
1 // There are some edge-cases where Clang depends on knowing the module whose implementation it's currently building.
2 // This test makes sure scanner always reports the corresponding module map.
3
4 // RUN: rm -rf %t
5 // RUN: split-file %s %t
6
7 //--- frameworks/A.framework/Modules/module.modulemap
8 framework module A { umbrella header "A.h" }
9 //--- frameworks/B.framework/Modules/module.modulemap
10 framework module B { umbrella header "B.h" }
11 //--- frameworks/A.framework/Headers/A.h
12 //--- frameworks/B.framework/Headers/B.h
13 //--- frameworks/A.framework/Modules/module.private.modulemap
14 framework module A_Private { umbrella header "A_Private.h" }
15 //--- frameworks/B.framework/Modules/module.private.modulemap
16 framework module B_Private { umbrella header "B_Private.h" }
17 //--- frameworks/A.framework/PrivateHeaders/A_Private.h
18 #import <A/H.h>
19 //--- frameworks/B.framework/PrivateHeaders/B_Private.h
20 #import <B/H.h>
21
22 //--- shared/H.h
23
24 //--- overlay.json.template
25 {
26 "case-sensitive": "false",
27 "version": 0,
28 "roots": [
29 {
30 "contents": [
31 {
32 "external-contents": "DIR/shared/H.h",
33 "name": "H.h",
34 "type": "file"
35 }
36 ],
37 "name": "DIR/frameworks/A.framework/PrivateHeaders",
38 "type": "directory"
39 },
40 {
41 "contents": [
42 {
43 "external-contents": "DIR/shared/H.h",
44 "name": "H.h",
45 "type": "file"
46 }
47 ],
48 "name": "DIR/frameworks/B.framework/PrivateHeaders",
49 "type": "directory"
50 }
51 ]
52 }
53
54 //--- cdb.json.template
55 [{
56 "file": "DIR/tu.m",
57 "directory": "DIR",
58 "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fmodule-name=A -ivfsoverlay DIR/overlay.json -F DIR/frameworks -c DIR/tu.m -o DIR/tu.o"
59 }]
60
61 //--- tu.m
62 @import B;
63 #import <A/H.h>
64 #import <B/H.h>
65
66 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
67 // RUN: sed -e "s|DIR|%/t|g" %t/overlay.json.template > %t/overlay.json
68
69 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
70 // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
71 // CHECK: {
72 // CHECK: "translation-units": [
73 // CHECK-NEXT: {
74 // CHECK-NEXT: "commands": [
75 // CHECK: {
76 // CHECK: "command-line": [
77 // CHECK: "-fmodule-map-file=[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap",
78 // CHECK: "-fmodule-name=A",
79 // CHECK: ],
80 // CHECK: "file-deps": [
81 // CHECK-NEXT: "[[PREFIX]]/tu.m",
82 // CHECK-NEXT: "[[PREFIX]]/shared/H.h",
83 // CHECK-NEXT: "[[PREFIX]]/overlay.json",
84 // CHECK-NEXT: "[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap"
85 // CHECK-NEXT: ],
86 // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m"
87 // CHECK-NEXT: }
88 // CHECK: ]
89 // CHECK: }
90
91 // RUN: %deps-to-rsp %t/result.json --module-name=B > %t/B.cc1.rsp
92 // RUN: %clang @%t/B.cc1.rsp
93
94 // RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp
95 // RUN: %clang @%t/tu.rsp