zig/lib/std/Build/FmtStep.zig
Andrew Kelley 02381c0372 std.Build: improve debugging of misconfigured steps
* Step.init() now takes an options struct
 * Step.init() now captures a small stack trace and stores it in the
   Step so that it can be accessed when printing user-friendly debugging
   information, including the lines of code that created the step in
   question.
2023-03-15 10:48:12 -07:00

37 lines
934 B
Zig

const std = @import("../std.zig");
const Step = std.Build.Step;
const FmtStep = @This();
pub const base_id = .fmt;
step: Step,
builder: *std.Build,
argv: [][]const u8,
pub fn create(builder: *std.Build, paths: []const []const u8) *FmtStep {
const self = builder.allocator.create(FmtStep) catch @panic("OOM");
const name = "zig fmt";
self.* = FmtStep{
.step = Step.init(builder.allocator, .{
.id = .fmt,
.name = name,
.makeFn = make,
}),
.builder = builder,
.argv = builder.allocator.alloc([]u8, paths.len + 2) catch @panic("OOM"),
};
self.argv[0] = builder.zig_exe;
self.argv[1] = "fmt";
for (paths, 0..) |path, i| {
self.argv[2 + i] = builder.pathFromRoot(path);
}
return self;
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(FmtStep, "step", step);
return self.builder.spawnChild(self.argv);
}