From 36e2d992dd8c45ca89a51d508c6c413cff5ad2cd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 31 Jan 2023 00:19:51 -0700 Subject: combine std.build and std.build.Builder into std.Build I've been wanting to do this for along time. --- lib/std/Build/RemoveDirStep.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/std/Build/RemoveDirStep.zig (limited to 'lib/std/Build/RemoveDirStep.zig') diff --git a/lib/std/Build/RemoveDirStep.zig b/lib/std/Build/RemoveDirStep.zig new file mode 100644 index 0000000000..f3b71dcec1 --- /dev/null +++ b/lib/std/Build/RemoveDirStep.zig @@ -0,0 +1,29 @@ +const std = @import("../std.zig"); +const log = std.log; +const fs = std.fs; +const Step = std.Build.Step; +const RemoveDirStep = @This(); + +pub const base_id = .remove_dir; + +step: Step, +builder: *std.Build, +dir_path: []const u8, + +pub fn init(builder: *std.Build, dir_path: []const u8) RemoveDirStep { + return RemoveDirStep{ + .builder = builder, + .step = Step.init(.remove_dir, builder.fmt("RemoveDir {s}", .{dir_path}), builder.allocator, make), + .dir_path = builder.dupePath(dir_path), + }; +} + +fn make(step: *Step) !void { + const self = @fieldParentPtr(RemoveDirStep, "step", step); + + const full_path = self.builder.pathFromRoot(self.dir_path); + fs.cwd().deleteTree(full_path) catch |err| { + log.err("Unable to remove {s}: {s}", .{ full_path, @errorName(err) }); + return err; + }; +} -- cgit v1.2.3