aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/InstallFileStep.zig
blob: f77b22c1121bc507262fb72ec00cc31dfe4e01c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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,
builder: *std.Build,
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.
override_source_builder: ?*std.Build = null,

pub fn init(
    builder: *std.Build,
    source: FileSource,
    dir: InstallDir,
    dest_rel_path: []const u8,
) InstallFileStep {
    builder.pushInstalledFile(dir, dest_rel_path);
    return InstallFileStep{
        .builder = builder,
        .step = Step.init(builder.allocator, .{
            .id = .install_file,
            .name = builder.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }),
            .makeFn = make,
        }),
        .source = source.dupe(builder),
        .dir = dir.dupe(builder),
        .dest_rel_path = builder.dupePath(dest_rel_path),
    };
}

fn make(step: *Step, prog_node: *std.Progress.Node) !void {
    _ = prog_node;
    const self = @fieldParentPtr(InstallFileStep, "step", step);
    const src_builder = self.override_source_builder orelse self.builder;
    const full_src_path = self.source.getPath2(src_builder, step);
    const full_dest_path = self.builder.getInstallPath(self.dir, self.dest_rel_path);
    try self.builder.updateFile(full_src_path, full_dest_path);
}