Skip to content

Commit d62e7bb

Browse files
committed
macho: unify accessLibPath with accessLibPath2
1 parent dc9b6ec commit d62e7bb

File tree

1 file changed

+4
-49
lines changed

1 file changed

+4
-49
lines changed

src/link/MachO.zig

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,11 @@ pub fn resolveLibSystem(
897897
if (self.sdk_layout) |sdk_layout| switch (sdk_layout) {
898898
.sdk => {
899899
const dir = try fs.path.join(arena, &[_][]const u8{ comp.sysroot.?, "usr", "lib" });
900-
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "libSystem")) break :success;
900+
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
901901
},
902902
.vendored => {
903903
const dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "darwin" });
904-
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "libSystem")) break :success;
904+
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
905905
},
906906
};
907907

@@ -916,51 +916,6 @@ pub fn resolveLibSystem(
916916
});
917917
}
918918

919-
fn accessLibPath(
920-
gpa: Allocator,
921-
test_path: *std.ArrayList(u8),
922-
checked_paths: *std.ArrayList([]const u8),
923-
search_dir: []const u8,
924-
lib_name: []const u8,
925-
) !bool {
926-
const sep = fs.path.sep_str;
927-
928-
tbd: {
929-
test_path.clearRetainingCapacity();
930-
try test_path.writer().print("{s}" ++ sep ++ "{s}.tbd", .{ search_dir, lib_name });
931-
try checked_paths.append(try gpa.dupe(u8, test_path.items));
932-
fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
933-
error.FileNotFound => break :tbd,
934-
else => |e| return e,
935-
};
936-
return true;
937-
}
938-
939-
dylib: {
940-
test_path.clearRetainingCapacity();
941-
try test_path.writer().print("{s}" ++ sep ++ "{s}.dylib", .{ search_dir, lib_name });
942-
try checked_paths.append(try gpa.dupe(u8, test_path.items));
943-
fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
944-
error.FileNotFound => break :dylib,
945-
else => |e| return e,
946-
};
947-
return true;
948-
}
949-
950-
noextension: {
951-
test_path.clearRetainingCapacity();
952-
try test_path.writer().print("{s}" ++ sep ++ "{s}", .{ search_dir, lib_name });
953-
try checked_paths.append(try gpa.dupe(u8, test_path.items));
954-
fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
955-
error.FileNotFound => break :noextension,
956-
else => |e| return e,
957-
};
958-
return true;
959-
}
960-
961-
return false;
962-
}
963-
964919
const ParseError = error{
965920
MalformedObject,
966921
MalformedArchive,
@@ -1173,7 +1128,7 @@ fn isHoisted(self: *MachO, install_name: []const u8) bool {
11731128
return false;
11741129
}
11751130

1176-
fn accessLibPath2(
1131+
fn accessLibPath(
11771132
arena: Allocator,
11781133
test_path: *std.ArrayList(u8),
11791134
checked_paths: *std.ArrayList([]const u8),
@@ -1274,7 +1229,7 @@ fn parseDependentDylibs(self: *MachO) !void {
12741229
const lib_name = eatPrefix(stem, "lib") orelse stem;
12751230
for (lib_dirs) |dir| {
12761231
test_path.clearRetainingCapacity();
1277-
if (try accessLibPath2(arena, &test_path, &checked_paths, dir, lib_name)) break :full_path test_path.items;
1232+
if (try accessLibPath(arena, &test_path, &checked_paths, dir, lib_name)) break :full_path test_path.items;
12781233
}
12791234
}
12801235

0 commit comments

Comments
 (0)