authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:29:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:29:05-07:00
logaf7afbd08b9c74c0d65ddda9f495e497c4c5e5a1
treedd7402eb4d2b317d5ab8fc588174ffda9168eee7
parent42658de76287ecd24691d774232c5ec07107a0ee

std.Build.Step: split evalChildProcess into two functions

Now there is `captureChildProcess` which gives access to the `std.process.Child.RunResult`, which is useful for accessing the stdout. It also accepts and passes an optional `std.Progress.Node` to the child.

1 files changed, 13 insertions(+), 2 deletions(-)

lib/std/Build/Step.zig+13-2
......@@ -269,7 +269,17 @@ const Allocator = std.mem.Allocator;
269269const assert = std.debug.assert;
270270const builtin = @import("builtin");
271271
272pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void {
272pub fn evalChildProcess(s: *Step, argv: []const []const u8) ![]u8 {
273 const run_result = try captureChildProcess(s, std.Progress.Node.none, argv);
274 try handleChildProcessTerm(s, run_result.term, null, argv);
275 return run_result.stdout;
276}
277
278pub fn captureChildProcess(
279 s: *Step,
280 progress_node: std.Progress.Node,
281 argv: []const []const u8,
282) !std.process.Child.RunResult {
273283 const arena = s.owner.allocator;
274284
275285 try handleChildProcUnsupported(s, null, argv);
......@@ -278,13 +288,14 @@ pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void {
278288 const result = std.process.Child.run(.{
279289 .allocator = arena,
280290 .argv = argv,
291 .progress_node = progress_node,
281292 }) catch |err| return s.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
282293
283294 if (result.stderr.len > 0) {
284295 try s.result_error_msgs.append(arena, result.stderr);
285296 }
286297
287 try handleChildProcessTerm(s, result.term, null, argv);
298 return result;
288299}
289300
290301pub fn fail(step: *Step, comptime fmt: []const u8, args: anytype) error{ OutOfMemory, MakeFailed } {