mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
* remove std.Build.updateFile. I noticed some people use it from build.zig (declare phase) when it is intended only for use in the make phase. - This also was incorrectly reporting errors with std.log. * std.Build.InstallArtifactStep - report better errors on failure - report whether the step was cached or not * std.Build.InstallDirStep: report better error on failure * std.Build.InstallFileStep: report better error on failure
53 lines
1.7 KiB
Zig
53 lines
1.7 KiB
Zig
const std = @import("../std.zig");
|
|
const Step = std.Build.Step;
|
|
const FileSource = std.Build.FileSource;
|
|
const InstallDir = std.Build.InstallDir;
|
|
const InstallFileStep = @This();
|
|
|
|
pub const base_id = .install_file;
|
|
|
|
step: Step,
|
|
source: FileSource,
|
|
dir: InstallDir,
|
|
dest_rel_path: []const u8,
|
|
/// This is used by the build system when a file being installed comes from one
|
|
/// package but is being installed by another.
|
|
dest_builder: *std.Build,
|
|
|
|
pub fn init(
|
|
owner: *std.Build,
|
|
source: FileSource,
|
|
dir: InstallDir,
|
|
dest_rel_path: []const u8,
|
|
) InstallFileStep {
|
|
owner.pushInstalledFile(dir, dest_rel_path);
|
|
return InstallFileStep{
|
|
.step = Step.init(.{
|
|
.id = base_id,
|
|
.name = owner.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }),
|
|
.owner = owner,
|
|
.makeFn = make,
|
|
}),
|
|
.source = source.dupe(owner),
|
|
.dir = dir.dupe(owner),
|
|
.dest_rel_path = owner.dupePath(dest_rel_path),
|
|
.dest_builder = owner,
|
|
};
|
|
}
|
|
|
|
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
|
|
_ = prog_node;
|
|
const src_builder = step.owner;
|
|
const self = @fieldParentPtr(InstallFileStep, "step", step);
|
|
const dest_builder = self.dest_builder;
|
|
const full_src_path = self.source.getPath2(src_builder, step);
|
|
const full_dest_path = dest_builder.getInstallPath(self.dir, self.dest_rel_path);
|
|
const cwd = std.fs.cwd();
|
|
const prev = std.fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| {
|
|
return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
|
|
full_src_path, full_dest_path, @errorName(err),
|
|
});
|
|
};
|
|
step.result_cached = prev == .fresh;
|
|
}
|