| 1 | const InstallFile = @This(); |
| 2 | |
| 3 | const std = @import("std"); |
| 4 | const Step = std.Build.Step; |
| 5 | const LazyPath = std.Build.LazyPath; |
| 6 | const InstallDir = std.Build.InstallDir; |
| 7 | const assert = std.debug.assert; |
| 8 | |
| 9 | step: Step, |
| 10 | source: LazyPath, |
| 11 | dir: InstallDir, |
| 12 | dest_rel_path: []const u8, |
| 13 | |
| 14 | pub const base_tag: Step.Tag = .install_file; |
| 15 | |
| 16 | pub fn create( |
| 17 | owner: *std.Build, |
| 18 | source: LazyPath, |
| 19 | dir: InstallDir, |
| 20 | dest_rel_path: []const u8, |
| 21 | ) *InstallFile { |
| 22 | assert(dest_rel_path.len != 0); |
| 23 | const graph = owner.graph; |
| 24 | const arena = graph.arena; |
| 25 | const install_file = arena.create(InstallFile) catch @panic("OOM"); |
| 26 | install_file.* = .{ |
| 27 | .step = Step.init(.{ |
| 28 | .tag = base_tag, |
| 29 | .name = owner.fmt("install {f} to {s}", .{ source, dest_rel_path }), |
| 30 | .owner = owner, |
| 31 | }), |
| 32 | .source = source.dupe(graph), |
| 33 | .dir = dir.dupe(graph), |
| 34 | .dest_rel_path = graph.dupePath(dest_rel_path), |
| 35 | }; |
| 36 | source.addStepDependencies(&install_file.step); |
| 37 | return install_file; |
| 38 | } |