@@ -117,6 +117,127 @@ TEST(TBDv3, ReadFile) {
117
117
std::equal (Exports.begin (), Exports.end (), std::begin (TBDv3Symbols)));
118
118
}
119
119
120
+ TEST (TBDv3, ReadMultipleDocuments) {
121
+ static const char TBDv3Inlines[] =
122
+ " --- !tapi-tbd-v3\n "
123
+ " archs: [ armv7, arm64 ]\n "
124
+ " uuids: [ 'armv7: 00000000-0000-0000-0000-000000000000',\n "
125
+ " 'arm64: 11111111-1111-1111-1111-111111111111']\n "
126
+ " platform: ios\n "
127
+ " install-name: Test.dylib\n "
128
+ " current-version: 2.3.4\n "
129
+ " compatibility-version: 1.0\n "
130
+ " swift-abi-version: 1.1\n "
131
+ " parent-umbrella: Umbrella.dylib\n "
132
+ " exports:\n "
133
+ " - archs: [ armv7, arm64 ]\n "
134
+ " allowable-clients: [ clientA ]\n "
135
+ " re-exports: [ /usr/lib/libfoo.dylib,\n "
136
+ " TestInline.dylib ]\n "
137
+ " symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n "
138
+ " objc-classes: [ class1, class2 ]\n "
139
+ " objc-eh-types: [ class1 ]\n "
140
+ " objc-ivars: [ class1._ivar1, class1._ivar2 ]\n "
141
+ " weak-def-symbols: [ _weak1, _weak2 ]\n "
142
+ " thread-local-symbols: [ _tlv1, _tlv3 ]\n "
143
+ " - archs: [ armv7 ]\n "
144
+ " symbols: [ _sym5 ]\n "
145
+ " objc-classes: [ class3 ]\n "
146
+ " objc-ivars: [ class1._ivar3 ]\n "
147
+ " weak-def-symbols: [ _weak3 ]\n "
148
+ " thread-local-symbols: [ _tlv3 ]\n "
149
+ " --- !tapi-tbd-v3\n "
150
+ " archs: [ armv7, arm64 ]\n "
151
+ " uuids: [ 'armv7: 00000000-0000-0000-0000-000000000000',\n "
152
+ " 'arm64: 11111111-1111-1111-1111-111111111111']\n "
153
+ " platform: ios\n "
154
+ " install-name: TestInline.dylib\n "
155
+ " swift-abi-version: 1.1\n "
156
+ " exports:\n "
157
+ " - archs: [ armv7, arm64 ]\n "
158
+ " symbols: [ _sym5, _sym6 ]\n "
159
+ " ...\n " ;
160
+
161
+ auto Result = TextAPIReader::get (MemoryBufferRef (TBDv3Inlines, " Test.tbd" ));
162
+ EXPECT_TRUE (!!Result);
163
+ auto File = std::move (Result.get ());
164
+ EXPECT_EQ (File->documents ().size (), 1U );
165
+ EXPECT_EQ (FileType::TBD_V3, File->getFileType ());
166
+ auto Archs = AK_armv7 | AK_arm64;
167
+ auto Platform = PlatformKind::iOS;
168
+ TargetList Targets;
169
+ for (auto &&arch : Archs)
170
+ Targets.emplace_back (Target (arch, Platform));
171
+ EXPECT_EQ (Archs, File->getArchitectures ());
172
+ UUIDs Uuids = {{Target (AK_armv7, PlatformKind::unknown),
173
+ " 00000000-0000-0000-0000-000000000000" },
174
+ {Target (AK_arm64, PlatformKind::unknown),
175
+ " 11111111-1111-1111-1111-111111111111" }};
176
+ EXPECT_EQ (Uuids, File->uuids ());
177
+ EXPECT_EQ (File->getPlatforms ().size (), 1U );
178
+ EXPECT_EQ (Platform, *File->getPlatforms ().begin ());
179
+ EXPECT_EQ (std::string (" Test.dylib" ), File->getInstallName ());
180
+ EXPECT_EQ (PackedVersion (2 , 3 , 4 ), File->getCurrentVersion ());
181
+ EXPECT_EQ (PackedVersion (1 , 0 , 0 ), File->getCompatibilityVersion ());
182
+ EXPECT_EQ (2U , File->getSwiftABIVersion ());
183
+ EXPECT_EQ (ObjCConstraintType::Retain_Release, File->getObjCConstraint ());
184
+ EXPECT_TRUE (File->isTwoLevelNamespace ());
185
+ EXPECT_TRUE (File->isApplicationExtensionSafe ());
186
+ EXPECT_FALSE (File->isInstallAPI ());
187
+ InterfaceFileRef Client (" clientA" , Targets);
188
+ const std::vector<InterfaceFileRef> Reexports = {
189
+ InterfaceFileRef (" /usr/lib/libfoo.dylib" , Targets),
190
+ InterfaceFileRef (" TestInline.dylib" , Targets)};
191
+ EXPECT_EQ (1U , File->allowableClients ().size ());
192
+ EXPECT_EQ (Client, File->allowableClients ().front ());
193
+ EXPECT_EQ (2U , File->reexportedLibraries ().size ());
194
+ EXPECT_EQ (Reexports, File->reexportedLibraries ());
195
+
196
+ ExportedSymbolSeq Exports;
197
+ for (const auto *Sym : File->symbols ()) {
198
+ EXPECT_FALSE (Sym->isWeakReferenced ());
199
+ EXPECT_FALSE (Sym->isUndefined ());
200
+ Exports.emplace_back (ExportedSymbol{Sym->getKind (), Sym->getName ().str (),
201
+ Sym->isWeakDefined (),
202
+ Sym->isThreadLocalValue ()});
203
+ }
204
+ llvm::sort (Exports.begin (), Exports.end ());
205
+
206
+ EXPECT_EQ (sizeof (TBDv3Symbols) / sizeof (ExportedSymbol), Exports.size ());
207
+ EXPECT_TRUE (
208
+ std::equal (Exports.begin (), Exports.end (), std::begin (TBDv3Symbols)));
209
+
210
+ // Check Second Document
211
+ Exports.clear ();
212
+ auto Document = File->documents ().front ();
213
+ EXPECT_EQ (FileType::TBD_V3, Document->getFileType ());
214
+ EXPECT_EQ (Archs, Document->getArchitectures ());
215
+ EXPECT_EQ (Uuids, Document->uuids ());
216
+ EXPECT_EQ (Platform, *Document->getPlatforms ().begin ());
217
+ EXPECT_EQ (std::string (" TestInline.dylib" ), Document->getInstallName ());
218
+ EXPECT_EQ (PackedVersion (1 , 0 , 0 ), Document->getCurrentVersion ());
219
+ EXPECT_EQ (PackedVersion (1 , 0 , 0 ), Document->getCompatibilityVersion ());
220
+ EXPECT_EQ (2U , Document->getSwiftABIVersion ());
221
+
222
+ for (const auto *Sym : Document->symbols ()) {
223
+ EXPECT_FALSE (Sym->isWeakReferenced ());
224
+ EXPECT_FALSE (Sym->isUndefined ());
225
+ Exports.emplace_back (ExportedSymbol{Sym->getKind (), Sym->getName ().str (),
226
+ Sym->isWeakDefined (),
227
+ Sym->isThreadLocalValue ()});
228
+ }
229
+ llvm::sort (Exports.begin (), Exports.end ());
230
+
231
+ ExportedSymbolSeq DocumentSymbols{
232
+ {SymbolKind::GlobalSymbol, " _sym5" , false , false },
233
+ {SymbolKind::GlobalSymbol, " _sym6" , false , false },
234
+ };
235
+
236
+ EXPECT_EQ (DocumentSymbols.size (), Exports.size ());
237
+ EXPECT_TRUE (
238
+ std::equal (Exports.begin (), Exports.end (), DocumentSymbols.begin ()));
239
+ }
240
+
120
241
TEST (TBDv3, WriteFile) {
121
242
static const char TBDv3File3[] =
122
243
" --- !tapi-tbd-v3\n "
@@ -171,6 +292,87 @@ TEST(TBDv3, WriteFile) {
171
292
EXPECT_STREQ (TBDv3File3, Buffer.c_str ());
172
293
}
173
294
295
+ TEST (TBDv3, WriteMultipleDocuments) {
296
+ static const char TBDv3Inlines[] =
297
+ " --- !tapi-tbd-v3\n "
298
+ " archs: [ i386, x86_64 ]\n "
299
+ " platform: zippered\n "
300
+ " install-name: '/usr/lib/libfoo.dylib'\n "
301
+ " current-version: 1.2.3\n "
302
+ " compatibility-version: 0\n "
303
+ " swift-abi-version: 5\n "
304
+ " exports:\n "
305
+ " - archs: [ x86_64 ]\n "
306
+ " allowable-clients: [ clientA ]\n "
307
+ " re-exports: [ '/usr/lib/libbar.dylib' ]\n "
308
+ " - archs: [ i386, x86_64 ]\n "
309
+ " symbols: [ _sym1 ]\n "
310
+ " objc-classes: [ Class1 ]\n "
311
+ " objc-eh-types: [ Class1 ]\n "
312
+ " objc-ivars: [ Class1._ivar1 ]\n "
313
+ " weak-def-symbols: [ _sym2 ]\n "
314
+ " thread-local-symbols: [ _symA ]\n "
315
+ " --- !tapi-tbd-v3\n "
316
+ " archs: [ i386 ]\n "
317
+ " platform: macosx\n "
318
+ " install-name: '/usr/lib/libbar.dylib'\n "
319
+ " current-version: 0\n "
320
+ " compatibility-version: 0\n "
321
+ " swift-abi-version: 5\n "
322
+ " objc-constraint: none\n "
323
+ " exports:\n "
324
+ " - archs: [ i386 ]\n "
325
+ " symbols: [ _sym3, _sym4 ]\n "
326
+ " ...\n " ;
327
+
328
+ InterfaceFile File;
329
+ TargetList Targets;
330
+ for (auto &&arch : AK_i386 | AK_x86_64) {
331
+ Targets.emplace_back (Target (arch, PlatformKind::macOS));
332
+ Targets.emplace_back (Target (arch, PlatformKind::macCatalyst));
333
+ }
334
+ File.addTargets (Targets);
335
+ File.setPath (" libfoo.dylib" );
336
+ File.setInstallName (" /usr/lib/libfoo.dylib" );
337
+ File.setFileType (FileType::TBD_V3);
338
+ File.setCurrentVersion (PackedVersion (1 , 2 , 3 ));
339
+ File.setTwoLevelNamespace ();
340
+ File.setApplicationExtensionSafe ();
341
+ File.setSwiftABIVersion (5 );
342
+ File.setObjCConstraint (ObjCConstraintType::Retain_Release);
343
+ File.addAllowableClient (" clientA" , Targets[2 ]);
344
+ File.addReexportedLibrary (" /usr/lib/libbar.dylib" , Targets[2 ]);
345
+ File.addSymbol (SymbolKind::GlobalSymbol, " _sym1" , Targets);
346
+ File.addSymbol (SymbolKind::GlobalSymbol, " _sym2" , Targets,
347
+ SymbolFlags::WeakDefined);
348
+ File.addSymbol (SymbolKind::GlobalSymbol, " _symA" , Targets,
349
+ SymbolFlags::ThreadLocalValue);
350
+ File.addSymbol (SymbolKind::ObjectiveCClass, " Class1" , Targets);
351
+ File.addSymbol (SymbolKind::ObjectiveCClassEHType, " Class1" , Targets);
352
+ File.addSymbol (SymbolKind::ObjectiveCInstanceVariable, " Class1._ivar1" ,
353
+ Targets);
354
+
355
+ // Inline document
356
+ InterfaceFile Document;
357
+ Targets = {Target (AK_i386, PlatformKind::macOS)};
358
+ Document.addTargets (Targets);
359
+ Document.setPath (" libbar.dylib" );
360
+ Document.setInstallName (" /usr/lib/libbar.dylib" );
361
+ Document.setFileType (FileType::TBD_V3);
362
+ Document.setTwoLevelNamespace ();
363
+ Document.setApplicationExtensionSafe ();
364
+ Document.setSwiftABIVersion (5 );
365
+ Document.addSymbol (SymbolKind::GlobalSymbol, " _sym3" , Targets);
366
+ Document.addSymbol (SymbolKind::GlobalSymbol, " _sym4" , Targets);
367
+ File.addDocument (std::make_shared<InterfaceFile>(std::move (Document)));
368
+
369
+ SmallString<4096 > Buffer;
370
+ raw_svector_ostream OS (Buffer);
371
+ auto Result = TextAPIWriter::writeToStream (OS, File);
372
+ EXPECT_FALSE (Result);
373
+ EXPECT_STREQ (TBDv3Inlines, Buffer.c_str ());
374
+ }
375
+
174
376
TEST (TBDv3, Platform_macOS) {
175
377
static const char TBDv3PlatformMacOS[] = " --- !tapi-tbd-v3\n "
176
378
" archs: [ x86_64 ]\n "
0 commit comments