1const CheckFile = @This();
2
3const std = @import("std");
4const Io = std.Io;
5const Configuration = std.Build.Configuration;
6
7const Step = @import("../Step.zig");
8const Maker = @import("../../Maker.zig");
9
10pub fn make(
11 check_file: *CheckFile,
12 step_index: Configuration.Step.Index,
13 maker: *Maker,
14 progress_node: std.Progress.Node,
15) Step.ExtendedMakeError!void {
16 _ = check_file;
17 _ = progress_node;
18 const graph = maker.graph;
19 const arena = maker.graph.arena; // TODO don't leak into process arena
20 const io = graph.io;
21 const step = maker.stepByIndex(step_index);
22 const conf = &maker.scanned_config.configuration;
23 const conf_step = step_index.ptr(conf);
24 const conf_cf = conf_step.extended.get(conf.extra).check_file;
25 const lazy_path = conf_cf.file.get(conf);
26
27 try step.singleUnchangingWatchInput(maker, arena, lazy_path);
28
29 const src_path = try maker.resolveLazyPath(arena, lazy_path, step_index);
30 const limit: Io.Limit = if (conf_cf.max_bytes.value) |x| .limited(x) else .unlimited;
31
32 const contents = src_path.root_dir.handle.readFileAlloc(io, src_path.sub_path, arena, limit) catch |err|
33 return step.fail(maker, "failed to read {f}: {t}", .{ src_path, err });
34
35 for (conf_cf.expected_matches.slice) |expected_match_index| {
36 const expected_match = expected_match_index.slice(conf);
37 if (std.mem.find(u8, contents, expected_match) == null) {
38 return step.fail(maker,
39 \\
40 \\========= expected to find: ===================
41 \\{s}
42 \\========= but file does not contain it: =======
43 \\{s}
44 \\===============================================
45 , .{ expected_match, contents });
46 }
47 }
48
49 if (conf_cf.expected_exact.value) |expected_exact_index| {
50 const expected_exact = expected_exact_index.slice(conf);
51 if (!std.mem.eql(u8, expected_exact, contents)) {
52 return step.fail(maker,
53 \\
54 \\========= expected: =====================
55 \\{s}
56 \\========= but found: ====================
57 \\{s}
58 \\========= from the following file: ======
59 \\{f}
60 , .{ expected_exact, contents, src_path });
61 }
62 }
63}