authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:30:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:30:14-07:00
logeb8201afde98d9ba35d0c8488d418b1b0bef4f35
tree0d16a5b43fe2c5e1f6190d3d627269e22500d0a4
parentaf7afbd08b9c74c0d65ddda9f495e497c4c5e5a1

std.Build.Step.Fmt: display non-conforming files

When in --check mode, and files are found to not conform, emit them explicitly as step errors. Previously this stdout data was being ignored.

1 files changed, 11 insertions(+), 4 deletions(-)

lib/std/Build/Step/Fmt.zig+11-4
...@@ -37,9 +37,6 @@ pub fn create(owner: *std.Build, options: Options) *Fmt {...@@ -37,9 +37,6 @@ pub fn create(owner: *std.Build, options: Options) *Fmt {
37}37}
3838
39fn make(step: *Step, prog_node: std.Progress.Node) !void {39fn make(step: *Step, prog_node: std.Progress.Node) !void {
40 // zig fmt is fast enough that no progress is needed.
41 _ = prog_node;
42
43 // TODO: if check=false, this means we are modifying source files in place, which40 // TODO: if check=false, this means we are modifying source files in place, which
44 // is an operation that could race against other operations also modifying source files41 // is an operation that could race against other operations also modifying source files
45 // in place. In this case, this step should obtain a write lock while making those42 // in place. In this case, this step should obtain a write lock while making those
...@@ -68,5 +65,15 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {...@@ -68,5 +65,15 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
68 argv.appendAssumeCapacity(b.pathFromRoot(p));65 argv.appendAssumeCapacity(b.pathFromRoot(p));
69 }66 }
7067
71 return step.evalChildProcess(argv.items);68 const run_result = try step.captureChildProcess(prog_node, argv.items);
69 if (fmt.check) switch (run_result.term) {
70 .Exited => |code| if (code != 0 and run_result.stdout.len != 0) {
71 var it = std.mem.tokenizeScalar(u8, run_result.stdout, '\n');
72 while (it.next()) |bad_file_name| {
73 try step.addError("{s}: non-conforming formatting", .{bad_file_name});
74 }
75 },
76 else => {},
77 };
78 try step.handleChildProcessTerm(run_result.term, null, argv.items);
72}79}