mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 11:13:08 +00:00
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.
This commit is contained in:
parent
42658de762
commit
af7afbd08b
@ -269,7 +269,17 @@ const Allocator = std.mem.Allocator;
|
|||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void {
|
pub fn evalChildProcess(s: *Step, argv: []const []const u8) ![]u8 {
|
||||||
|
const run_result = try captureChildProcess(s, std.Progress.Node.none, argv);
|
||||||
|
try handleChildProcessTerm(s, run_result.term, null, argv);
|
||||||
|
return run_result.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn captureChildProcess(
|
||||||
|
s: *Step,
|
||||||
|
progress_node: std.Progress.Node,
|
||||||
|
argv: []const []const u8,
|
||||||
|
) !std.process.Child.RunResult {
|
||||||
const arena = s.owner.allocator;
|
const arena = s.owner.allocator;
|
||||||
|
|
||||||
try handleChildProcUnsupported(s, null, argv);
|
try handleChildProcUnsupported(s, null, argv);
|
||||||
@ -278,13 +288,14 @@ pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void {
|
|||||||
const result = std.process.Child.run(.{
|
const result = std.process.Child.run(.{
|
||||||
.allocator = arena,
|
.allocator = arena,
|
||||||
.argv = argv,
|
.argv = argv,
|
||||||
|
.progress_node = progress_node,
|
||||||
}) catch |err| return s.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
|
}) catch |err| return s.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
|
||||||
|
|
||||||
if (result.stderr.len > 0) {
|
if (result.stderr.len > 0) {
|
||||||
try s.result_error_msgs.append(arena, result.stderr);
|
try s.result_error_msgs.append(arena, result.stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
try handleChildProcessTerm(s, result.term, null, argv);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fail(step: *Step, comptime fmt: []const u8, args: anytype) error{ OutOfMemory, MakeFailed } {
|
pub fn fail(step: *Step, comptime fmt: []const u8, args: anytype) error{ OutOfMemory, MakeFailed } {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user