aboutsummaryrefslogtreecommitdiff
path: root/lib/std/build/fmt.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/build/fmt.zig')
-rw-r--r--lib/std/build/fmt.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/std/build/fmt.zig b/lib/std/build/fmt.zig
new file mode 100644
index 0000000000..f3b8e08180
--- /dev/null
+++ b/lib/std/build/fmt.zig
@@ -0,0 +1,35 @@
+const std = @import("../std.zig");
+const build = @import("../build.zig");
+const Step = build.Step;
+const Builder = build.Builder;
+const BufMap = std.BufMap;
+const mem = std.mem;
+
+pub const FmtStep = struct {
+ step: Step,
+ builder: *Builder,
+ argv: [][]const u8,
+
+ pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep {
+ const self = builder.allocator.create(FmtStep) catch unreachable;
+ const name = "zig fmt";
+ self.* = FmtStep{
+ .step = Step.init(name, builder.allocator, make),
+ .builder = builder,
+ .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,
+ };
+
+ self.argv[0] = builder.zig_exe;
+ self.argv[1] = "fmt";
+ for (paths) |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);
+ }
+};