From 36e5751c989cffbcf797d25ca7fe40d0dcd56a78 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Fri, 11 Oct 2024 11:02:21 -0600 Subject: [PATCH] Quote prereq names in layout depfile (#68) The layout step was choking on paths with spaces in the depfile, so now all depfile paths are quoted. I could have just added quotation marks to all existing print calls, but I figured it will harder to screw it up again if we're not directly using the writer. --- src/exes/layout.zig | 10 +++++----- src/exes/layout/DepWriter.zig | 17 +++++++++++++++++ src/exes/layout/cache.zig | 19 ++++++++++--------- 3 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 src/exes/layout/DepWriter.zig diff --git a/src/exes/layout.zig b/src/exes/layout.zig index e4aa781..ed25ee8 100644 --- a/src/exes/layout.zig +++ b/src/exes/layout.zig @@ -7,6 +7,7 @@ const superhtml = @import("superhtml"); const cache = @import("layout/cache.zig"); const zine = @import("zine"); const context = zine.context; +const DepWriter = @import("layout/DepWriter.zig"); const log = std.log.scoped(.layout); pub const std_options: std.Options = .{ @@ -103,8 +104,8 @@ pub fn main() !void { }; var dep_buf_writer = std.io.bufferedWriter(dep_file.writer()); - const dep_writer = dep_buf_writer.writer(); - dep_writer.print("target: ", .{}) catch |err| { + const dep_writer = DepWriter.init(dep_buf_writer.writer().any()); + dep_writer.writeTarget("target") catch |err| { fatal("error writing to the dep file: {s}", .{@errorName(err)}); }; @@ -167,7 +168,7 @@ pub fn main() !void { index_dir_path, output_path_prefix, locales, - dep_writer.any(), + dep_writer, asset_list_writer.any(), ); @@ -256,13 +257,12 @@ pub fn main() !void { template_html, std.mem.endsWith(u8, template_name, ".xml"), ); - try dep_writer.print("{s} ", .{template_path}); + try dep_writer.writePrereq(template_path); }, }; try out_buf_writer.flush(); try asset_list_buf_writer.flush(); - try dep_writer.writeAll("\n"); try dep_buf_writer.flush(); } diff --git a/src/exes/layout/DepWriter.zig b/src/exes/layout/DepWriter.zig new file mode 100644 index 0000000..690e08e --- /dev/null +++ b/src/exes/layout/DepWriter.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +const DepWriter = @This(); + +w: std.io.AnyWriter, + +pub fn init(writer: std.io.AnyWriter) DepWriter { + return .{.w=writer}; +} + +pub fn writeTarget(dw: DepWriter, target: []const u8) !void { + try dw.w.print("\n{s}:", .{target}); +} + +pub fn writePrereq(dw: DepWriter, prereq: []const u8) !void { + try dw.w.print(" \"{s}\"", .{prereq}); +} diff --git a/src/exes/layout/cache.zig b/src/exes/layout/cache.zig index f6f7cd6..123f3b8 100644 --- a/src/exes/layout/cache.zig +++ b/src/exes/layout/cache.zig @@ -4,6 +4,7 @@ const ziggy = @import("ziggy"); const zine = @import("zine"); const context = zine.context; const Allocator = std.mem.Allocator; +const DepWriter = @import("DepWriter.zig"); const log = std.log.scoped(.layout_cache); @@ -19,7 +20,7 @@ pub fn initAll( _index_dir_path: []const u8, output_path_prefix: []const u8, locales: []const Locale, - _dep_writer: std.io.AnyWriter, + _dep_writer: DepWriter, asset_list_writer: std.io.AnyWriter, ) error{OutOfMemory}!void { gpa = _gpa; @@ -61,7 +62,7 @@ pub fn initAll( } var gpa: Allocator = undefined; -var dep_writer: std.io.AnyWriter = undefined; +var dep_writer: DepWriter = undefined; var index_dir_path: []const u8 = undefined; pub const sites = struct { @@ -266,7 +267,7 @@ const page_finder = struct { log.debug("dep: '{s}'", .{index_path}); - dep_writer.print("{s} ", .{index_path}) catch { + dep_writer.writePrereq(index_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{index_path}, @@ -327,7 +328,7 @@ const page_finder = struct { log.debug("dep: '{s}'", .{index_path}); - dep_writer.print("{s} ", .{index_path}) catch { + dep_writer.writePrereq(index_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{index_path}, @@ -426,7 +427,7 @@ const asset_finder = struct { }; log.debug("dep: '{s}'", .{full_path}); - dep_writer.print("{s} ", .{full_path}) catch { + dep_writer.writePrereq(full_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{ref}, @@ -473,7 +474,7 @@ const asset_finder = struct { }); log.debug("dep: '{s}'", .{full_path}); - dep_writer.print("{s} ", .{full_path}) catch { + dep_writer.writePrereq(full_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{ref}, @@ -686,7 +687,7 @@ fn loadPage( ) catch @panic("i/o"); log.debug("dep: '{s}'", .{ps_index_file_path}); - dep_writer.print("{s} ", .{ps_index_file_path}) catch { + dep_writer.writePrereq(ps_index_file_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{ps_index_file_path}, @@ -715,7 +716,7 @@ fn loadPage( ) catch @panic("i/o"); log.debug("dep: '{s}'", .{ps_file_path}); - dep_writer.print("{s} ", .{ps_file_path}) catch { + dep_writer.writePrereq(ps_file_path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{ps_file_path}, @@ -912,7 +913,7 @@ fn loadPage( log.debug("dep: '{s}'", .{value.asset._meta.path}); - dep_writer.print("{s} ", .{value.asset._meta.path}) catch { + dep_writer.writePrereq(value.asset._meta.path) catch { std.debug.panic( "error while writing to dep file file: '{s}'", .{value.asset._meta.path},