-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathbridging-header.swift
275 lines (229 loc) · 12.8 KB
/
bridging-header.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// REQUIRES: objc_interop
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/test.swift -o %t/deps.json -auto-bridging-header-chaining -cache-compile-job -cas-path %t/cas \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap -import-objc-header %t/Bridging.h
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json Test bridgingHeader | %FileCheck %s
// CHECK: "includeTree"
// CHECK-NEXT: "moduleDependencies": [
// CHECK-NEXT: "A"
// CHECK-NEXT: ],
// CHECK-NEXT: "commandLine": [
// CHECK: "-fmodule-format=obj"
// CHECK: "-dwarf-ext-refs"
// CHECK: "-fmodule-file-cache-key",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.pcm",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "llvmcas://{{.*}}",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "-fmodule-file-cache-key",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "{{.*}}{{/|\\}}B-{{.*}}.pcm",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "llvmcas://{{.*}}"
/// Try build then import from a non-caching compilation.
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd
// RUN: %swift_frontend_plain @%t/shim.cmd
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
// RUN: %swift_frontend_plain @%t/B.cmd
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json bridgingHeader > %t/header.cmd
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/bridging.pch
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/bridging.pch > %t/keys.json
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys.json > %t/key
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
// RUN: echo "\"-disable-implicit-string-processing-module-import\"" >> %t/MyApp.cmd
// RUN: echo "\"-disable-implicit-concurrency-module-import\"" >> %t/MyApp.cmd
// RUN: echo "\"-disable-implicit-swift-modules\"" >> %t/MyApp.cmd
// RUN: echo "\"-import-objc-header\"" >> %t/MyApp.cmd
// RUN: echo "\"%t/Bridging.h\"" >> %t/MyApp.cmd
// RUN: echo "\"-import-pch\"" >> %t/MyApp.cmd
// RUN: echo "\"%t/bridging.pch\"" >> %t/MyApp.cmd
// RUN: echo "\"-bridging-header-pch-key\"" >> %t/MyApp.cmd
// RUN: echo "\"@%t/key\"" >> %t/MyApp.cmd
// RUN: echo "\"-explicit-swift-module-map-file\"" >> %t/MyApp.cmd
// RUN: echo "\"@%t/map.casid\"" >> %t/MyApp.cmd
// RUN: %target-swift-frontend -cache-compile-job -module-name Test -O -cas-path %t/cas @%t/MyApp.cmd %t/test.swift \
// RUN: -emit-module -o %t/Test.swiftmodule
/// Importing binary module with bridging header built from CAS from a regluar build.
/// This should succeed even it is also importing a bridging header that shares same header dependencies (with proper header guard).
// RUN: %target-swift-frontend -typecheck -module-name User -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap \
// RUN: -I %t %t/user2.swift -import-objc-header %t/Bridging2.h
/// Importing binary module with bridging header built from CAS from a cached build. This should work without additional bridging header deps.
// RUN: %target-swift-frontend -scan-dependencies -module-name User -module-cache-path %t/clang-module-cache -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/user.swift -o %t/deps2.json -auto-bridging-header-chaining -cache-compile-job -cas-path %t/cas \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap -I %t
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps2.json User chainedBridgingHeaderPath | %FileCheck %s --check-prefix HEADER-PATH
// HEADER-PATH: <compiler-generated>{{/|\\}}User-{{.*}}-ChainedBridgingHeader.h
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps2.json bridgingHeader > %t/header1.cmd
// RUN: %target-swift-frontend @%t/header1.cmd -disable-implicit-swift-modules -O -o %t/bridging1.pch
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend @%t/header1.cmd -disable-implicit-swift-modules -O -o %t/bridging1.pch > %t/keys1.json
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys1.json > %t/key1
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps2.json > %t/map2.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map2.json > %t/map2.casid
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps2.json User > %t/User.cmd
// RUN: %target-swift-frontend -cache-compile-job -module-name User -O -cas-path %t/cas \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -disable-implicit-swift-modules \
// RUN: -import-pch %t/bridging1.pch -bridging-header-pch-key @%t/key1 \
// RUN: -explicit-swift-module-map-file @%t/map2.casid @%t/User.cmd %t/user.swift \
// RUN: -emit-module -o %t/User.swiftmodule
// RUN: llvm-bcanalyzer -dump %t/User.swiftmodule | %FileCheck %s --check-prefix CHECK-NO-HEADER
// CHECK-NO-HEADER-NOT: <IMPORTED_HEADER
/// Importing binary module with bridging header for a cached build while also importing a bridging header.
// RUN: %target-swift-frontend -scan-dependencies -module-name User -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap \
// RUN: -I %t %t/user2.swift -import-objc-header %t/Bridging2.h -cache-compile-job -cas-path %t/cas \
// RUN: -o %t/deps3.json -auto-bridging-header-chaining
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps3.json clang:SwiftShims > %t/shim2.cmd
// RUN: %swift_frontend_plain @%t/shim2.cmd
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps3.json clang:B > %t/B2.cmd
// RUN: %swift_frontend_plain @%t/B2.cmd
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps3.json clang:A > %t/A2.cmd
// RUN: %swift_frontend_plain @%t/A2.cmd
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps3.json bridgingHeader > %t/header2.cmd
// RUN: %target-swift-frontend @%t/header2.cmd -disable-implicit-swift-modules -O -o %t/bridging2.pch
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend @%t/header2.cmd -disable-implicit-swift-modules -O -o %t/bridging2.pch > %t/keys2.json
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys2.json > %t/key2
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps3.json > %t/map3.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map3.json > %t/map3.casid
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps3.json User > %t/User2.cmd
// RUN: echo "\"-import-objc-header\"" >> %t/User2.cmd
// RUN: echo "\"%t/Bridging2.h\"" >> %t/User2.cmd
// RUN: echo "\"-import-pch\"" >> %t/User2.cmd
// RUN: echo "\"%t/bridging2.pch\"" >> %t/User2.cmd
// RUN: echo "\"-bridging-header-pch-key\"" >> %t/User2.cmd
// RUN: echo "\"@%t/key2\"" >> %t/User2.cmd
// RUN: %target-swift-frontend -cache-compile-job -module-name User -O -cas-path %t/cas \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -disable-implicit-swift-modules \
// RUN: -explicit-swift-module-map-file @%t/map3.casid @%t/User2.cmd %t/user2.swift \
// RUN: -emit-module -o %t/User2.swiftmodule
// RUN: %target-swift-frontend -scan-dependencies -module-name User -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap \
// RUN: -I %t %t/user2.swift -import-objc-header %t/Bridging3.h -cache-compile-job -cas-path %t/cas \
// RUN: -o %t/deps4.json -auto-bridging-header-chaining
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps4.json bridgingHeader > %t/header3.cmd
// RUN: %target-swift-frontend @%t/header3.cmd -disable-implicit-swift-modules -O -o %t/bridging3.pch
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend @%t/header3.cmd -disable-implicit-swift-modules -O -o %t/bridging3.pch > %t/keys3.json
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys3.json > %t/key3
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps4.json > %t/map4.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map4.json > %t/map4.casid
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps4.json User > %t/User3.cmd
// RUN: echo "\"-import-pch\"" >> %t/User3.cmd
// RUN: echo "\"%t/bridging3.pch\"" >> %t/User3.cmd
// RUN: echo "\"-import-objc-header\"" >> %t/User3.cmd
// RUN: echo "\"%t/Bridging3.h\"" >> %t/User3.cmd
// RUN: echo "\"-bridging-header-pch-key\"" >> %t/User3.cmd
// RUN: echo "\"@%t/key3\"" >> %t/User3.cmd
// RUN: %target-swift-frontend -cache-compile-job -module-name User -O -cas-path %t/cas \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -disable-implicit-swift-modules \
// RUN: -explicit-swift-module-map-file @%t/map4.casid @%t/User3.cmd %t/user2.swift \
// RUN: -emit-module -o %t/User3.swiftmodule
/// Verify the encoded here is just the `-import-objc-header` option.
// RUN: llvm-bcanalyzer -dump %t/User3.swiftmodule | %FileCheck %s --check-prefix CHECK-HEADER
// CHECK-HEADER: <IMPORTED_HEADER
// CHECK-HEADER-SAME: Bridging3.h
/// Try removing the bridging header and using the embedded header.
// RUN: rm %t/Bridging.h
// RUN: %target-swift-frontend -scan-dependencies -module-name User -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap \
// RUN: -I %t %t/user2.swift -import-objc-header %t/Bridging3.h -cache-compile-job -cas-path %t/cas \
// RUN: -o %t/deps5.json -auto-bridging-header-chaining
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps5.json bridgingHeader > %t/header4.cmd
// RUN: %target-swift-frontend @%t/header4.cmd -disable-implicit-swift-modules -O -o %t/bridging4.pch
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
// RUN: %target-swift-frontend @%t/header4.cmd -disable-implicit-swift-modules -O -o %t/bridging4.pch > %t/keys4.json
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys4.json > %t/key4
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps5.json > %t/map5.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map5.json > %t/map5.casid
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps5.json User > %t/User4.cmd
// RUN: echo "\"-import-pch\"" >> %t/User4.cmd
// RUN: echo "\"%t/bridging4.pch\"" >> %t/User4.cmd
// RUN: echo "\"-import-objc-header\"" >> %t/User4.cmd
// RUN: echo "\"%t/Bridging4.h\"" >> %t/User4.cmd
// RUN: echo "\"-bridging-header-pch-key\"" >> %t/User4.cmd
// RUN: echo "\"@%t/key4\"" >> %t/User4.cmd
// RUN: %target-swift-frontend -cache-compile-job -module-name User -O -cas-path %t/cas \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -disable-implicit-swift-modules \
// RUN: -explicit-swift-module-map-file @%t/map5.casid @%t/User4.cmd %t/user2.swift \
// RUN: -emit-module -o %t/User5.swiftmodule
//--- test.swift
public func test() {
b()
}
public class TestB: B {}
//--- user.swift
import Test
func user() {
var b: TestB
test()
}
extension A {
public func testA() {}
}
//--- user2.swift
import Test
func user() {
var b: TestB
var bridging: Bridging2
test()
}
extension Bridging2 {
public func testA() {}
}
//--- Bridging.h
#include "Foo.h"
#include "Foo2.h"
//--- Bridging2.h
#include "Foo.h"
#include "Foo2.h"
@interface Bridging2
@end
//--- Bridging3.h
@interface Bridging2
@end
//--- Foo.h
#import "a.h"
#ifndef IMPORT_FOO
#define IMPORT_FOO
int Foo = 0;
#endif
//--- Foo2.h
#ifndef IMPORT_FOO2
#define IMPORT_FOO2
int Foo2 = 0;
#endif
//--- a.h
#include "b.h"
struct A {
int a;
};
//--- b.h
void b(void);
@interface B
@end
//--- a.modulemap
module A {
header "a.h"
export *
}
//--- b.modulemap
module B {
header "b.h"
export *
}