[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / ClangScanDeps / P1689.cppm
blob24632e25cf7f3bdcf1b5244edaf92a00381b04a0
1 // The slash direction in linux and windows are different.
2 // UNSUPPORTED: system-windows
3 //
4 // RUN: rm -fr %t
5 // RUN: mkdir -p %t
6 // RUN: split-file %s %t
7 //
8 // RUN: sed "s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json
9 // RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
10 // RUN: clang-scan-deps --mode=preprocess-dependency-directives -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
12 // Check the separated dependency format. This is required by CMake for the case
13 // that we have non-exist files in a fresh build and potentially out-of-date after that.
14 // So the build system need to wrtie a compilation database just for scanning purposes,
15 // which is not so good. So here is the per file mode for P1689.
16 // RUN: clang-scan-deps -format=p1689 \
17 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/M.cppm -o %t/M.o \
18 // RUN:   | FileCheck %t/M.cppm -DPREFIX=%/t
19 // RUN: clang-scan-deps -format=p1689 \
20 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/Impl.cpp -o %t/Impl.o \
21 // RUN:   | FileCheck %t/Impl.cpp -DPREFIX=%/t
22 // RUN: clang-scan-deps -format=p1689 \
23 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/impl_part.cppm -o %t/impl_part.o \
24 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
25 // RUN: clang-scan-deps -format=p1689 \
26 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/interface_part.cppm -o %t/interface_part.o \
27 // RUN:   | FileCheck %t/interface_part.cppm -DPREFIX=%/t
28 // RUN: clang-scan-deps -format=p1689 \
29 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/User.cpp -o %t/User.o \
30 // RUN:   | FileCheck %t/User.cpp -DPREFIX=%/t
32 // Check we can generate the make-style dependencies as expected.
33 // RUN: clang-scan-deps -format=p1689 \
34 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/impl_part.cppm -o %t/impl_part.o \
35 // RUN:      -MT %t/impl_part.o.ddi -MD -MF %t/impl_part.dep
36 // RUN:   cat %t/impl_part.dep | FileCheck %t/impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE
38 // Check that we can generate multiple make-style dependency information with compilation database.
39 // RUN: cat %t/P1689.dep | FileCheck %t/Checks.cpp -DPREFIX=%/t --check-prefix=CHECK-MAKE
41 // Check that we can mix the use of -format=p1689 and -fmodules.
42 // RUN: clang-scan-deps -format=p1689 \
43 // RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
44 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
46 // Check the path in the make style dependencies are generated in relative path form
47 // RUN: cd %t
48 // RUN: clang-scan-deps -format=p1689 \
49 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t impl_part.cppm -o impl_part.o \
50 // RUN:      -MT impl_part.o.ddi -MD -MF impl_part.dep
51 // RUN:   cat impl_part.dep | FileCheck impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE-RELATIVE
54 //--- P1689.json.in
57   "directory": "DIR",
58   "command": "clang++ -std=c++20 DIR/M.cppm -c -o DIR/M.o -MT DIR/M.o.ddi -MD -MF DIR/P1689.dep",
59   "file": "DIR/M.cppm",
60   "output": "DIR/M.o"
63   "directory": "DIR",
64   "command": "clang++ -std=c++20 DIR/Impl.cpp -c -o DIR/Impl.o -MT DIR/Impl.o.ddi -MD -MF DIR/P1689.dep",
65   "file": "DIR/Impl.cpp",
66   "output": "DIR/Impl.o"
69   "directory": "DIR",
70   "command": "clang++ -std=c++20 DIR/impl_part.cppm -c -o DIR/impl_part.o -MT DIR/impl_part.o.ddi -MD -MF DIR/P1689.dep",
71   "file": "DIR/impl_part.cppm",
72   "output": "DIR/impl_part.o"
75   "directory": "DIR",
76   "command": "clang++ -std=c++20 DIR/interface_part.cppm -c -o DIR/interface_part.o -MT DIR/interface_part.o.ddi -MD -MF DIR/P1689.dep",
77   "file": "DIR/interface_part.cppm",
78   "output": "DIR/interface_part.o"
81   "directory": "DIR",
82   "command": "clang++ -std=c++20 DIR/User.cpp -c -o DIR/User.o -MT DIR/User.o.ddi -MD -MF DIR/P1689.dep",
83   "file": "DIR/User.cpp",
84   "output": "DIR/User.o"
88 //--- M.cppm
89 export module M;
90 export import :interface_part;
91 import :impl_part;
92 export void Hello();
94 // CHECK: {
95 // CHECK-NEXT:   "revision": 0,
96 // CHECK-NEXT:   "rules": [
97 // CHECK-NEXT:     {
98 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/M.o",
99 // CHECK-NEXT:       "provides": [
100 // CHECK-NEXT:         {
101 // CHECK-NEXT:           "is-interface": true,
102 // CHECK-NEXT:           "logical-name": "M",
103 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
104 // CHECK-NEXT:         }
105 // CHECK-NEXT:       ],
106 // CHECK-NEXT:       "requires": [
107 // CHECK-NEXT:         {
108 // CHECK-NEXT:           "logical-name": "M:interface_part"
109 // CHECK-NEXT:         },
110 // CHECK-NEXT:         {
111 // CHECK-NEXT:           "logical-name": "M:impl_part"
112 // CHECK-NEXT:         }
113 // CHECK-NEXT:       ]
114 // CHECK-NEXT:     }
115 // CHECK-NEXT:   ],
116 // CHECK-NEXT:   "version": 1
117 // CHECK-NEXT: }
119 //--- Impl.cpp
120 module;
121 #include "header.mock"
122 module M;
123 void Hello() {
124     std::cout << "Hello ";
127 // CHECK: {
128 // CHECK-NEXT:   "revision": 0,
129 // CHECK-NEXT:   "rules": [
130 // CHECK-NEXT:     {
131 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/Impl.o",
132 // CHECK-NEXT:       "requires": [
133 // CHECK-NEXT:         {
134 // CHECK-NEXT:           "logical-name": "M"
135 // CHECK-NEXT:         }
136 // CHECK-NEXT:       ]
137 // CHECK-NEXT:     }
138 // CHECK-NEXT:   ],
139 // CHECK-NEXT:   "version": 1
140 // CHECK-NEXT: }
142 //--- impl_part.cppm
143 module;
144 #include "header.mock"
145 module M:impl_part;
146 import :interface_part;
148 std::string W = "World.";
149 void World() {
150     std::cout << W << std::endl;
153 // CHECK: {
154 // CHECK-NEXT:   "revision": 0,
155 // CHECK-NEXT:   "rules": [
156 // CHECK-NEXT:     {
157 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/impl_part.o",
158 // CHECK-NEXT:       "provides": [
159 // CHECK-NEXT:         {
160 // CHECK-NEXT:           "is-interface": false,
161 // CHECK-NEXT:           "logical-name": "M:impl_part",
162 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
163 // CHECK-NEXT:         }
164 // CHECK-NEXT:       ],
165 // CHECK-NEXT:       "requires": [
166 // CHECK-NEXT:         {
167 // CHECK-NEXT:           "logical-name": "M:interface_part"
168 // CHECK-NEXT:         }
169 // CHECK-NEXT:       ]
170 // CHECK-NEXT:     }
171 // CHECK-NEXT:   ],
172 // CHECK-NEXT:   "version": 1
173 // CHECK-NEXT: }
175 // CHECK-MAKE: [[PREFIX]]/impl_part.o.ddi:
176 // CHECK-MAKE:   [[PREFIX]]/impl_part.cppm
177 // CHECK-MAKE:   [[PREFIX]]/header.mock
179 // CHECK-MAKE-RELATIVE: impl_part.o.ddi: impl_part.cppm header.mock
181 //--- interface_part.cppm
182 export module M:interface_part;
183 export void World();
185 // CHECK: {
186 // CHECK-NEXT:   "revision": 0,
187 // CHECK-NEXT:   "rules": [
188 // CHECK-NEXT:     {
189 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/interface_part.o",
190 // CHECK-NEXT:       "provides": [
191 // CHECK-NEXT:         {
192 // CHECK-NEXT:           "is-interface": true,
193 // CHECK-NEXT:           "logical-name": "M:interface_part",
194 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
195 // CHECK-NEXT:         }
196 // CHECK-NEXT:       ]
197 // CHECK-NEXT:     }
198 // CHECK-NEXT:   ],
199 // CHECK-NEXT:   "version": 1
200 // CHECK-NEXT: }
202 //--- User.cpp
203 import M;
204 import third_party_module;
205 int main() {
206     Hello();
207     World();
208     return 0;
211 // CHECK: {
212 // CHECK-NEXT:   "revision": 0,
213 // CHECK-NEXT:   "rules": [
214 // CHECK-NEXT:     {
215 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/User.o",
216 // CHECK-NEXT:       "requires": [
217 // CHECK-NEXT:         {
218 // CHECK-NEXT:           "logical-name": "M"
219 // CHECK-NEXT:         },
220 // CHECK-NEXT:         {
221 // CHECK-NEXT:           "logical-name": "third_party_module"
222 // CHECK-NEXT:         }
223 // CHECK-NEXT:       ]
224 // CHECK-NEXT:     }
225 // CHECK-NEXT:   ],
226 // CHECK-NEXT:   "version": 1
227 // CHECK-NEXT: }
229 //--- Checks.cpp
230 // CHECK: {
231 // CHECK-NEXT:   "revision": 0,
232 // CHECK-NEXT:   "rules": [
233 // CHECK-NEXT:     {
234 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/Impl.o",
235 // CHECK-NEXT:       "requires": [
236 // CHECK-NEXT:         {
237 // CHECK-NEXT:           "logical-name": "M",
238 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
239 // CHECK-NEXT:         }
240 // CHECK-NEXT:       ]
241 // CHECK-NEXT:     },
242 // CHECK-NEXT:     {
243 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/M.o",
244 // CHECK-NEXT:       "provides": [
245 // CHECK-NEXT:         {
246 // CHECK-NEXT:           "is-interface": true,
247 // CHECK-NEXT:           "logical-name": "M",
248 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
249 // CHECK-NEXT:         }
250 // CHECK-NEXT:       ],
251 // CHECK-NEXT:       "requires": [
252 // CHECK-NEXT:         {
253 // CHECK-NEXT:           "logical-name": "M:interface_part",
254 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
255 // CHECK-NEXT:         },
256 // CHECK-NEXT:         {
257 // CHECK-NEXT:           "logical-name": "M:impl_part",
258 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
259 // CHECK-NEXT:         }
260 // CHECK-NEXT:       ]
261 // CHECK-NEXT:     },
262 // CHECK-NEXT:     {
263 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/User.o",
264 // CHECK-NEXT:       "requires": [
265 // CHECK-NEXT:         {
266 // CHECK-NEXT:           "logical-name": "M",
267 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
268 // CHECK-NEXT:         },
269 // CHECK-NEXT:         {
270 // CHECK-NEXT:           "logical-name": "third_party_module"
271 // CHECK-NEXT:         }
272 // CHECK-NEXT:       ]
273 // CHECK-NEXT:     },
274 // CHECK-NEXT:     {
275 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/impl_part.o",
276 // CHECK-NEXT:       "provides": [
277 // CHECK-NEXT:         {
278 // CHECK-NEXT:           "is-interface": false,
279 // CHECK-NEXT:           "logical-name": "M:impl_part",
280 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
281 // CHECK-NEXT:         }
282 // CHECK-NEXT:       ],
283 // CHECK-NEXT:       "requires": [
284 // CHECK-NEXT:         {
285 // CHECK-NEXT:           "logical-name": "M:interface_part",
286 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
287 // CHECK-NEXT:         }
288 // CHECK-NEXT:       ]
289 // CHECK-NEXT:     },
290 // CHECK-NEXT:     {
291 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/interface_part.o",
292 // CHECK-NEXT:       "provides": [
293 // CHECK-NEXT:         {
294 // CHECK-NEXT:           "is-interface": true,
295 // CHECK-NEXT:           "logical-name": "M:interface_part",
296 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
297 // CHECK-NEXT:         }
298 // CHECK-NEXT:       ]
299 // CHECK-NEXT:     }
300 // CHECK-NEXT:   ],
301 // CHECK-NEXT:   "version": 1
302 // CHECK-NEXT: }
304 // CHECK-MAKE-DAG: [[PREFIX]]/impl_part.o.ddi: \
305 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/impl_part.cppm \
306 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
307 // CHECK-MAKE-DAG: [[PREFIX]]/interface_part.o.ddi: \
308 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/interface_part.cppm
309 // CHECK-MAKE-DAG: [[PREFIX]]/M.o.ddi: \
310 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/M.cppm
311 // CHECK-MAKE-DAG: [[PREFIX]]/User.o.ddi: \
312 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/User.cpp
313 // CHECK-MAKE-DAG: [[PREFIX]]/Impl.o.ddi: \
314 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/Impl.cpp \
315 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
317 //--- module.modulemap
318 module Mock { header "header.mock" }
320 //--- header.mock