Merge pull request #22941 from Techatrix/config-header

std.Build.Step.ConfigHeader: improve handling of autoconf style headers
This commit is contained in:
Andrew Kelley
2025-02-22 00:25:09 -05:00
committed by GitHub
5 changed files with 88 additions and 8 deletions

View File

@@ -131,7 +131,7 @@ fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: ty
.comptime_int => {
try config_header.values.put(field_name, .{ .int = v });
},
.enum_literal => {
.@"enum", .enum_literal => {
try config_header.values.put(field_name, .{ .ident = @tagName(v) });
},
.optional => {
@@ -264,8 +264,11 @@ fn render_autoconf(
values: std.StringArrayHashMap(Value),
src_path: []const u8,
) !void {
var values_copy = try values.clone();
defer values_copy.deinit();
const build = step.owner;
const allocator = build.allocator;
var is_used: std.DynamicBitSetUnmanaged = try .initEmpty(allocator, values.count());
defer is_used.deinit(allocator);
var any_errors = false;
var line_index: u32 = 0;
@@ -283,19 +286,21 @@ fn render_autoconf(
try output.appendSlice("\n");
continue;
}
const name = it.rest();
const kv = values_copy.fetchSwapRemove(name) orelse {
const name = it.next().?;
const index = values.getIndex(name) orelse {
try step.addError("{s}:{d}: error: unspecified config header value: '{s}'", .{
src_path, line_index + 1, name,
});
any_errors = true;
continue;
};
try renderValueC(output, name, kv.value);
is_used.set(index);
try renderValueC(output, name, values.values()[index]);
}
for (values_copy.keys()) |name| {
try step.addError("{s}: error: config header value unused: '{s}'", .{ src_path, name });
var unused_value_it = is_used.iterator(.{ .kind = .unset });
while (unused_value_it.next()) |index| {
try step.addError("{s}: error: config header value unused: '{s}'", .{ src_path, values.keys()[index] });
any_errors = true;
}