1//! Fail the build step if a file does not match certain checks.
2const CheckFile = @This();
3
4const std = @import("std");
5const Io = std.Io;
6const Step = std.Build.Step;
7const fs = std.fs;
8const mem = std.mem;
9const Configuration = std.Build.Configuration;
10
11step: Step,
12file: std.Build.LazyPath,
13expected_matches: []const Configuration.Bytes,
14expected_exact: ?Configuration.Bytes,
15max_bytes: ?u32,
16
17pub const base_tag: Step.Tag = .check_file;
18
19pub const Options = struct {
20 expected_matches: []const []const u8 = &.{},
21 expected_exact: ?[]const u8 = null,
22 max_bytes: ?u32 = null,
23};
24
25pub fn create(owner: *std.Build, file: std.Build.LazyPath, options: Options) *CheckFile {
26 const graph = owner.graph;
27 const check_file = graph.create(CheckFile);
28 check_file.* = .{
29 .step = .init(.{
30 .tag = base_tag,
31 .name = "CheckFile",
32 .owner = owner,
33 }),
34 .file = file.dupe(graph),
35 .expected_matches = graph.addBytesList(options.expected_matches),
36 .expected_exact = if (options.expected_exact) |b| graph.addBytes(b) else null,
37 .max_bytes = options.max_bytes,
38 };
39 file.addStepDependencies(&check_file.step);
40 return check_file;
41}
42
43pub fn setName(check_file: *CheckFile, name: []const u8) void {
44 check_file.step.name = name;
45}