Skip to content

std.Build.Step.UpdateSourceFiles

Standard libraryZig 0.17.0Official documentation
Sourcestd/Build/Step/UpdateSourceFiles.zig

Source line 1

Fields

step: Step
embeds: std.ArrayList(Embed) = .empty
copies: std.ArrayList(Copy) = .empty

std.Build.Step.UpdateSourceFiles.addBytesToSource

function

Source line 54

Overwrites a path relative to the package root with the provided bytes.

Because it updates source files, this should not be used as part of the normal build process, but as a utility occasionally run by a developer with intent to modify source files and then commit those changes to version control.

pub fn addBytesToSource(usf: *UpdateSourceFiles, contents: []const u8, sub_path: []const u8) void

Parameters

usf: *UpdateSourceFiles
contents: []const u8
sub_path: []const u8

std.Build.Step.UpdateSourceFiles.addCopyFileToSource

function

Source line 35

Overwrites a path relative to the build root with the contents of another file.

Because it updates source files, this should not be used as part of the normal build process, but as a utility occasionally run by a developer with intent to modify source files and then commit those changes to version control.

pub fn addCopyFileToSource(usf: *UpdateSourceFiles, src_file: std.Build.LazyPath, sub_path: []const u8) void

Parameters

usf: *UpdateSourceFiles
src_file: std.Build.LazyPath
sub_path: []const u8

std.Build.Step.UpdateSourceFiles.base_tag

constant

Source line 11

Step.Tag

std.Build.Step.UpdateSourceFiles.Configuration

alias

Source line 5

Alias of std.Build.Configuration

std.Build.Step.UpdateSourceFiles.Copy

alias

Source line 14

Alias of std.Build.Step.WriteFile.Copy

std.Build.Step.UpdateSourceFiles.create

function

Source line 16

pub fn create(owner: *std.Build) *UpdateSourceFiles

Parameters

owner: *std.Build

std.Build.Step.UpdateSourceFiles.Embed

alias

Source line 13

Alias of std.Build.Step.WriteFile.Embed

std.Build.Step.UpdateSourceFiles.std

alias

Source line 3

Alias of std

std.Build.Step.UpdateSourceFiles.Step

alias

Source line 4

Alias of std.Build.Step

std.Build.Step.UpdateSourceFiles.UpdateSourceFiles

alias

Source line 1

Alias of std.Build.Step.UpdateSourceFiles

Source code

std/Build/Step/UpdateSourceFiles.zig

const UpdateSourceFiles = @This();

const std = @import("std");
const Step = std.Build.Step;
const Configuration = std.Build.Configuration;

step: Step,
embeds: std.ArrayList(Embed) = .empty,
copies: std.ArrayList(Copy) = .empty,

pub const base_tag: Step.Tag = .update_source_files;

pub const Embed = Step.WriteFile.Embed;
pub const Copy = Step.WriteFile.Copy;

pub fn create(owner: *std.Build) *UpdateSourceFiles {
    const graph = owner.graph;
    const usf = graph.create(UpdateSourceFiles);
    usf.* = .{
        .step = .init(.{
            .tag = base_tag,
            .name = "UpdateSourceFiles",
            .owner = owner,
        }),
    };
    return usf;
}

/// Overwrites a path relative to the build root with the contents of another file.
///
/// Because it updates source files, this should not be used as part of the
/// normal build process, but as a utility occasionally run by a developer with
/// intent to modify source files and then commit those changes to version
/// control.
pub fn addCopyFileToSource(usf: *UpdateSourceFiles, src_file: std.Build.LazyPath, sub_path: []const u8) void {
    const graph = usf.step.owner.graph;
    const wc = &graph.wip_configuration;
    const arena = graph.arena;

    usf.copies.append(arena, .{
        .sub_path = wc.addString(sub_path) catch @panic("OOM"),
        .src_file = src_file.dupe(graph),
    }) catch @panic("OOM");

    src_file.addStepDependencies(&usf.step);
}

/// Overwrites a path relative to the package root with the provided bytes.
///
/// Because it updates source files, this should not be used as part of the
/// normal build process, but as a utility occasionally run by a developer with
/// intent to modify source files and then commit those changes to version
/// control.
pub fn addBytesToSource(usf: *UpdateSourceFiles, contents: []const u8, sub_path: []const u8) void {
    const graph = usf.step.owner.graph;
    const wc = &graph.wip_configuration;
    const arena = graph.arena;

    usf.embeds.append(arena, .{
        .sub_path = wc.addString(sub_path) catch @panic("OOM"),
        .contents = wc.addBytes(contents) catch @panic("OOM"),
    }) catch @panic("OOM");
}