cleanup processPkgConfig

This commit is contained in:
Lee Cannon 2022-09-27 19:49:59 +01:00
parent 137edcd527
commit 58d8c1434d
No known key found for this signature in database
GPG Key ID: 983D5E5CC5E1401F

View File

@ -150,9 +150,7 @@ fn processIncludeDirs(
else => continue,
};
if (include_dirs.contains(candidate)) continue;
include_dirs.putAssumeCapacityNoClobber(candidate, {});
include_dirs.putAssumeCapacity(candidate, {});
}
}
@ -162,20 +160,12 @@ fn processPkgConfig(
exe: *std.build.LibExeObjStep,
) !void {
for (exe.link_objects.items) |link_object| {
switch (link_object) {
.system_lib => |system_lib| {
switch (system_lib.use_pkg_config) {
.no => {},
.yes, .force => {
if (exe.runPkgConfig(system_lib.name)) |args| {
for (args) |arg| {
if (std.mem.startsWith(u8, arg, "-I")) {
const candidate = arg[2..];
if (include_dirs.contains(candidate)) continue;
try include_dirs.putNoClobber(allocator, candidate, {});
}
}
} else |err| switch (err) {
if (link_object != .system_lib) continue;
const system_lib = link_object.system_lib;
if (system_lib.use_pkg_config == .no) continue;
getPkgConfigIncludes(allocator, include_dirs, exe, system_lib.name) catch |err| switch (err) {
error.PkgConfigInvalidOutput,
error.PkgConfigCrashed,
error.PkgConfigFailed,
@ -190,15 +180,25 @@ fn processPkgConfig(
},
.no => unreachable,
},
else => |e| return e,
}
},
}
},
else => {},
};
}
}
fn getPkgConfigIncludes(
allocator: std.mem.Allocator,
include_dirs: *std.StringArrayHashMapUnmanaged(void),
exe: *std.build.LibExeObjStep,
name: []const u8,
) !void {
if (exe.runPkgConfig(name)) |args| {
for (args) |arg| {
if (std.mem.startsWith(u8, arg, "-I")) {
const candidate = arg[2..];
try include_dirs.put(allocator, candidate, {});
}
}
} else |err| return err;
}
fn runBuild(builder: *Builder) anyerror!void {