macho: simplify versioning logic for TAPI

This commit is contained in:
Jakub Konka 2021-08-10 18:43:32 +02:00
parent 8afe6210e9
commit d95e8bc5f8
3 changed files with 28 additions and 43 deletions

View File

@ -348,6 +348,8 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_
const arch_string = @tagName(target.cpu.arch);
log.debug("{s}", .{lib_stub.inner[0].installName()});
for (lib_stub.inner) |elem, stub_index| {
const stub = elem.v3;
if (!hasArch(stub.archs, arch_string)) continue;
@ -370,41 +372,28 @@ fn parseFromStubV3(self: *Dylib, allocator: *Allocator, target: std.Target, lib_
}
}
if (exp.objc_classes) |objc_classes| {
for (objc_classes) |class_name| {
try self.addObjCClassSymbols(allocator, class_name);
}
}
if (exp.re_exports) |re_exports| {
for (re_exports) |reexp| {
if (self.symbols.contains(reexp)) continue;
try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, reexp), {});
for (re_exports) |lib| {
if (umbrella_libs.contains(lib)) {
log.debug(" | {s} <= {s}", .{ lib, lib_stub.inner[0].installName() });
continue;
}
log.debug(" | {s}", .{lib});
const dep_id = try Id.default(allocator, lib);
try self.dependent_libs.append(allocator, dep_id);
}
}
}
}
}
log.debug("{s}", .{lib_stub.inner[0].installName()});
// // TODO track which libs were already parsed in different steps
// for (lib_stub.inner) |elem| {
// const stub = elem.v3;
// if (!archMatches(stub.archs, arch_string)) continue;
// if (stub.reexported_libraries) |reexports| {
// for (reexports) |reexp| {
// if (!matcher.matches(reexp.targets)) continue;
// for (reexp.libraries) |lib| {
// if (umbrella_libs.contains(lib)) {
// log.debug(" | {s} <= {s}", .{ lib, umbrella_lib.install_name });
// continue;
// }
// log.debug(" | {s}", .{lib});
// const dep_id = try Id.default(allocator, lib);
// try self.dependent_libs.append(allocator, dep_id);
// }
// }
// }
// }
}
fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 {

View File

@ -19,11 +19,12 @@ pub const TbdV3 = struct {
install_name: []const u8,
current_version: ?VersionField,
compatibility_version: ?VersionField,
objc_constraint: []const u8,
objc_constraint: ?[]const u8,
exports: ?[]const struct {
archs: []const []const u8,
re_exports: ?[]const []const u8,
symbols: ?[]const []const u8,
objc_classes: ?[]const []const u8,
},
};
@ -107,10 +108,8 @@ pub const LibStub = struct {
// TODO clean this up.
lib_stub.inner = blk: {
err: {
const inner = lib_stub.yaml.parse([]TbdV4) catch |err| switch (err) {
error.TypeMismatch => break :err,
else => |e| return e,
};
log.debug("trying to parse as []TbdV4", .{});
const inner = lib_stub.yaml.parse([]TbdV4) catch break :err;
var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, inner.len);
for (inner) |doc, i| {
out[i] = .{ .v4 = doc };
@ -119,25 +118,22 @@ pub const LibStub = struct {
}
err: {
const inner = lib_stub.yaml.parse(TbdV4) catch |err| switch (err) {
error.TypeMismatch => break :err,
else => |e| return e,
};
log.debug("trying to parse as TbdV4", .{});
const inner = lib_stub.yaml.parse(TbdV4) catch break :err;
var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);
out[0] = .{ .v4 = inner };
break :blk out;
}
err: {
const inner = lib_stub.yaml.parse(TbdV3) catch |err| switch (err) {
error.TypeMismatch => break :err,
else => |e| return e,
};
log.debug("trying to parse as TbdV3", .{});
const inner = lib_stub.yaml.parse(TbdV3) catch break :err;
var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, 1);
out[0] = .{ .v3 = inner };
break :blk out;
}
// TODO this is clunky. Perhaps an optional would be better here?
return error.TypeMismatch;
};

View File

@ -371,7 +371,7 @@ pub const Yaml = struct {
}
const unwrapped = value orelse {
log.err("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) });
log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.field_type) });
return error.StructFieldMissing;
};
@field(parsed, field.name) = try self.parseValue(field.field_type, unwrapped);