step: Step,
paths: []const []const u8,
exclude_paths: []const []const u8,
check: bool,
pub const base_id = .fmt;
pub const Options = struct {
paths: []const []const u8 = &.{},
exclude_paths: []const []const u8 = &.{},
check: bool = false,
};
pub fn create(owner: *std.Build, options: Options) *FmtStep {
const self = owner.allocator.create(FmtStep) catch @panic("OOM");
const name = if (options.check) "zig fmt --check" else "zig fmt";
self.* = .{
.step = Step.init(.{
.id = base_id,
.name = name,
.owner = owner,
.makeFn = make,
}),
.paths = options.paths,
.exclude_paths = options.exclude_paths,
.check = options.check,
};
return self;
}
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
_ = prog_node;
const b = step.owner;
const arena = b.allocator;
const self = @fieldParentPtr(FmtStep, "step", step);
var argv: std.ArrayListUnmanaged([]const u8) = .{};
try argv.ensureUnusedCapacity(arena, 2 + 1 + self.paths.len + 2 * self.exclude_paths.len);
argv.appendAssumeCapacity(b.zig_exe);
argv.appendAssumeCapacity("fmt");
if (self.check) {
argv.appendAssumeCapacity("--check");
}
for (self.paths) |p| {
argv.appendAssumeCapacity(b.pathFromRoot(p));
}
for (self.exclude_paths) |p| {
argv.appendAssumeCapacity("--exclude");
argv.appendAssumeCapacity(b.pathFromRoot(p));
}
return step.evalChildProcess(argv.items);
}
const std = @import("../std.zig");
const Step = std.Build.Step;
const FmtStep = @This();