跳转到内容

std.Build.Step.Fmt

标准库Zig 0.17.1官方原文
源码std/Build/Step/Fmt.zig

第 1 行

此步骤具有两种模式:

  • 修改模式:直接修改源码文件,原地格式化。
  • 检查模式:发现不符合规范的文件时使步骤失败。

字段

step: Step
paths: []const LazyPath

创建 Fmt 步骤后,预期仅供读取。

exclude_paths: []const LazyPath

创建 Fmt 步骤后,预期仅供读取。

check: bool

std.Build.Step.Fmt.base_tag

常量

第 18 行

Step.Tag

std.Build.Step.Fmt.Configuration

别名

第 9 行

别名目标 std.Build.Configuration

std.Build.Step.Fmt.create

函数

第 27 行

pub fn create(owner: *std.Build, options: Options) *Fmt

参数

owner: *std.Build
options: Options

std.Build.Step.Fmt.Fmt

别名

第 4 行

别名目标 std.Build.Step.Fmt

std.Build.Step.Fmt.LazyPath

别名

第 8 行

别名目标 std.Build.LazyPath

std.Build.Step.Fmt.Options

容器

第 20 行

字段

paths: []const LazyPath = &.{}
exclude_paths: []const LazyPath = &.{}
check: bool = false

若为 true,遇到不符合规范的文件时使构建步骤失败。

std.Build.Step.Fmt.std

别名

第 6 行

别名目标 std

std.Build.Step.Fmt.Step

别名

第 7 行

别名目标 std.Build.Step

源码

std/Build/Step/Fmt.zig

//! 此步骤具有两种模式:
//! * 修改模式:直接修改源码文件,原地格式化。
//! * 检查模式:发现不符合规范的文件时使步骤失败。
const Fmt = @This();

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

step: Step,
/// 创建 `Fmt` 步骤后,预期仅供读取。
paths: []const LazyPath,
/// 创建 `Fmt` 步骤后,预期仅供读取。
exclude_paths: []const LazyPath,
check: bool,

pub const base_tag: Step.Tag = .fmt;

pub const Options = struct {
    paths: []const LazyPath = &.{},
    exclude_paths: []const LazyPath = &.{},
    /// 若为 true,遇到不符合规范的文件时使构建步骤失败。
    check: bool = false,
};

pub fn create(owner: *std.Build, options: Options) *Fmt {
    const graph = owner.graph;
    const fmt = graph.create(Fmt);

    fmt.* = .{
        .step = .init(.{
            .tag = base_tag,
            .name = if (options.check) "zig fmt --check" else "zig fmt",
            .owner = owner,
        }),
        .paths = LazyPath.dupeList(options.paths, graph),
        .exclude_paths = LazyPath.dupeList(options.exclude_paths, graph),
        .check = options.check,
    };

    for (options.paths) |lp| lp.addStepDependencies(&fmt.step);
    for (options.exclude_paths) |lp| lp.addStepDependencies(&fmt.step);

    return fmt;
}