diff options
| author | Nicolas Sterchele <nicolas@sterchelen.net> | 2023-03-20 09:23:10 +0100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-05-03 08:39:24 +0300 |
| commit | 13eb7251d37759bd47403db304c6120c706fe353 (patch) | |
| tree | 225d87ef968270968379e2d58b9791b0aa152aa7 /lib/std/Build/Step/InstallFile.zig | |
| parent | 855493bb8b395970921494d3a11ccfeaac30c2dc (diff) | |
| download | zig-13eb7251d37759bd47403db304c6120c706fe353.tar.gz zig-13eb7251d37759bd47403db304c6120c706fe353.zip | |
build: rename std.Build.*Step to std.Build.Step.*
Follow-up actions from #14647
Fixes #14947
Diffstat (limited to 'lib/std/Build/Step/InstallFile.zig')
| -rw-r--r-- | lib/std/Build/Step/InstallFile.zig | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/std/Build/Step/InstallFile.zig b/lib/std/Build/Step/InstallFile.zig new file mode 100644 index 0000000000..b6b66fd1e0 --- /dev/null +++ b/lib/std/Build/Step/InstallFile.zig @@ -0,0 +1,57 @@ +const std = @import("std"); +const Step = std.Build.Step; +const FileSource = std.Build.FileSource; +const InstallDir = std.Build.InstallDir; +const InstallFileStep = @This(); +const assert = std.debug.assert; + +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 create( + owner: *std.Build, + source: FileSource, + dir: InstallDir, + dest_rel_path: []const u8, +) *InstallFileStep { + assert(dest_rel_path.len != 0); + owner.pushInstalledFile(dir, dest_rel_path); + const self = owner.allocator.create(InstallFileStep) catch @panic("OOM"); + self.* = .{ + .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, + }; + source.addStepDependencies(&self.step); + return self; +} + +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; +} |
