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;...@@ -18,6 +18,7 @@ const assert = std.debug.assert;
18const WebServer = @import("WebServer.zig");18const WebServer = @import("WebServer.zig");
19const Maker = @import("../Maker.zig");19const Maker = @import("../Maker.zig");
2020
21pub const CheckFile = @import("Step/CheckFile.zig");
21pub const Compile = @import("Step/Compile.zig");22pub const Compile = @import("Step/Compile.zig");
22pub const FindProgram = @import("Step/FindProgram.zig");23pub const FindProgram = @import("Step/FindProgram.zig");
23pub const Fmt = @import("Step/Fmt.zig");24pub const Fmt = @import("Step/Fmt.zig");
...@@ -75,7 +76,7 @@ comptime {...@@ -75,7 +76,7 @@ comptime {
75}76}
7677
77pub const Extended = union(enum) {78pub const Extended = union(enum) {
78 check_file: Todo,79 check_file: CheckFile,
79 compile: Compile,80 compile: Compile,
80 config_header: Todo,81 config_header: Todo,
81 fail: Fail,82 fail: Fail,
lib/compiler/Maker/Step/CheckFile.zig+10-7
...@@ -13,6 +13,7 @@ pub fn make(...@@ -13,6 +13,7 @@ pub fn make(
13 maker: *Maker,13 maker: *Maker,
14 progress_node: std.Progress.Node,14 progress_node: std.Progress.Node,
15) Step.ExtendedMakeError!void {15) Step.ExtendedMakeError!void {
16 _ = check_file;
16 _ = progress_node;17 _ = progress_node;
17 const graph = maker.graph;18 const graph = maker.graph;
18 const arena = maker.graph.arena; // TODO don't leak into process arena19 const arena = maker.graph.arena; // TODO don't leak into process arena
...@@ -20,7 +21,7 @@ pub fn make(...@@ -20,7 +21,7 @@ pub fn make(
20 const step = maker.stepByIndex(step_index);21 const step = maker.stepByIndex(step_index);
21 const conf = &maker.scanned_config.configuration;22 const conf = &maker.scanned_config.configuration;
22 const conf_step = step_index.ptr(conf);23 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;
24 const lazy_path = conf_cf.file.get(conf);25 const lazy_path = conf_cf.file.get(conf);
2526
26 try step.singleUnchangingWatchInput(maker, arena, lazy_path);27 try step.singleUnchangingWatchInput(maker, arena, lazy_path);
...@@ -29,11 +30,12 @@ pub fn make(...@@ -29,11 +30,12 @@ pub fn make(
29 const limit: Io.Limit = if (conf_cf.max_bytes.value) |x| .limited(x) else .unlimited;30 const limit: Io.Limit = if (conf_cf.max_bytes.value) |x| .limited(x) else .unlimited;
3031
31 const contents = src_path.root_dir.handle.readFileAlloc(io, src_path.sub_path, arena, limit) catch |err|32 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);
35 if (std.mem.find(u8, contents, expected_match) == null) {37 if (std.mem.find(u8, contents, expected_match) == null) {
36 return step.fail(38 return step.fail(maker,
37 \\39 \\
38 \\========= expected to find: ===================40 \\========= expected to find: ===================
39 \\{s}41 \\{s}
...@@ -44,16 +46,17 @@ pub fn make(...@@ -44,16 +46,17 @@ pub fn make(
44 }46 }
45 }47 }
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);
48 if (!std.mem.eql(u8, expected_exact, contents)) {51 if (!std.mem.eql(u8, expected_exact, contents)) {
49 return step.fail(52 return step.fail(maker,
50 \\53 \\
51 \\========= expected: =====================54 \\========= expected: =====================
52 \\{s}55 \\{s}
53 \\========= but found: ====================56 \\========= but found: ====================
54 \\{s}57 \\{s}
55 \\========= from the following file: ======58 \\========= from the following file: ======
56 \\{s}59 \\{f}
57 , .{ expected_exact, contents, src_path });60 , .{ expected_exact, contents, src_path });
58 }61 }
59 }62 }