authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-22 18:56:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:36-07:00
log31c159c228ecf6c2ffcf44ee44621c3d6b1ceb61
tree5fdb38723143013bf22f0f21a9695a653f51e8af
parent92038675af545ecdbe1f1b4cbd1095a8b3264e07

Maker: implement CheckFile


2 files changed, 12 insertions(+), 8 deletions(-)

lib/compiler/Maker/Step.zig+2-1
......@@ -18,6 +18,7 @@ const assert = std.debug.assert;
1818const WebServer = @import("WebServer.zig");
1919const Maker = @import("../Maker.zig");
2020
21pub const CheckFile = @import("Step/CheckFile.zig");
2122pub const Compile = @import("Step/Compile.zig");
2223pub const FindProgram = @import("Step/FindProgram.zig");
2324pub const Fmt = @import("Step/Fmt.zig");
......@@ -75,7 +76,7 @@ comptime {
7576}
7677
7778pub const Extended = union(enum) {
78 check_file: Todo,
79 check_file: CheckFile,
7980 compile: Compile,
8081 config_header: Todo,
8182 fail: Fail,
lib/compiler/Maker/Step/CheckFile.zig+10-7
......@@ -13,6 +13,7 @@ pub fn make(
1313 maker: *Maker,
1414 progress_node: std.Progress.Node,
1515) Step.ExtendedMakeError!void {
16 _ = check_file;
1617 _ = progress_node;
1718 const graph = maker.graph;
1819 const arena = maker.graph.arena; // TODO don't leak into process arena
......@@ -20,7 +21,7 @@ pub fn make(
2021 const step = maker.stepByIndex(step_index);
2122 const conf = &maker.scanned_config.configuration;
2223 const conf_step = step_index.ptr(conf);
23 const conf_cf = conf_step.extended.get(conf.extra).install_file;
24 const conf_cf = conf_step.extended.get(conf.extra).check_file;
2425 const lazy_path = conf_cf.file.get(conf);
2526
2627 try step.singleUnchangingWatchInput(maker, arena, lazy_path);
......@@ -29,11 +30,12 @@ pub fn make(
2930 const limit: Io.Limit = if (conf_cf.max_bytes.value) |x| .limited(x) else .unlimited;
3031
3132 const contents = src_path.root_dir.handle.readFileAlloc(io, src_path.sub_path, arena, limit) catch |err|
32 return step.fail("failed to read {f}: {t}", .{ src_path, err });
33 return step.fail(maker, "failed to read {f}: {t}", .{ src_path, err });
3334
34 for (check_file.expected_matches) |expected_match| {
35 for (conf_cf.expected_matches.slice) |expected_match_index| {
36 const expected_match = expected_match_index.slice(conf);
3537 if (std.mem.find(u8, contents, expected_match) == null) {
36 return step.fail(
38 return step.fail(maker,
3739 \\
3840 \\========= expected to find: ===================
3941 \\{s}
......@@ -44,16 +46,17 @@ pub fn make(
4446 }
4547 }
4648
47 if (check_file.expected_exact) |expected_exact| {
49 if (conf_cf.expected_exact.value) |expected_exact_index| {
50 const expected_exact = expected_exact_index.slice(conf);
4851 if (!std.mem.eql(u8, expected_exact, contents)) {
49 return step.fail(
52 return step.fail(maker,
5053 \\
5154 \\========= expected: =====================
5255 \\{s}
5356 \\========= but found: ====================
5457 \\{s}
5558 \\========= from the following file: ======
56 \\{s}
59 \\{f}
5760 , .{ expected_exact, contents, src_path });
5861 }
5962 }