DoxigAlpha

make

Function parameters

Parameters

#
step:*Step
options:Step.MakeOptions

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#

= .fmt

Values

#
base_id
= .fmt

Source

Implementation

#
fn make(step: *Step, options: Step.MakeOptions) !void {
    const prog_node = options.progress_node;

    // TODO: if check=false, this means we are modifying source files in place, which
    // is an operation that could race against other operations also modifying source files
    // in place. In this case, this step should obtain a write lock while making those
    // modifications.

    const b = step.owner;
    const arena = b.allocator;
    const fmt: *Fmt = @fieldParentPtr("step", step);

    var argv: std.ArrayListUnmanaged([]const u8) = .empty;
    try argv.ensureUnusedCapacity(arena, 2 + 1 + fmt.paths.len + 2 * fmt.exclude_paths.len);

    argv.appendAssumeCapacity(b.graph.zig_exe);
    argv.appendAssumeCapacity("fmt");

    if (fmt.check) {
        argv.appendAssumeCapacity("--check");
    }

    for (fmt.paths) |p| {
        argv.appendAssumeCapacity(b.pathFromRoot(p));
    }

    for (fmt.exclude_paths) |p| {
        argv.appendAssumeCapacity("--exclude");
        argv.appendAssumeCapacity(b.pathFromRoot(p));
    }

    const run_result = try step.captureChildProcess(prog_node, argv.items);
    if (fmt.check) switch (run_result.term) {
        .Exited => |code| if (code != 0 and run_result.stdout.len != 0) {
            var it = std.mem.tokenizeScalar(u8, run_result.stdout, '\n');
            while (it.next()) |bad_file_name| {
                try step.addError("{s}: non-conforming formatting", .{bad_file_name});
            }
        },
        else => {},
    };
    try step.handleChildProcessTerm(run_result.term, null, argv.items);
}