@@ -197,42 +197,59 @@ void binary::BinarySerializer::serializeContainer(std::vector<std::pair<clang::M
197
197
this ->finish (container);
198
198
}
199
199
200
- static llvm::ErrorOr<bool > isStaticFramework (clang::Module* framework)
201
- {
200
+ static llvm::ErrorOr<llvm::SmallString<128 >> getFrameworkLib (clang::Module* framework, const std::string& library) {
202
201
using namespace llvm ;
203
- using namespace llvm ::object;
204
202
using namespace llvm ::sys;
205
203
206
- if (framework->LinkLibraries .size () == 0 ) {
207
- return errc::no_such_file_or_directory;
208
- }
209
-
210
- std::string library = framework->LinkLibraries [0 ].Library ;
211
-
212
204
SmallString<128 > path;
213
205
if (!path::is_absolute (library)) {
214
206
path::append (path, framework->Directory ->getName ());
215
207
}
216
208
path::append (path, library);
217
-
209
+
218
210
if (!fs::exists (path)) {
219
211
path.append (" .tbd" );
220
212
if (fs::exists (path)) {
221
213
// A TBD file is a text-based file used by Apple. It contains information about a .DYLIB library.
222
214
// TBD files were introduced in Xcode 7 in September 2015 in order to reduce the size of SDKs
223
215
// that come with Xcode by linking to DYLIB libraries instead of storing the actual, larger DYLIB libraries.
224
- return false ;
216
+ return path ;
225
217
}
226
218
227
219
return errc::no_such_file_or_directory;
228
220
}
221
+
222
+ return path;
223
+ }
224
+
225
+ static llvm::ErrorOr<bool > isStaticFramework (clang::Module* framework)
226
+ {
227
+ using namespace llvm ;
228
+ using namespace llvm ::object;
229
+ using namespace llvm ::sys;
230
+
231
+ llvm::ErrorOr<SmallString<128 >> path = getFrameworkLib (framework, framework->Name );
232
+
233
+ if (path.getError ()) {
234
+ if (framework->LinkLibraries .size () == 0 ) {
235
+ return errc::no_such_file_or_directory;
236
+ }
237
+
238
+ path = getFrameworkLib (framework, framework->LinkLibraries [0 ].Library );
239
+ }
240
+
241
+ if (path.getError ()) {
242
+ return path.getError ();
243
+ } else if (path.get ().endswith (" .tbd" )) {
244
+ return true ;
245
+ }
229
246
230
247
auto isDylib = [](MachOObjectFile* machObjectFile) -> bool {
231
248
uint32_t filetype = (machObjectFile->is64Bit () ? machObjectFile->getHeader64 ().filetype : machObjectFile->getHeader ().filetype );
232
249
return (filetype == MachO::MH_DYLIB || filetype == MachO::MH_DYLIB_STUB || filetype == MachO::MH_DYLINKER);
233
250
};
234
251
235
- if (Expected<OwningBinary<Binary> > binaryOrErr = createBinary (path)) {
252
+ if (Expected<OwningBinary<Binary> > binaryOrErr = createBinary (path. get () )) {
236
253
Binary& binary = *binaryOrErr.get ().getBinary ();
237
254
238
255
if (MachOUniversalBinary* machoBinary = dyn_cast<MachOUniversalBinary>(&binary)) {
0 commit comments