std.Build: port UpdateSourceFiles step to new system

This commit is contained in:
Andrew Kelley
2026-05-06 23:17:34 -07:00
parent d3ec255a1f
commit affe5ed867
11 changed files with 293 additions and 209 deletions
+1 -48
View File
@@ -29,11 +29,10 @@ pub const Contents = union(enum) {
pub fn create(owner: *std.Build) *UpdateSourceFiles {
const usf = owner.allocator.create(UpdateSourceFiles) catch @panic("OOM");
usf.* = .{
.step = Step.init(.{
.step = .init(.{
.tag = base_tag,
.name = "UpdateSourceFiles",
.owner = owner,
.makeFn = make,
}),
.output_source_files = .empty,
};
@@ -68,49 +67,3 @@ pub fn addBytesToSource(usf: *UpdateSourceFiles, bytes: []const u8, sub_path: []
.sub_path = sub_path,
}) catch @panic("OOM");
}
fn make(step: *Step, options: Step.MakeOptions) !void {
_ = options;
const b = step.owner;
const io = b.graph.io;
const usf: *UpdateSourceFiles = @fieldParentPtr("step", step);
var any_miss = false;
for (usf.output_source_files.items) |output_source_file| {
if (fs.path.dirname(output_source_file.sub_path)) |dirname| {
b.build_root.handle.createDirPath(io, dirname) catch |err| {
return step.fail("unable to make path '{f}{s}': {t}", .{ b.build_root, dirname, err });
};
}
switch (output_source_file.contents) {
.bytes => |bytes| {
b.build_root.handle.writeFile(io, .{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {
return step.fail("unable to write file '{f}{s}': {t}", .{
b.build_root, output_source_file.sub_path, err,
});
};
any_miss = true;
},
.copy => |file_source| {
if (!step.inputs.populated()) try step.addWatchInput(file_source);
const source_path = file_source.getPath2(b, step);
const prev_status = Io.Dir.updateFile(
.cwd(),
io,
source_path,
b.build_root.handle,
output_source_file.sub_path,
.{},
) catch |err| {
return step.fail("unable to update file from '{s}' to '{f}{s}': {t}", .{
source_path, b.build_root, output_source_file.sub_path, err,
});
};
any_miss = any_miss or prev_status == .stale;
},
}
}
step.result_cached = !any_miss;
}