render_autoconf_at
Function parameters
Parameters
- step:*Step
- contents:[]const u8
- aw:*std.io.Writer.Allocating
- values:std.StringArrayHashMap(Value)
- src_path:[]const u8
Type definitions in this namespace
Types
Functions in this namespace
Functions
- getOutput
- Deprecated; use `getOutputFile`.
= .config_header
Values
- base_id
- = .config_header
Source
Implementation
fn render_autoconf_at(
step: *Step,
contents: []const u8,
aw: *std.io.Writer.Allocating,
values: std.StringArrayHashMap(Value),
src_path: []const u8,
) !void {
const build = step.owner;
const allocator = build.allocator;
const bw = &aw.writer;
const used = allocator.alloc(bool, values.count()) catch @panic("OOM");
for (used) |*u| u.* = false;
defer allocator.free(used);
var any_errors = false;
var line_index: u32 = 0;
var line_it = std.mem.splitScalar(u8, contents, '\n');
while (line_it.next()) |line| : (line_index += 1) {
const last_line = line_it.index == line_it.buffer.len;
const old_len = aw.written().len;
expand_variables_autoconf_at(bw, line, values, used) catch |err| switch (err) {
error.MissingValue => {
const name = aw.written()[old_len..];
defer aw.shrinkRetainingCapacity(old_len);
try step.addError("{s}:{d}: error: unspecified config header value: '{s}'", .{
src_path, line_index + 1, name,
});
any_errors = true;
continue;
},
else => {
try step.addError("{s}:{d}: unable to substitute variable: error: {s}", .{
src_path, line_index + 1, @errorName(err),
});
any_errors = true;
continue;
},
};
if (!last_line) try bw.writeByte('\n');
}
for (values.unmanaged.entries.slice().items(.key), used) |name, u| {
if (!u) {
try step.addError("{s}: error: config header value unused: '{s}'", .{ src_path, name });
any_errors = true;
}
}
if (any_errors) return error.MakeFailed;
}