From a98d97b76f41128c108fc68ebaa736b5bc81115a Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 25 Jan 2024 11:24:28 +0100 Subject: [PATCH] macho: unify accessLibPath with accessLibPath2 --- src/link/MachO.zig | 53 ++++------------------------------------------ 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 6a170f9ca015..9ace2e3b82fa 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -897,11 +897,11 @@ pub fn resolveLibSystem( if (self.sdk_layout) |sdk_layout| switch (sdk_layout) { .sdk => { const dir = try fs.path.join(arena, &[_][]const u8{ comp.sysroot.?, "usr", "lib" }); - if (try accessLibPath(arena, &test_path, &checked_paths, dir, "libSystem")) break :success; + if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success; }, .vendored => { const dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "darwin" }); - if (try accessLibPath(arena, &test_path, &checked_paths, dir, "libSystem")) break :success; + if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success; }, }; @@ -916,51 +916,6 @@ pub fn resolveLibSystem( }); } -fn accessLibPath( - gpa: Allocator, - test_path: *std.ArrayList(u8), - checked_paths: *std.ArrayList([]const u8), - search_dir: []const u8, - lib_name: []const u8, -) !bool { - const sep = fs.path.sep_str; - - tbd: { - test_path.clearRetainingCapacity(); - try test_path.writer().print("{s}" ++ sep ++ "{s}.tbd", .{ search_dir, lib_name }); - try checked_paths.append(try gpa.dupe(u8, test_path.items)); - fs.cwd().access(test_path.items, .{}) catch |err| switch (err) { - error.FileNotFound => break :tbd, - else => |e| return e, - }; - return true; - } - - dylib: { - test_path.clearRetainingCapacity(); - try test_path.writer().print("{s}" ++ sep ++ "{s}.dylib", .{ search_dir, lib_name }); - try checked_paths.append(try gpa.dupe(u8, test_path.items)); - fs.cwd().access(test_path.items, .{}) catch |err| switch (err) { - error.FileNotFound => break :dylib, - else => |e| return e, - }; - return true; - } - - noextension: { - test_path.clearRetainingCapacity(); - try test_path.writer().print("{s}" ++ sep ++ "{s}", .{ search_dir, lib_name }); - try checked_paths.append(try gpa.dupe(u8, test_path.items)); - fs.cwd().access(test_path.items, .{}) catch |err| switch (err) { - error.FileNotFound => break :noextension, - else => |e| return e, - }; - return true; - } - - return false; -} - const ParseError = error{ MalformedObject, MalformedArchive, @@ -1173,7 +1128,7 @@ fn isHoisted(self: *MachO, install_name: []const u8) bool { return false; } -fn accessLibPath2( +fn accessLibPath( arena: Allocator, test_path: *std.ArrayList(u8), checked_paths: *std.ArrayList([]const u8), @@ -1274,7 +1229,7 @@ fn parseDependentDylibs(self: *MachO) !void { const lib_name = eatPrefix(stem, "lib") orelse stem; for (lib_dirs) |dir| { test_path.clearRetainingCapacity(); - if (try accessLibPath2(arena, &test_path, &checked_paths, dir, lib_name)) break :full_path test_path.items; + if (try accessLibPath(arena, &test_path, &checked_paths, dir, lib_name)) break :full_path test_path.items; } }