| 1 | //! Fail the build step if a file does not match certain checks. |
| 2 | const CheckFile = @This(); |
| 3 | |
| 4 | const std = @import("std"); |
| 5 | const Io = std.Io; |
| 6 | const Step = std.Build.Step; |
| 7 | const fs = std.fs; |
| 8 | const mem = std.mem; |
| 9 | const Configuration = std.Build.Configuration; |
| 10 | |
| 11 | step: Step, |
| 12 | file: std.Build.LazyPath, |
| 13 | expected_matches: []const Configuration.Bytes, |
| 14 | expected_exact: ?Configuration.Bytes, |
| 15 | max_bytes: ?u32, |
| 16 | |
| 17 | pub const base_tag: Step.Tag = .check_file; |
| 18 | |
| 19 | pub const Options = struct { |
| 20 | expected_matches: []const []const u8 = &.{}, |
| 21 | expected_exact: ?[]const u8 = null, |
| 22 | max_bytes: ?u32 = null, |
| 23 | }; |
| 24 | |
| 25 | pub 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 | |
| 43 | pub fn setName(check_file: *CheckFile, name: []const u8) void { |
| 44 | check_file.step.name = name; |
| 45 | } |