1 // Check that tracking of VFSs works with PCH.
4 // RUN: split-file %s %t
5 // RUN: sed -e "s|DIR|%/t|g" %t/build/compile-commands-pch.json.in > %t/build/compile-commands-pch.json
6 // RUN: sed -e "s|DIR|%/t|g" %t/build/compile-commands-tu.json.in > %t/build/compile-commands-tu.json
7 // RUN: sed -e "s|DIR|%/t|g" %t/build/compile-commands-tu-no-vfs-error.json.in > %t/build/compile-commands-tu-no-vfs-error.json
8 // RUN: sed -e "s|DIR|%/t|g" %t/build/compile-commands-tu1.json.in > %t/build/compile-commands-tu1.json
9 // RUN: sed -e "s|DIR|%/t|g" %t/build/pch-overlay.yaml.in > %t/build/pch-overlay.yaml
11 // RUN: clang-scan-deps -compilation-database %t/build/compile-commands-pch.json \
12 // RUN: -j 1 -format experimental-full --optimize-args=vfs,header-search > %t/pch-deps.db
13 // RUN: %deps-to-rsp %t/pch-deps.db --module-name=A > %t/A.rsp
14 // RUN: %deps-to-rsp %t/pch-deps.db --module-name=B > %t/B.rsp
15 // RUN: %deps-to-rsp %t/pch-deps.db --tu-index=0 > %t/pch.rsp
16 // RUN: %clang @%t/A.rsp
17 // RUN: %clang @%t/B.rsp
18 // RUN: %clang @%t/pch.rsp
20 // RUN: clang-scan-deps -compilation-database %t/build/compile-commands-tu.json \
21 // RUN: -j 1 -format experimental-full --optimize-args=vfs,header-search > %t/tu-deps.db
22 // RUN: %deps-to-rsp %t/tu-deps.db --module-name=C > %t/C.rsp
23 // RUN: %deps-to-rsp %t/tu-deps.db --tu-index=0 > %t/tu.rsp
24 // RUN: %clang @%t/C.rsp
25 // RUN: %clang @%t/tu.rsp
27 // RUN: not clang-scan-deps -compilation-database %t/build/compile-commands-tu-no-vfs-error.json \
28 // RUN: -j 1 -format experimental-full --optimize-args=vfs,header-search 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
30 // CHECK-ERROR: error: PCH was compiled with different VFS overlay files than are currently in use
31 // CHECK-ERROR: note: current translation unit has no VFS overlays
33 // Next test is to verify that a module that doesn't use the VFS, that depends
34 // on the PCH's A, which does use the VFS, still records that it needs the VFS.
35 // This avoids a fatal error when emitting diagnostics.
37 // RUN: clang-scan-deps -compilation-database %t/build/compile-commands-tu1.json \
38 // RUN: -j 1 -format experimental-full --optimize-args=vfs,header-search > %t/tu1-deps.db
39 // RUN: %deps-to-rsp %t/tu1-deps.db --tu-index=0 > %t/tu1.rsp
41 // RUN: %deps-to-rsp %t/tu1-deps.db --module-name=E > %t/E.rsp
42 // RUN: %deps-to-rsp %t/tu1-deps.db --module-name=D > %t/D.rsp
43 // The build of D depends on B which depend on the prebuilt A. D will only build
44 // if it has A's VFS, as it needs to emit a diagnostic showing the content of A.
45 // RUN: %clang @%t/E.rsp
46 // RUN: %clang @%t/D.rsp -verify
47 // RUN: %clang @%t/tu1.rsp
48 // RUN: cat %t/tu1-deps.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
50 // Check that D has the overlay, but E doesn't.
52 // CHECK-NEXT: "modules": [
54 // CHECK-NEXT: "clang-module-deps": [
56 // CHECK-NEXT: "context-hash": "{{.*}}",
57 // CHECK-NEXT: "module-name": "E"
60 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/D/module.modulemap",
61 // CHECK-NEXT: "command-line": [
62 // CHECK: "-ivfsoverlay"
63 // CHECK-NEXT: "[[PREFIX]]/build/pch-overlay.yaml"
65 // CHECK-NEXT: "context-hash": "{{.*}}",
66 // CHECK-NEXT: "file-deps": [
67 // CHECK-NEXT: "{{.*}}"
68 // CHECK-NEXT: "{{.*}}"
69 // CHECK-NEXT: "{{.*}}"
70 // CHECK-NEXT: "{{.*}}"
75 // CHECK-NEXT: "clang-module-deps": [],
76 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/E/module.modulemap",
77 // CHECK-NEXT: "command-line": [
78 // CHECK-NOT: "-ivfsoverlay"
80 // CHECK-NEXT: "context-hash": "{{.*}}",
81 // CHECK-NEXT: "file-deps": [
82 // CHECK-NEXT: "{{.*}}"
83 // CHECK-NEXT: "{{.*}}"
88 //--- build/compile-commands-pch.json.in
93 "command": "clang -x objective-c-header DIR/pch.h -I DIR/modules/A -I DIR/modules/B -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.pch -ivfsoverlay DIR/build/pch-overlay.yaml",
98 //--- build/compile-commands-tu.json.in
103 "command": "clang -fsyntax-only DIR/tu.m -I DIR/modules/A -I DIR/modules/B -I DIR/modules/C -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o -ivfsoverlay DIR/build/pch-overlay.yaml",
108 //--- build/compile-commands-tu-no-vfs-error.json.in
113 "command": "clang -Wpch-vfs-diff -Werror=pch-vfs-diff -fsyntax-only DIR/tu.m -I DIR/modules/A -I DIR/modules/B -I DIR/modules/C -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o",
118 //--- build/compile-commands-tu1.json.in
123 "command": "clang -fsyntax-only DIR/tu1.m -I DIR/modules/B -I DIR/modules/D -I DIR/modules/E -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu1.o -ivfsoverlay DIR/build/pch-overlay.yaml",
128 //--- build/pch-overlay.yaml.in
132 "case-sensitive":"false",
137 "external-contents":"DIR/build/module.modulemap",
138 "name":"module.modulemap",
142 "external-contents":"DIR/build/A.h",
147 "name":"DIR/modules/A",
156 //--- build/module.modulemap
159 umbrella header "A.h"
164 typedef int A_t __attribute__((deprecated("yep, it's depr")));
166 //--- modules/B/module.modulemap
169 umbrella header "B.h"
178 //--- modules/C/module.modulemap
181 umbrella header "C.h"
197 //--- modules/D/module.modulemap
200 umbrella header "D.h"
208 typedef A_t D_t; // expected-warning{{'A_t' is deprecated}}
209 // expected-note@*:* {{marked deprecated here}}
211 //--- modules/E/module.modulemap
214 umbrella header "E.h"