Skip to content

Commit 4b86c62

Browse files
jansvoboda11cyndyishida
authored andcommitted
[clang][deps][cas] CAS test for llvm#138920
In addition to the dependency issue described in llvm#138920, not rebuilding an implicit module when its explicitly-built dependency got out of date made us use stale include-tree of the implicitly-built module, which caused file content conflicts and the "file changed during build" error message. rdar://150230022
1 parent 4159815 commit 4b86c62

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// Test that modifications to a common header (imported from both a PCH and a TU)
2+
// cause rebuilds of dependent modules imported from the TU on incremental build.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
//--- module.modulemap
8+
module mod_common { header "mod_common.h" }
9+
module mod_tu { header "mod_tu.h" }
10+
module mod_tu_extra { header "mod_tu_extra.h" }
11+
12+
//--- mod_common.h
13+
#define MOD_COMMON_MACRO 0
14+
//--- mod_tu.h
15+
#include "mod_common.h"
16+
#if MOD_COMMON_MACRO
17+
#include "mod_tu_extra.h"
18+
#endif
19+
20+
//--- mod_tu_extra.h
21+
22+
//--- prefix.h
23+
#include "mod_common.h"
24+
25+
//--- tu.c
26+
#include "mod_tu.h"
27+
28+
// Clean: scan the PCH.
29+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_pch_clean.json -- \
30+
// RUN: %clang -x c-header %t/prefix.h -o %t/prefix.h.pch -F %t \
31+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
32+
33+
// Clean: build the PCH.
34+
// RUN: %deps-to-rsp %t/deps_pch_clean.json --module-name mod_common > %t/mod_common.rsp
35+
// RUN: %deps-to-rsp %t/deps_pch_clean.json --tu-index 0 > %t/pch.rsp
36+
// RUN: %clang @%t/mod_common.rsp
37+
// RUN: %clang @%t/pch.rsp
38+
39+
// Clean: scan the TU.
40+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_tu_clean.json -- \
41+
// RUN: %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h -F %t \
42+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
43+
// RUN: cat %t/deps_tu_clean.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-TU-CLEAN -DPREFIX=%/t
44+
// CHECK-TU-CLEAN: {
45+
// CHECK-TU-CLEAN-NEXT: "modules": [
46+
// CHECK-TU-CLEAN-NEXT: {
47+
// CHECK-TU-CLEAN-NEXT: "cache-key": "llvmcas://{{.*}}",
48+
// CHECK-TU-CLEAN-NEXT: "cas-include-tree-id": "llvmcas://{{.*}}",
49+
// CHECK-TU-CLEAN-NEXT: "clang-module-deps": [],
50+
// CHECK-TU-CLEAN-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
51+
// CHECK-TU-CLEAN-NEXT: "command-line": [
52+
// CHECK-TU-CLEAN: ],
53+
// CHECK-TU-CLEAN-NEXT: "context-hash": "{{.*}}",
54+
// CHECK-TU-CLEAN-NEXT: "file-deps": [
55+
// CHECK-TU-CLEAN-NEXT: "[[PREFIX]]/module.modulemap",
56+
// CHECK-TU-CLEAN-NEXT: "[[PREFIX]]/mod_tu.h"
57+
// CHECK-TU-CLEAN-NEXT: ],
58+
// CHECK-TU-CLEAN-NEXT: "link-libraries": [],
59+
// CHECK-TU-CLEAN-NEXT: "name": "mod_tu"
60+
// CHECK-TU-CLEAN-NEXT: }
61+
// CHECK-TU-CLEAN-NEXT: ],
62+
// CHECK-TU-CLEAN-NEXT: "translation-units": [
63+
// CHECK-TU-CLEAN-NEXT: {
64+
// CHECK-TU-CLEAN-NEXT: "commands": [
65+
// CHECK-TU-CLEAN-NEXT: {
66+
// CHECK-TU-CLEAN-NEXT: "cache-key": "llvmcas://{{.*}}",
67+
// CHECK-TU-CLEAN-NEXT: "cas-include-tree-id": "llvmcas://{{.*}}",
68+
// CHECK-TU-CLEAN-NEXT: "clang-context-hash": "{{.*}}",
69+
// CHECK-TU-CLEAN-NEXT: "clang-module-deps": [
70+
// CHECK-TU-CLEAN-NEXT: {
71+
// CHECK-TU-CLEAN-NEXT: "context-hash": "{{.*}}",
72+
// CHECK-TU-CLEAN-NEXT: "module-name": "mod_tu"
73+
// CHECK-TU-CLEAN-NEXT: }
74+
// CHECK-TU-CLEAN-NEXT: ],
75+
// CHECK-TU-CLEAN-NEXT: "command-line": [
76+
// CHECK-TU-CLEAN: ],
77+
// CHECK-TU-CLEAN-NEXT: "executable": "{{.*}}",
78+
// CHECK-TU-CLEAN-NEXT: "file-deps": [
79+
// CHECK-TU-CLEAN-NEXT: "[[PREFIX]]/tu.c",
80+
// CHECK-TU-CLEAN-NEXT: "[[PREFIX]]/prefix.h.pch"
81+
// CHECK-TU-CLEAN-NEXT: ],
82+
// CHECK-TU-CLEAN-NEXT: "input-file": "[[PREFIX]]/tu.c"
83+
// CHECK-TU-CLEAN-NEXT: }
84+
// CHECK-TU-CLEAN-NEXT: ]
85+
// CHECK-TU-CLEAN-NEXT: }
86+
// CHECK-TU-CLEAN: ]
87+
// CHECK-TU-CLEAN: }
88+
89+
// Clean: build the TU.
90+
// RUN: %deps-to-rsp %t/deps_tu_clean.json --module-name mod_tu > %t/mod_tu.rsp
91+
// RUN: %deps-to-rsp %t/deps_tu_clean.json --tu-index 0 > %t/tu.rsp
92+
// RUN: %clang @%t/mod_tu.rsp
93+
// RUN: %clang @%t/tu.rsp
94+
95+
// Incremental: modify the common module.
96+
// RUN: sleep 1
97+
// RUN: echo "#define MOD_COMMON_MACRO 1" > %t/mod_common.h
98+
99+
// Incremental: scan the PCH.
100+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_pch_incremental.json -- \
101+
// RUN: %clang -x c-header %t/prefix.h -o %t/prefix.h.pch -F %t \
102+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
103+
104+
// Incremental: build the PCH.
105+
// RUN: %deps-to-rsp %t/deps_pch_incremental.json --module-name mod_common > %t/mod_common.rsp
106+
// RUN: %deps-to-rsp %t/deps_pch_incremental.json --tu-index 0 > %t/pch.rsp
107+
// RUN: %clang @%t/mod_common.rsp
108+
// RUN: %clang @%t/pch.rsp
109+
110+
// Incremental: scan the TU. This needs to invalidate modules imported from the
111+
// TU that depend on modules imported from the PCH and discover the
112+
// new dependency on 'mod_tu_extra'.
113+
// RUN: clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -o %t/deps_tu_incremental.json -- \
114+
// RUN: %clang -c %t/tu.c -o %t/tu.o -include %t/prefix.h -F %t \
115+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache
116+
// RUN: cat %t/deps_tu_incremental.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-TU-INCREMENTAL -DPREFIX=%/t
117+
// CHECK-TU-INCREMENTAL: {
118+
// CHECK-TU-INCREMENTAL-NEXT: "modules": [
119+
// CHECK-TU-INCREMENTAL-NEXT: {
120+
// CHECK-TU-INCREMENTAL-NEXT: "cache-key": "llvmcas://{{.*}}",
121+
// CHECK-TU-INCREMENTAL-NEXT: "cas-include-tree-id": "llvmcas://{{.*}}",
122+
// CHECK-TU-INCREMENTAL-NEXT: "clang-module-deps": [
123+
// CHECK-TU-INCREMENTAL-NEXT: {
124+
// CHECK-TU-INCREMENTAL-NEXT: "context-hash": "{{.*}}",
125+
// CHECK-TU-INCREMENTAL-NEXT: "module-name": "mod_tu_extra"
126+
// CHECK-TU-INCREMENTAL-NEXT: }
127+
// CHECK-TU-INCREMENTAL-NEXT: ],
128+
// CHECK-TU-INCREMENTAL-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
129+
// CHECK-TU-INCREMENTAL-NEXT: "command-line": [
130+
// CHECK-TU-INCREMENTAL: ],
131+
// CHECK-TU-INCREMENTAL-NEXT: "context-hash": "{{.*}}",
132+
// CHECK-TU-INCREMENTAL-NEXT: "file-deps": [
133+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/module.modulemap",
134+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/mod_tu.h"
135+
// CHECK-TU-INCREMENTAL-NEXT: ],
136+
// CHECK-TU-INCREMENTAL-NEXT: "link-libraries": [],
137+
// CHECK-TU-INCREMENTAL-NEXT: "name": "mod_tu"
138+
// CHECK-TU-INCREMENTAL-NEXT: },
139+
// CHECK-TU-INCREMENTAL-NEXT: {
140+
// CHECK-TU-INCREMENTAL-NEXT: "cache-key": "llvmcas://{{.*}}",
141+
// CHECK-TU-INCREMENTAL-NEXT: "cas-include-tree-id": "llvmcas://{{.*}}",
142+
// CHECK-TU-INCREMENTAL-NEXT: "clang-module-deps": [],
143+
// CHECK-TU-INCREMENTAL-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
144+
// CHECK-TU-INCREMENTAL-NEXT: "command-line": [
145+
// CHECK-TU-INCREMENTAL: ],
146+
// CHECK-TU-INCREMENTAL-NEXT: "context-hash": "{{.*}}",
147+
// CHECK-TU-INCREMENTAL-NEXT: "file-deps": [
148+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/module.modulemap",
149+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/mod_tu_extra.h"
150+
// CHECK-TU-INCREMENTAL-NEXT: ],
151+
// CHECK-TU-INCREMENTAL-NEXT: "link-libraries": [],
152+
// CHECK-TU-INCREMENTAL-NEXT: "name": "mod_tu_extra"
153+
// CHECK-TU-INCREMENTAL-NEXT: }
154+
// CHECK-TU-INCREMENTAL-NEXT: ],
155+
// CHECK-TU-INCREMENTAL-NEXT: "translation-units": [
156+
// CHECK-TU-INCREMENTAL-NEXT: {
157+
// CHECK-TU-INCREMENTAL-NEXT: "commands": [
158+
// CHECK-TU-INCREMENTAL-NEXT: {
159+
// CHECK-TU-INCREMENTAL-NEXT: "cache-key": "llvmcas://{{.*}}",
160+
// CHECK-TU-INCREMENTAL-NEXT: "cas-include-tree-id": "llvmcas://{{.*}}",
161+
// CHECK-TU-INCREMENTAL-NEXT: "clang-context-hash": "{{.*}}",
162+
// CHECK-TU-INCREMENTAL-NEXT: "clang-module-deps": [
163+
// CHECK-TU-INCREMENTAL-NEXT: {
164+
// CHECK-TU-INCREMENTAL-NEXT: "context-hash": "{{.*}}",
165+
// CHECK-TU-INCREMENTAL-NEXT: "module-name": "mod_tu"
166+
// CHECK-TU-INCREMENTAL-NEXT: }
167+
// CHECK-TU-INCREMENTAL-NEXT: ],
168+
// CHECK-TU-INCREMENTAL-NEXT: "command-line": [
169+
// CHECK-TU-INCREMENTAL: ],
170+
// CHECK-TU-INCREMENTAL-NEXT: "executable": "{{.*}}",
171+
// CHECK-TU-INCREMENTAL-NEXT: "file-deps": [
172+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/tu.c",
173+
// CHECK-TU-INCREMENTAL-NEXT: "[[PREFIX]]/prefix.h.pch"
174+
// CHECK-TU-INCREMENTAL-NEXT: ],
175+
// CHECK-TU-INCREMENTAL-NEXT: "input-file": "[[PREFIX]]/tu.c"
176+
// CHECK-TU-INCREMENTAL-NEXT: }
177+
// CHECK-TU-INCREMENTAL-NEXT: ]
178+
// CHECK-TU-INCREMENTAL-NEXT: }
179+
// CHECK-TU-INCREMENTAL: ]
180+
// CHECK-TU-INCREMENTAL: }
181+
182+
// Incremental: build the TU.
183+
// RUN: %deps-to-rsp %t/deps_tu_incremental.json --module-name mod_tu_extra > %t/mod_tu_extra.rsp
184+
// RUN: %deps-to-rsp %t/deps_tu_incremental.json --module-name mod_tu > %t/mod_tu.rsp
185+
// RUN: %deps-to-rsp %t/deps_tu_incremental.json --tu-index 0 > %t/tu.rsp
186+
// RUN: %clang @%t/mod_tu_extra.rsp
187+
// RUN: %clang @%t/mod_tu.rsp
188+
// RUN: %clang @%t/tu.rsp

0 commit comments

Comments
 (0)