Skip to content

Commit

Permalink
Quote prereq names in layout depfile (#68)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandondyck authored Oct 11, 2024
1 parent 1630838 commit 36e5751
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/exes/layout.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{
Expand Down Expand Up @@ -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)});
};

Expand Down Expand Up @@ -167,7 +168,7 @@ pub fn main() !void {
index_dir_path,
output_path_prefix,
locales,
dep_writer.any(),
dep_writer,
asset_list_writer.any(),
);

Expand Down Expand Up @@ -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();
}

Expand Down
17 changes: 17 additions & 0 deletions src/exes/layout/DepWriter.zig
Original file line number Diff line number Diff line change
@@ -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});
}
19 changes: 10 additions & 9 deletions src/exes/layout/cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 36e5751

Please sign in to comment.