此步骤具有两种模式:
- 修改模式:直接修改源码文件,原地格式化。
- 检查模式:发现不符合规范的文件时使步骤失败。
字段
step: Step
paths: []const LazyPath创建 Fmt 步骤后,预期仅供读取。
exclude_paths: []const LazyPath创建 Fmt 步骤后,预期仅供读取。
check: bool
std.Build.Step.Fmt.base_tag
常量
Step.Tag
std.Build.Step.Fmt.Configuration
别名
std.Build.Step.Fmt.create
函数
pub fn create(owner: *std.Build, options: Options) *Fmt
参数
std.Build.Step.Fmt.Fmt
别名
别名目标 std.Build.Step.Fmt
std.Build.Step.Fmt.LazyPath
别名
别名目标 std.Build.LazyPath
std.Build.Step.Fmt.Options
容器
字段
std.Build.Step.Fmt.std
别名
别名目标 std
std.Build.Step.Fmt.Step
别名
别名目标 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;
}