From 1d7e5479b0826776e53b499811198356bc180706 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Feb 2019 18:33:27 -0500 Subject: [PATCH] fix .gitignore file and add commit missing std lib file --- .gitignore | 6 +++--- std/build/fmt.zig | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 std/build/fmt.zig diff --git a/.gitignore b/.gitignore index 4b7bff11a6..f85fc969b1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,6 @@ # -andrewrk zig-cache/ -build/ -build-*/ -docgen_tmp/ +/build/ +/build-*/ +/docgen_tmp/ diff --git a/std/build/fmt.zig b/std/build/fmt.zig new file mode 100644 index 0000000000..ec0536dd34 --- /dev/null +++ b/std/build/fmt.zig @@ -0,0 +1,35 @@ +const std = @import("../index.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); + } +};