forked from mirror/vulkan-zig
Update to new zig render API
This commit is contained in:
@@ -60,15 +60,22 @@ pub fn main() !void {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const out_file = cwd.createFile(out_path, .{}) catch |err| {
|
|
||||||
try stderr.writer().print("Error: Failed to create output file '{s}' ({s})\n", .{ out_path, @errorName(err) });
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
defer out_file.close();
|
|
||||||
|
|
||||||
var out_buffer = std.ArrayList(u8).init(allocator);
|
var out_buffer = std.ArrayList(u8).init(allocator);
|
||||||
try generate(allocator, xml_src, out_buffer.writer());
|
try generate(allocator, xml_src, out_buffer.writer());
|
||||||
const tree = try std.zig.parse(allocator, out_buffer.items);
|
|
||||||
|
|
||||||
_ = try std.zig.render(allocator, out_file.writer(), tree);
|
const tree = try std.zig.parse(allocator, out_buffer.items);
|
||||||
|
const formatted = try tree.render(allocator);
|
||||||
|
defer allocator.free(formatted);
|
||||||
|
|
||||||
|
if (std.fs.path.dirname(out_path)) |dir| {
|
||||||
|
cwd.makePath(dir) catch |err| {
|
||||||
|
try stderr.writer().print("Error: Failed to create output directory '{s}' ({s})\n", .{ dir, @errorName(err) });
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
cwd.writeFile(out_path, formatted) catch |err| {
|
||||||
|
try stderr.writer().print("Error: Failed to write to output file '{s}' ({s})\n", .{ out_path, @errorName(err) });
|
||||||
|
return;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,16 +65,18 @@ pub const GenerateStep = struct {
|
|||||||
fn make(step: *Step) !void {
|
fn make(step: *Step) !void {
|
||||||
const self = @fieldParentPtr(GenerateStep, "step", step);
|
const self = @fieldParentPtr(GenerateStep, "step", step);
|
||||||
const cwd = std.fs.cwd();
|
const cwd = std.fs.cwd();
|
||||||
var out_buffer = std.ArrayList(u8).init(self.builder.allocator);
|
|
||||||
const spec = try cwd.readFileAlloc(self.builder.allocator, self.spec_path, std.math.maxInt(usize));
|
const spec = try cwd.readFileAlloc(self.builder.allocator, self.spec_path, std.math.maxInt(usize));
|
||||||
|
|
||||||
|
var out_buffer = std.ArrayList(u8).init(self.builder.allocator);
|
||||||
try generate(self.builder.allocator, spec, out_buffer.writer());
|
try generate(self.builder.allocator, spec, out_buffer.writer());
|
||||||
|
|
||||||
const tree = try std.zig.parse(self.builder.allocator, out_buffer.items);
|
const tree = try std.zig.parse(self.builder.allocator, out_buffer.items);
|
||||||
|
|
||||||
|
var formatted = try tree.render(self.builder.allocator);
|
||||||
|
|
||||||
const dir = path.dirname(self.package.path).?;
|
const dir = path.dirname(self.package.path).?;
|
||||||
try cwd.makePath(dir);
|
try cwd.makePath(dir);
|
||||||
const output_file = cwd.createFile(self.package.path, .{}) catch unreachable;
|
try cwd.writeFile(self.package.path, formatted);
|
||||||
defer output_file.close();
|
|
||||||
_ = try std.zig.render(self.builder.allocator, output_file.writer(), tree);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user