mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
* 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.
34 lines
905 B
Zig
34 lines
905 B
Zig
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(builder.allocator, .{
|
|
.id = .remove_dir,
|
|
.name = builder.fmt("RemoveDir {s}", .{dir_path}),
|
|
.makeFn = 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;
|
|
};
|
|
}
|