| ... | @@ -62,7 +62,6 @@ pub fn createAndParseFromPath( | ... | @@ -62,7 +62,6 @@ pub fn createAndParseFromPath( |
| 62 | arch: Arch, | 62 | arch: Arch, |
| 63 | path: []const u8, | 63 | path: []const u8, |
| 64 | syslibroot: ?[]const u8, | 64 | syslibroot: ?[]const u8, |
| 65 | recurse_libs: bool, | | |
| 66 | ) Error!?[]*Dylib { | 65 | ) Error!?[]*Dylib { |
| 67 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { | 66 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { |
| 68 | error.FileNotFound => return null, | 67 | error.FileNotFound => return null, |
| ... | @@ -102,11 +101,9 @@ pub fn createAndParseFromPath( | ... | @@ -102,11 +101,9 @@ pub fn createAndParseFromPath( |
| 102 | | 101 | |
| 103 | var dylibs = std.ArrayList(*Dylib).init(allocator); | 102 | var dylibs = std.ArrayList(*Dylib).init(allocator); |
| 104 | defer dylibs.deinit(); | 103 | defer dylibs.deinit(); |
| 105 | try dylibs.append(dylib); | | |
| 106 | | 104 | |
| 107 | if (recurse_libs) { | 105 | try dylibs.append(dylib); |
| 108 | try dylib.parseDependentLibs(&dylibs); | 106 | try dylib.parseDependentLibs(&dylibs); |
| 109 | } | | |
| 110 | | 107 | |
| 111 | return dylibs.toOwnedSlice(); | 108 | return dylibs.toOwnedSlice(); |
| 112 | } | 109 | } |
| ... | @@ -283,18 +280,17 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void { | ... | @@ -283,18 +280,17 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void { |
| 283 | else => unreachable, | 280 | else => unreachable, |
| 284 | }; | 281 | }; |
| 285 | | 282 | |
| 286 | for (lib_stub.inner) |stub| { | 283 | var umbrella_libs = std.StringHashMap(void).init(self.allocator); |
| 287 | if (!hasTarget(stub.targets, target_string)) continue; | 284 | defer umbrella_libs.deinit(); |
| 288 | | 285 | |
| 289 | if (stub.reexported_libraries) |reexports| { | 286 | for (lib_stub.inner) |stub, stub_index| { |
| 290 | for (reexports) |reexp| { | 287 | if (!hasTarget(stub.targets, target_string)) continue; |
| 291 | if (!hasTarget(reexp.targets, target_string)) continue; | | |
| 292 | | 288 | |
| 293 | try self.dependent_libs.ensureUnusedCapacity(self.allocator, reexp.libraries.len); | 289 | if (stub_index > 0) { |
| 294 | for (reexp.libraries) |lib| { | 290 | // TODO I thought that we could switch on presence of `parent-umbrella` map; |
| 295 | self.dependent_libs.putAssumeCapacity(try self.allocator.dupe(u8, lib), {}); | 291 | // however, turns out `libsystem_notify.dylib` is fully reexported by `libSystem.dylib` |
| 296 | } | 292 | // BUT does not feature a `parent-umbrella` map as the only sublib. Apple's bug perhaps? |
| 297 | } | 293 | try umbrella_libs.put(stub.install_name, .{}); |
| 298 | } | 294 | } |
| 299 | | 295 | |
| 300 | if (stub.exports) |exports| { | 296 | if (stub.exports) |exports| { |
| ... | @@ -341,6 +337,29 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void { | ... | @@ -341,6 +337,29 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void { |
| 341 | } | 337 | } |
| 342 | } | 338 | } |
| 343 | } | 339 | } |
| | 340 | |
| | 341 | log.debug("{s}", .{umbrella_lib.install_name}); |
| | 342 | |
| | 343 | // TODO track which libs were already parsed in different steps |
| | 344 | for (lib_stub.inner) |stub| { |
| | 345 | if (!hasTarget(stub.targets, target_string)) continue; |
| | 346 | |
| | 347 | if (stub.reexported_libraries) |reexports| { |
| | 348 | for (reexports) |reexp| { |
| | 349 | if (!hasTarget(reexp.targets, target_string)) continue; |
| | 350 | |
| | 351 | for (reexp.libraries) |lib| { |
| | 352 | if (umbrella_libs.contains(lib)) { |
| | 353 | log.debug(" | {s} <= {s}", .{ lib, umbrella_lib.install_name }); |
| | 354 | continue; |
| | 355 | } |
| | 356 | |
| | 357 | log.debug(" | {s}", .{lib}); |
| | 358 | try self.dependent_libs.put(self.allocator, try self.allocator.dupe(u8, lib), {}); |
| | 359 | } |
| | 360 | } |
| | 361 | } |
| | 362 | } |
| 344 | } | 363 | } |
| 345 | | 364 | |
| 346 | pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void { | 365 | pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void { |
| ... | @@ -374,7 +393,6 @@ pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void { | ... | @@ -374,7 +393,6 @@ pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void { |
| 374 | self.arch.?, | 393 | self.arch.?, |
| 375 | lib_path, | 394 | lib_path, |
| 376 | self.syslibroot, | 395 | self.syslibroot, |
| 377 | true, | | |
| 378 | )) orelse { | 396 | )) orelse { |
| 379 | continue; | 397 | continue; |
| 380 | }; | 398 | }; |