Skip to content

Commit e3288df

Browse files
committed
[clang][cas] Add simple prefix-mapping test for include-tree modules
(cherry picked from commit f796c8f) (cherry picked from commit c2817ea)
1 parent 5d9a934 commit e3288df

File tree

1 file changed

+305
-0
lines changed

1 file changed

+305
-0
lines changed
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
// REQUIRES: ondisk_cas
2+
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t/dir1
5+
// RUN: cp -r %t/dir1 %t/dir2
6+
// RUN: sed "s|DIR|%/t/dir1|g" %t/dir1/cdb.json.template > %t/cdb1.json
7+
// RUN: sed "s|DIR|%/t/dir2|g" %t/dir1/cdb.json.template > %t/cdb2.json
8+
9+
// RUN: clang-scan-deps -compilation-database %t/cdb1.json \
10+
// RUN: -cas-path %t/cas -module-files-dir %t/dir1/outputs \
11+
// RUN: -prefix-map=%t/dir1/outputs=/^modules -prefix-map=%t/dir1=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \
12+
// RUN: -format experimental-include-tree-full -mode preprocess-dependency-directives \
13+
// RUN: > %t/deps.json
14+
15+
// Extract the include-tree commands
16+
// RUN: %deps-to-rsp %t/deps.json --module-name Top > %t/Top.rsp
17+
// RUN: %deps-to-rsp %t/deps.json --module-name Left > %t/Left.rsp
18+
// RUN: %deps-to-rsp %t/deps.json --module-name Right > %t/Right.rsp
19+
// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
20+
21+
// Extract include-tree casids
22+
// RUN: cat %t/Top.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/Top.casid
23+
// RUN: cat %t/Left.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/Left.casid
24+
// RUN: cat %t/Right.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/Right.casid
25+
// RUN: cat %t/tu.rsp | sed -E 's|.*"-fcas-include-tree" "(llvmcas://[[:xdigit:]]+)".*|\1|' > %t/tu.casid
26+
27+
// RUN: echo "MODULE Top" > %t/result.txt
28+
// RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/Top.casid >> %t/result.txt
29+
// RUN: echo "MODULE Left" >> %t/result.txt
30+
// RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/Left.casid >> %t/result.txt
31+
// RUN: echo "MODULE Right" >> %t/result.txt
32+
// RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/Right.casid >> %t/result.txt
33+
// RUN: echo "TRANSLATION UNIT" >> %t/result.txt
34+
// RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/tu.casid >> %t/result.txt
35+
36+
// RUN: FileCheck %s -input-file %t/result.txt -DPREFIX=%/t -check-prefix=NO_PATHS
37+
// NO_PATHS-NOT: [[PREFIX]]
38+
39+
// RUN: cat %t/deps.json >> %t/result.txt
40+
41+
// RUN: FileCheck %s -input-file %t/result.txt -DPREFIX=%/t
42+
43+
// CHECK-LABEL: MODULE Top
44+
// CHECK: <module-includes> llvmcas://{{[[:xdigit:]]+}}
45+
// CHECK: 1:1 <built-in> llvmcas://{{[[:xdigit:]]+}}
46+
// CHECK: 2:1 /^src/Top.h llvmcas://{{[[:xdigit:]]+}}
47+
// CHECK: Module Map:
48+
// CHECK: Top
49+
// CHECK: export *
50+
// CHECK: Files:
51+
// CHECK-NOT: module.modulemap
52+
// CHECK: /^src/Top.h llvmcas://{{[[:xdigit:]]+}}
53+
// CHECK-NOT: module.modulemap
54+
55+
// CHECK-LABEL: MODULE Left
56+
// CHECK: <module-includes> llvmcas://{{[[:xdigit:]]+}}
57+
// CHECK: 1:1 <built-in> llvmcas://{{[[:xdigit:]]+}}
58+
// CHECK: 2:1 /^src/Left.h llvmcas://{{[[:xdigit:]]+}}
59+
// CHECK: 2:1 (Module) Top
60+
// CHECK: Module Map:
61+
// CHECK: Left
62+
// CHECK: export *
63+
// CHECK: Files:
64+
// CHECK-NOT: module.modulemap
65+
// CHECK: /^src/Left.h llvmcas://{{[[:xdigit:]]+}}
66+
// CHECK-NOT: module.modulemap
67+
// CHECK: /^src/Top.h llvmcas://{{[[:xdigit:]]+}}
68+
69+
// CHECK-LABEL: MODULE Right
70+
// CHECK: <module-includes> llvmcas://{{[[:xdigit:]]+}}
71+
// CHECK: 1:1 <built-in> llvmcas://{{[[:xdigit:]]+}}
72+
// CHECK: 2:1 /^src/Right.h llvmcas://{{[[:xdigit:]]+}}
73+
// CHECK: 2:1 (Module) Top
74+
// CHECK: Module Map:
75+
// CHECK: Right
76+
// CHECK: export *
77+
// CHECK: Files:
78+
// CHECK-NOT: module.modulemap
79+
// CHECK: /^src/Right.h llvmcas://{{[[:xdigit:]]+}}
80+
// CHECK-NOT: module.modulemap
81+
// CHECK: /^src/Top.h llvmcas://{{[[:xdigit:]]+}}
82+
83+
// CHECK-LABEL: TRANSLATION UNIT
84+
// CHECK: /^src/tu.m llvmcas://{{[[:xdigit:]]+}}
85+
// CHECK: 1:1 <built-in> llvmcas://{{[[:xdigit:]]+}}
86+
// CHECK: 2:1 (Module) Left
87+
// CHECK: 3:1 (Module) Right
88+
89+
// Note: the modules with explicit imports are imported via parser and are not
90+
// recorded in the include-tree; it's handled entirely by fmodule-map-file,
91+
// fmodule-file, and fmodule-file-cache-key options.
92+
93+
// CHECK-NOT: Module Map
94+
// CHECK: Files:
95+
// CHECK-NOT: module.modulemap
96+
// CHECK: /^src/Left.h llvmcas://{{[[:xdigit:]]+}}
97+
// CHECK: /^src/Top.h llvmcas://{{[[:xdigit:]]+}}
98+
// CHECK: /^src/Right.h llvmcas://{{[[:xdigit:]]+}}
99+
100+
// CHECK: {
101+
// CHECK-NEXT "modules": [
102+
// CHECK-NEXT {
103+
// CHECK: "cas-include-tree-id": "[[LEFT_TREE:llvmcas://[[:xdigit:]]+]]"
104+
// CHECK: "clang-module-deps": [
105+
// CHECK: {
106+
// CHECK: "module-name": "Top"
107+
// CHECK: }
108+
// CHECK-NEXT: ]
109+
// CHECK: "clang-modulemap-file": "[[PREFIX]]/dir1/module.modulemap"
110+
// CHECK: "command-line": [
111+
// CHECK-NEXT: "-cc1"
112+
// CHECK: "-fcas-path"
113+
// CHECK-NEXT: "[[PREFIX]]/cas"
114+
// CHECK-NOT: -fmodule-map-file
115+
// CHECK: "-o"
116+
// CHECK-NEXT: "[[PREFIX]]/dir1/outputs/{{.*}}/Left-{{.*}}.pcm"
117+
// CHECK: "-disable-free"
118+
// CHECK: "-fno-pch-timestamp"
119+
// CHECK: "-fcas-include-tree"
120+
// CHECK-NEXT: "[[LEFT_TREE]]"
121+
// CHECK: "-fcache-compile-job"
122+
// CHECK: "-emit-module"
123+
// CHECK: "-fmodule-file-cache-key"
124+
// CHECK-NEXT: "/^modules/{{.*}}/Top-{{.*}}.pcm"
125+
// CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}"
126+
// CHECK: "-fmodule-file=Top=/^modules/{{.*}}/Top-{{.*}}.pcm"
127+
// CHECK: "-fmodules"
128+
// CHECK: "-fmodule-name=Left"
129+
// CHECK: "-fno-implicit-modules"
130+
// CHECK: ]
131+
// CHECK: "file-deps": [
132+
// CHECK-NEXT: "[[PREFIX]]/dir1/Left.h"
133+
// CHECK-NEXT: "[[PREFIX]]/dir1/module.modulemap"
134+
// CHECK: ]
135+
// CHECK: "name": "Left"
136+
// CHECK: }
137+
// CHECK-NEXT: {
138+
// CHECK: "cas-include-tree-id": "[[RIGHT_TREE:llvmcas://[[:xdigit:]]+]]"
139+
// CHECK: "clang-module-deps": [
140+
// CHECK-NEXT: {
141+
// CHECK: "module-name": "Top"
142+
// CHECK: }
143+
// CHECK-NEXT: ]
144+
// CHECK: "clang-modulemap-file": "[[PREFIX]]/dir1/module.modulemap"
145+
// CHECK: "command-line": [
146+
// CHECK-NEXT: "-cc1"
147+
// CHECK: "-fcas-path"
148+
// CHECK-NEXT: "[[PREFIX]]/cas"
149+
// CHECK-NOT: -fmodule-map-file
150+
// CHECK: "-o"
151+
// CHECK-NEXT: "[[PREFIX]]/dir1/outputs/{{.*}}/Right-{{.*}}.pcm"
152+
// CHECK: "-disable-free"
153+
// CHECK: "-fno-pch-timestamp"
154+
// CHECK: "-fcas-include-tree"
155+
// CHECK-NEXT: "[[RIGHT_TREE]]"
156+
// CHECK: "-fcache-compile-job"
157+
// CHECK: "-emit-module"
158+
// CHECK: "-fmodule-file-cache-key
159+
// CHECK-NEXT: "/^modules/{{.*}}/Top-{{.*}}.pcm"
160+
// CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}"
161+
// CHECK: "-fmodule-file=Top=/^modules/{{.*}}/Top-{{.*}}.pcm"
162+
// CHECK: "-fmodules"
163+
// CHECK: "-fmodule-name=Right"
164+
// CHECK: "-fno-implicit-modules"
165+
// CHECK: ]
166+
// CHECK: "file-deps": [
167+
// CHECK-NEXT: "[[PREFIX]]/dir1/Right.h"
168+
// CHECK-NEXT: "[[PREFIX]]/dir1/module.modulemap"
169+
// CHECK-NEXT: ]
170+
// CHECK: "name": "Right"
171+
// CHECK: }
172+
// CHECK-NEXT: {
173+
// CHECK: "cas-include-tree-id": "[[TOP_TREE:llvmcas://[[:xdigit:]]+]]"
174+
// CHECK: "clang-module-deps": []
175+
// CHECK: "clang-modulemap-file": "[[PREFIX]]/dir1/module.modulemap"
176+
// CHECK: "command-line": [
177+
// CHECK-NEXT: "-cc1"
178+
// CHECK: "-fcas-path"
179+
// CHECK-NEXT: "[[PREFIX]]/cas"
180+
// CHECK: "-o"
181+
// CHECK-NEXT: "[[PREFIX]]/dir1/outputs/{{.*}}/Top-{{.*}}.pcm"
182+
// CHECK: "-disable-free"
183+
// CHECK: "-fno-pch-timestamp"
184+
// CHECK: "-fcas-include-tree"
185+
// CHECK-NEXT: "[[TOP_TREE]]"
186+
// CHECK: "-fcache-compile-job"
187+
// CHECK: "-emit-module"
188+
// CHECK: "-fmodules"
189+
// CHECK: "-fmodule-name=Top"
190+
// CHECK: "-fno-implicit-modules"
191+
// CHECK: ]
192+
// CHECK: "file-deps": [
193+
// CHECK-NEXT: "[[PREFIX]]/dir1/Top.h"
194+
// CHECK-NEXT: "[[PREFIX]]/dir1/module.modulemap"
195+
// CHECK-NEXT: ]
196+
// CHECK: "name": "Top"
197+
// CHECK: }
198+
// CHECK: ]
199+
// CHECK-NEXT: "translation-units": [
200+
// CHECK-NEXT: {
201+
// CHECK-NEXT: "commands": [
202+
// CHECK-NEXT: {
203+
// CHECK: "cas-include-tree-id": "[[TU_TREE:llvmcas://[[:xdigit:]]+]]"
204+
// CHECK: "clang-module-deps": [
205+
// CHECK-NEXT: {
206+
// CHECK: "module-name": "Left"
207+
// CHECK: }
208+
// CHECK-NEXT: {
209+
// CHECK: "module-name": "Right"
210+
// CHECK: }
211+
// CHECK-NEXT: ]
212+
// CHECK: "command-line": [
213+
// CHECK-NEXT: "-cc1"
214+
// CHECK: "-fcas-path"
215+
// CHECK-NEXT: "[[PREFIX]]/cas"
216+
// CHECK-NOT: -fmodule-map-file
217+
// CHECK: "-disable-free"
218+
// CHECK: "-fcas-include-tree"
219+
// CHECK-NEXT: "[[TU_TREE]]"
220+
// CHECK: "-fcache-compile-job"
221+
// CHECK: "-fsyntax-only"
222+
// CHECK: "-fmodule-file-cache-key"
223+
// CHECK-NEXT: "/^modules/{{.*}}/Left-{{.*}}.pcm"
224+
// CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}"
225+
// CHECK: "-fmodule-file-cache-key"
226+
// CHECK-NEXT: "/^modules/{{.*}}/Right-{{.*}}.pcm"
227+
// CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}"
228+
// CHECK: "-fmodule-file=Left=/^modules/{{.*}}/Left-{{.*}}.pcm"
229+
// CHECK: "-fmodule-file=Right=/^modules/{{.*}}/Right-{{.*}}.pcm"
230+
// CHECK: "-fmodules"
231+
// CHECK: "-fno-implicit-modules"
232+
// CHECK: ]
233+
// CHECK: "file-deps": [
234+
// CHECK-NEXT: "[[PREFIX]]/dir1/tu.m"
235+
// CHECK-NEXT: ]
236+
// CHECK: "input-file": "[[PREFIX]]/dir1/tu.m"
237+
// CHECK: }
238+
// CHECK-NEXT: ]
239+
// CHECK-NEXT: }
240+
// CHECK-NEXT: ]
241+
// CHECK-NEXT: }
242+
243+
// Build the include-tree commands
244+
// RUN: %clang @%t/Top.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_MISS
245+
// RUN: %clang @%t/Left.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_MISS
246+
// RUN: %clang @%t/Right.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_MISS
247+
// RUN: %clang @%t/tu.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_MISS
248+
249+
// Scan in a different directory
250+
// RUN: clang-scan-deps -compilation-database %t/cdb2.json \
251+
// RUN: -cas-path %t/cas -module-files-dir %t/dir2/outputs \
252+
// RUN: -prefix-map=%t/dir2/outputs=/^modules -prefix-map=%t/dir2=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \
253+
// RUN: -format experimental-include-tree-full -mode preprocess-dependency-directives \
254+
// RUN: > %t/deps2.json
255+
256+
// RUN: %deps-to-rsp %t/deps2.json --module-name Top > %t/Top2.rsp
257+
// RUN: %deps-to-rsp %t/deps2.json --module-name Left > %t/Left2.rsp
258+
// RUN: %deps-to-rsp %t/deps2.json --module-name Right > %t/Right2.rsp
259+
// RUN: %deps-to-rsp %t/deps2.json --tu-index 0 > %t/tu2.rsp
260+
261+
// Check cache hits
262+
// RUN: %clang @%t/Top2.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_HIT
263+
// RUN: %clang @%t/Left2.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_HIT
264+
// RUN: %clang @%t/Right2.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_HIT
265+
// RUN: %clang @%t/tu2.rsp 2>&1 | FileCheck %s -check-prefix=CACHE_HIT
266+
267+
// CACHE_MISS: compile job cache miss
268+
// CACHE_HIT: compile job cache hit
269+
270+
//--- cdb.json.template
271+
[{
272+
"file": "DIR/tu.m",
273+
"directory": "DIR",
274+
"command": "clang -fsyntax-only DIR/tu.m -I DIR -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache -Rcompile-job-cache"
275+
}]
276+
277+
//--- module.modulemap
278+
module Top { header "Top.h" export *}
279+
module Left { header "Left.h" export *}
280+
module Right { header "Right.h" export *}
281+
282+
//--- Top.h
283+
#pragma once
284+
struct Top {
285+
int x;
286+
};
287+
void top(void);
288+
289+
//--- Left.h
290+
#include "Top.h"
291+
void left(void);
292+
293+
//--- Right.h
294+
#include "Top.h"
295+
void right(void);
296+
297+
//--- tu.m
298+
#import "Left.h"
299+
#import <Right.h>
300+
301+
void tu(void) {
302+
top();
303+
left();
304+
right();
305+
}

0 commit comments

Comments
 (0)