| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | const std = @import("../index.zig"); |
| 2 | const build = @import("../build.zig"); |
| 3 | const Step = build.Step; |
| 4 | const Builder = build.Builder; |
| 5 | const BufMap = std.BufMap; |
| 6 | const mem = std.mem; |
| 7 | |
| 8 | pub const FmtStep = struct { |
| 9 | step: Step, |
| 10 | builder: *Builder, |
| 11 | argv: [][]const u8, |
| 12 | |
| 13 | pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep { |
| 14 | const self = builder.allocator.create(FmtStep) catch unreachable; |
| 15 | const name = "zig fmt"; |
| 16 | self.* = FmtStep{ |
| 17 | .step = Step.init(name, builder.allocator, make), |
| 18 | .builder = builder, |
| 19 | .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable, |
| 20 | }; |
| 21 | |
| 22 | self.argv[0] = builder.zig_exe; |
| 23 | self.argv[1] = "fmt"; |
| 24 | for (paths) |path, i| { |
| 25 | self.argv[2 + i] = builder.pathFromRoot(path); |
| 26 | } |
| 27 | return self; |
| 28 | } |
| 29 | |
| 30 | fn make(step: *Step) !void { |
| 31 | const self = @fieldParentPtr(FmtStep, "step", step); |
| 32 | |
| 33 | return self.builder.spawnChild(self.argv); |
| 34 | } |
| 35 | }; |