| author | |
| committer | |
| log | 1d2b870501ab4ef6adb38c817976669c0329329c |
| tree | 88b9ad9859c5cc1fb7ebb2cf09a03fab09d010ed |
| parent | 5e6b8e17eff77107af7fb69cf86009bd45222778 |
5 files changed, 38 insertions(+), 97 deletions(-)
lib/std/Build/Step.zig+15-15| ... | @@ -510,13 +510,13 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { | ... | @@ -510,13 +510,13 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { |
| 510 | 510 | ||
| 511 | var result: ?Path = null; | 511 | var result: ?Path = null; |
| 512 | 512 | ||
| 513 | const stdout_br = zp.poller.reader(.stdout); | 513 | const stdout = zp.poller.reader(.stdout); |
| 514 | poll: while (true) { | 514 | poll: while (true) { |
| 515 | const Header = std.zig.Server.Message.Header; | 515 | const Header = std.zig.Server.Message.Header; |
| 516 | while (stdout_br.buffered().len < @sizeOf(Header)) if (!try zp.poller.poll()) break :poll; | 516 | while (stdout.buffered().len < @sizeOf(Header)) if (!try zp.poller.poll()) break :poll; |
| 517 | const header = (stdout_br.takeStruct(Header) catch unreachable).*; | 517 | const header = (stdout.takeStruct(Header) catch unreachable).*; |
| 518 | while (stdout_br.buffered().len < header.bytes_len) if (!try zp.poller.poll()) break :poll; | 518 | while (stdout.buffered().len < header.bytes_len) if (!try zp.poller.poll()) break :poll; |
| 519 | const body = stdout_br.take(header.bytes_len) catch unreachable; | 519 | const body = stdout.take(header.bytes_len) catch unreachable; |
| 520 | switch (header.tag) { | 520 | switch (header.tag) { |
| 521 | .zig_version => { | 521 | .zig_version => { |
| 522 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { | 522 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| ... | @@ -606,8 +606,8 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { | ... | @@ -606,8 +606,8 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { |
| 606 | 606 | ||
| 607 | s.result_duration_ns = timer.read(); | 607 | s.result_duration_ns = timer.read(); |
| 608 | 608 | ||
| 609 | const stderr_br = zp.poller.reader(.stderr); | 609 | const stderr = zp.poller.reader(.stderr); |
| 610 | const stderr_contents = stderr_br.buffered(); | 610 | const stderr_contents = stderr.buffered(); |
| 611 | if (stderr_contents.len > 0) { | 611 | if (stderr_contents.len > 0) { |
| 612 | try s.result_error_msgs.append(arena, try arena.dupe(u8, stderr_contents)); | 612 | try s.result_error_msgs.append(arena, try arena.dupe(u8, stderr_contents)); |
| 613 | } | 613 | } |
| ... | @@ -761,8 +761,8 @@ pub fn allocPrintCmd2( | ... | @@ -761,8 +761,8 @@ pub fn allocPrintCmd2( |
| 761 | }; | 761 | }; |
| 762 | 762 | ||
| 763 | var aw: std.io.Writer.Allocating = .init(arena); | 763 | var aw: std.io.Writer.Allocating = .init(arena); |
| 764 | const w = &aw.interface; | 764 | const writer = &aw.writer; |
| 765 | if (opt_cwd) |cwd| try w.print(arena, "cd {s} && ", .{cwd}); | 765 | if (opt_cwd) |cwd| try writer.print(arena, "cd {s} && ", .{cwd}); |
| 766 | if (opt_env) |env| { | 766 | if (opt_env) |env| { |
| 767 | const process_env_map = std.process.getEnvMap(arena) catch std.process.EnvMap.init(arena); | 767 | const process_env_map = std.process.getEnvMap(arena) catch std.process.EnvMap.init(arena); |
| 768 | var it = env.iterator(); | 768 | var it = env.iterator(); |
| ... | @@ -772,15 +772,15 @@ pub fn allocPrintCmd2( | ... | @@ -772,15 +772,15 @@ pub fn allocPrintCmd2( |
| 772 | if (process_env_map.get(key)) |process_value| { | 772 | if (process_env_map.get(key)) |process_value| { |
| 773 | if (std.mem.eql(u8, value, process_value)) continue; | 773 | if (std.mem.eql(u8, value, process_value)) continue; |
| 774 | } | 774 | } |
| 775 | try w.print(arena, "{s}=", .{key}); | 775 | try writer.print(arena, "{s}=", .{key}); |
| 776 | try shell.escape(w, value, false); | 776 | try shell.escape(writer, value, false); |
| 777 | try w.writeByte(arena, ' '); | 777 | try writer.writeByte(arena, ' '); |
| 778 | } | 778 | } |
| 779 | } | 779 | } |
| 780 | try shell.escape(w, argv[0], true); | 780 | try shell.escape(writer, argv[0], true); |
| 781 | for (argv[1..]) |arg| { | 781 | for (argv[1..]) |arg| { |
| 782 | try w.writeByte(arena, ' '); | 782 | try writer.writeByte(arena, ' '); |
| 783 | try shell.escape(w, arg, false); | 783 | try shell.escape(writer, arg, false); |
| 784 | } | 784 | } |
| 785 | return aw.getWritten(); | 785 | return aw.getWritten(); |
| 786 | } | 786 | } |
lib/std/Build/Step/Run.zig+14-14| ... | @@ -73,12 +73,12 @@ skip_foreign_checks: bool, | ... | @@ -73,12 +73,12 @@ skip_foreign_checks: bool, |
| 73 | /// external executor (such as qemu) but not fail if the executor is unavailable. | 73 | /// external executor (such as qemu) but not fail if the executor is unavailable. |
| 74 | failing_to_execute_foreign_is_an_error: bool, | 74 | failing_to_execute_foreign_is_an_error: bool, |
| 75 | 75 | ||
| 76 | /// Deprecated for `stdio_limit`. | 76 | /// Deprecated in favor of `stdio_limit`. |
| 77 | max_stdio_size: usize, | 77 | max_stdio_size: usize, |
| 78 | 78 | ||
| 79 | /// If stderr or stdout exceeds this amount, the child process is killed and | 79 | /// If stderr or stdout exceeds this amount, the child process is killed and |
| 80 | /// the step fails. | 80 | /// the step fails. |
| 81 | stdio_limit: std.io.Limit, | 81 | stdio_limit: std.Io.Limit, |
| 82 | 82 | ||
| 83 | captured_stdout: ?*Output, | 83 | captured_stdout: ?*Output, |
| 84 | captured_stderr: ?*Output, | 84 | captured_stderr: ?*Output, |
| ... | @@ -1015,7 +1015,7 @@ fn populateGeneratedPaths( | ... | @@ -1015,7 +1015,7 @@ fn populateGeneratedPaths( |
| 1015 | } | 1015 | } |
| 1016 | } | 1016 | } |
| 1017 | 1017 | ||
| 1018 | fn formatTerm(term: ?std.process.Child.Term, w: *std.io.Writer) std.io.Writer.Error!void { | 1018 | fn formatTerm(term: ?std.process.Child.Term, w: *std.Io.Writer) std.Io.Writer.Error!void { |
| 1019 | if (term) |t| switch (t) { | 1019 | if (term) |t| switch (t) { |
| 1020 | .Exited => |code| try w.print("exited with code {d}", .{code}), | 1020 | .Exited => |code| try w.print("exited with code {d}", .{code}), |
| 1021 | .Signal => |sig| try w.print("terminated with signal {d}", .{sig}), | 1021 | .Signal => |sig| try w.print("terminated with signal {d}", .{sig}), |
| ... | @@ -1504,7 +1504,7 @@ fn evalZigTest( | ... | @@ -1504,7 +1504,7 @@ fn evalZigTest( |
| 1504 | const gpa = run.step.owner.allocator; | 1504 | const gpa = run.step.owner.allocator; |
| 1505 | const arena = run.step.owner.allocator; | 1505 | const arena = run.step.owner.allocator; |
| 1506 | 1506 | ||
| 1507 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ | 1507 | var poller = std.Io.poll(gpa, enum { stdout, stderr }, .{ |
| 1508 | .stdout = child.stdout.?, | 1508 | .stdout = child.stdout.?, |
| 1509 | .stderr = child.stderr.?, | 1509 | .stderr = child.stderr.?, |
| 1510 | }); | 1510 | }); |
| ... | @@ -1540,14 +1540,14 @@ fn evalZigTest( | ... | @@ -1540,14 +1540,14 @@ fn evalZigTest( |
| 1540 | var sub_prog_node: ?std.Progress.Node = null; | 1540 | var sub_prog_node: ?std.Progress.Node = null; |
| 1541 | defer if (sub_prog_node) |n| n.end(); | 1541 | defer if (sub_prog_node) |n| n.end(); |
| 1542 | 1542 | ||
| 1543 | const stdout_br = poller.reader(.stdout); | 1543 | const stdout = poller.reader(.stdout); |
| 1544 | const stderr_br = poller.reader(.stderr); | 1544 | const stderr = poller.reader(.stderr); |
| 1545 | const any_write_failed = first_write_failed or poll: while (true) { | 1545 | const any_write_failed = first_write_failed or poll: while (true) { |
| 1546 | const Header = std.zig.Server.Message.Header; | 1546 | const Header = std.zig.Server.Message.Header; |
| 1547 | while (stdout_br.buffered().len < @sizeOf(Header)) if (!try poller.poll()) break :poll false; | 1547 | while (stdout.buffered().len < @sizeOf(Header)) if (!try poller.poll()) break :poll false; |
| 1548 | const header = (stdout_br.takeStruct(Header) catch unreachable).*; | 1548 | const header = (stdout.takeStruct(Header, .little) catch unreachable).*; |
| 1549 | while (stdout_br.buffered().len < header.bytes_len) if (!try poller.poll()) break :poll false; | 1549 | while (stdout.buffered().len < header.bytes_len) if (!try poller.poll()) break :poll false; |
| 1550 | const body = stdout_br.take(header.bytes_len) catch unreachable; | 1550 | const body = stdout.take(header.bytes_len) catch unreachable; |
| 1551 | switch (header.tag) { | 1551 | switch (header.tag) { |
| 1552 | .zig_version => { | 1552 | .zig_version => { |
| 1553 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { | 1553 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| ... | @@ -1604,8 +1604,8 @@ fn evalZigTest( | ... | @@ -1604,8 +1604,8 @@ fn evalZigTest( |
| 1604 | 1604 | ||
| 1605 | if (tr_hdr.flags.fail or tr_hdr.flags.leak or tr_hdr.flags.log_err_count > 0) { | 1605 | if (tr_hdr.flags.fail or tr_hdr.flags.leak or tr_hdr.flags.log_err_count > 0) { |
| 1606 | const name = std.mem.sliceTo(md.string_bytes[md.names[tr_hdr.index]..], 0); | 1606 | const name = std.mem.sliceTo(md.string_bytes[md.names[tr_hdr.index]..], 0); |
| 1607 | const stderr_contents = stderr_br.buffered(); | 1607 | const stderr_contents = stderr.buffered(); |
| 1608 | stderr_br.toss(stderr_contents.len); | 1608 | stderr.toss(stderr_contents.len); |
| 1609 | const msg = std.mem.trim(u8, stderr_contents, "\n"); | 1609 | const msg = std.mem.trim(u8, stderr_contents, "\n"); |
| 1610 | const label = if (tr_hdr.flags.fail) | 1610 | const label = if (tr_hdr.flags.fail) |
| 1611 | "failed" | 1611 | "failed" |
| ... | @@ -1665,7 +1665,7 @@ fn evalZigTest( | ... | @@ -1665,7 +1665,7 @@ fn evalZigTest( |
| 1665 | while (try poller.poll()) {} | 1665 | while (try poller.poll()) {} |
| 1666 | } | 1666 | } |
| 1667 | 1667 | ||
| 1668 | const stderr_contents = std.mem.trim(u8, stderr_br.buffered(), "\n"); | 1668 | const stderr_contents = std.mem.trim(u8, stderr.buffered(), "\n"); |
| 1669 | if (stderr_contents.len > 0) { | 1669 | if (stderr_contents.len > 0) { |
| 1670 | run.step.result_stderr = try arena.dupe(u8, stderr_contents); | 1670 | run.step.result_stderr = try arena.dupe(u8, stderr_contents); |
| 1671 | } | 1671 | } |
| ... | @@ -1793,7 +1793,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { | ... | @@ -1793,7 +1793,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1793 | run.stdio_limit = run.stdio_limit.min(.limited(run.max_stdio_size)); | 1793 | run.stdio_limit = run.stdio_limit.min(.limited(run.max_stdio_size)); |
| 1794 | if (child.stdout) |stdout| { | 1794 | if (child.stdout) |stdout| { |
| 1795 | if (child.stderr) |stderr| { | 1795 | if (child.stderr) |stderr| { |
| 1796 | var poller = std.io.poll(arena, enum { stdout, stderr }, .{ | 1796 | var poller = std.Io.poll(arena, enum { stdout, stderr }, .{ |
| 1797 | .stdout = stdout, | 1797 | .stdout = stdout, |
| 1798 | .stderr = stderr, | 1798 | .stderr = stderr, |
| 1799 | }); | 1799 | }); |
lib/std/Io.zig-3| ... | @@ -82,9 +82,6 @@ pub const Limit = enum(usize) { | ... | @@ -82,9 +82,6 @@ pub const Limit = enum(usize) { |
| 82 | pub const Reader = @import("Io/Reader.zig"); | 82 | pub const Reader = @import("Io/Reader.zig"); |
| 83 | pub const Writer = @import("Io/Writer.zig"); | 83 | pub const Writer = @import("Io/Writer.zig"); |
| 84 | 84 | ||
| 85 | pub const ChangeDetectionStream = @import("Io/change_detection_stream.zig").ChangeDetectionStream; | ||
| 86 | pub const changeDetectionStream = @import("Io/change_detection_stream.zig").changeDetectionStream; | ||
| 87 | |||
| 88 | pub const tty = @import("Io/tty.zig"); | 85 | pub const tty = @import("Io/tty.zig"); |
| 89 | 86 | ||
| 90 | pub fn poll( | 87 | pub fn poll( |
lib/std/Io/change_detection_stream.zig deleted-55| ... | @@ -1,55 +0,0 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | const io = std.io; | ||
| 3 | const mem = std.mem; | ||
| 4 | const assert = std.debug.assert; | ||
| 5 | |||
| 6 | /// Used to detect if the data written to a stream differs from a source buffer | ||
| 7 | pub fn ChangeDetectionStream(comptime WriterType: type) type { | ||
| 8 | return struct { | ||
| 9 | const Self = @This(); | ||
| 10 | pub const Error = WriterType.Error; | ||
| 11 | pub const Writer = io.GenericWriter(*Self, Error, write); | ||
| 12 | |||
| 13 | anything_changed: bool, | ||
| 14 | underlying_writer: WriterType, | ||
| 15 | source_index: usize, | ||
| 16 | source: []const u8, | ||
| 17 | |||
| 18 | pub fn writer(self: *Self) Writer { | ||
| 19 | return .{ .context = self }; | ||
| 20 | } | ||
| 21 | |||
| 22 | fn write(self: *Self, bytes: []const u8) Error!usize { | ||
| 23 | if (!self.anything_changed) { | ||
| 24 | const end = self.source_index + bytes.len; | ||
| 25 | if (end > self.source.len) { | ||
| 26 | self.anything_changed = true; | ||
| 27 | } else { | ||
| 28 | const src_slice = self.source[self.source_index..end]; | ||
| 29 | self.source_index += bytes.len; | ||
| 30 | if (!mem.eql(u8, bytes, src_slice)) { | ||
| 31 | self.anything_changed = true; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | return self.underlying_writer.write(bytes); | ||
| 37 | } | ||
| 38 | |||
| 39 | pub fn changeDetected(self: *Self) bool { | ||
| 40 | return self.anything_changed or (self.source_index != self.source.len); | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | } | ||
| 44 | |||
| 45 | pub fn changeDetectionStream( | ||
| 46 | source: []const u8, | ||
| 47 | underlying_writer: anytype, | ||
| 48 | ) ChangeDetectionStream(@TypeOf(underlying_writer)) { | ||
| 49 | return ChangeDetectionStream(@TypeOf(underlying_writer)){ | ||
| 50 | .anything_changed = false, | ||
| 51 | .underlying_writer = underlying_writer, | ||
| 52 | .source_index = 0, | ||
| 53 | .source = source, | ||
| 54 | }; | ||
| 55 | } | ||
lib/std/process/Child.zig+9-10| ... | @@ -348,7 +348,7 @@ pub const RunResult = struct { | ... | @@ -348,7 +348,7 @@ pub const RunResult = struct { |
| 348 | stderr: []u8, | 348 | stderr: []u8, |
| 349 | }; | 349 | }; |
| 350 | 350 | ||
| 351 | fn writeBufferedReaderToArrayList(allocator: Allocator, list: *std.ArrayListUnmanaged(u8), r: *std.io.Reader) !void { | 351 | fn writeBufferedReaderToArrayList(allocator: Allocator, list: *std.ArrayListUnmanaged(u8), r: *std.Io.Reader) !void { |
| 352 | assert(r.seek == 0); | 352 | assert(r.seek == 0); |
| 353 | if (list.capacity == 0) { | 353 | if (list.capacity == 0) { |
| 354 | list.* = .{ | 354 | list.* = .{ |
| ... | @@ -376,16 +376,16 @@ pub fn collectOutput( | ... | @@ -376,16 +376,16 @@ pub fn collectOutput( |
| 376 | assert(child.stdout_behavior == .Pipe); | 376 | assert(child.stdout_behavior == .Pipe); |
| 377 | assert(child.stderr_behavior == .Pipe); | 377 | assert(child.stderr_behavior == .Pipe); |
| 378 | 378 | ||
| 379 | var poller = std.io.poll(allocator, enum { stdout, stderr }, .{ | 379 | var poller = std.Io.poll(allocator, enum { stdout, stderr }, .{ |
| 380 | .stdout = child.stdout.?, | 380 | .stdout = child.stdout.?, |
| 381 | .stderr = child.stderr.?, | 381 | .stderr = child.stderr.?, |
| 382 | }); | 382 | }); |
| 383 | defer poller.deinit(); | 383 | defer poller.deinit(); |
| 384 | 384 | ||
| 385 | while (try poller.poll()) { | 385 | while (try poller.poll()) { |
| 386 | if (poller.reader(.stdout).buffered().len > max_output_bytes) | 386 | if (poller.reader(.stdout).bufferedLen() > max_output_bytes) |
| 387 | return error.StdoutStreamTooLong; | 387 | return error.StdoutStreamTooLong; |
| 388 | if (poller.reader(.stderr).buffered().len > max_output_bytes) | 388 | if (poller.reader(.stderr).bufferedLen() > max_output_bytes) |
| 389 | return error.StderrStreamTooLong; | 389 | return error.StderrStreamTooLong; |
| 390 | } | 390 | } |
| 391 | 391 | ||
| ... | @@ -1002,17 +1002,16 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { | ... | @@ -1002,17 +1002,16 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 1002 | } | 1002 | } |
| 1003 | 1003 | ||
| 1004 | fn writeIntFd(fd: i32, value: ErrInt) !void { | 1004 | fn writeIntFd(fd: i32, value: ErrInt) !void { |
| 1005 | var fw = std.fs.File.writer(.{ .handle = fd }); | ||
| 1006 | var buffer: [8]u8 = undefined; | 1005 | var buffer: [8]u8 = undefined; |
| 1007 | var bw = fw.interface().buffered(&buffer); | 1006 | var fw: std.fs.File.Writer = .initMode(.{ .handle = fd }, &buffer, .streaming); |
| 1008 | bw.writeInt(u64, value, .little) catch return error.SystemResources; | 1007 | fw.interface.writeInt(u64, value, .little) catch unreachable; |
| 1008 | fw.interface.flush() catch return error.SystemResources; | ||
| 1009 | } | 1009 | } |
| 1010 | 1010 | ||
| 1011 | fn readIntFd(fd: i32) !ErrInt { | 1011 | fn readIntFd(fd: i32) !ErrInt { |
| 1012 | var fr = std.fs.File.reader(.{ .handle = fd }); | ||
| 1013 | var buffer: [8]u8 = undefined; | 1012 | var buffer: [8]u8 = undefined; |
| 1014 | var br = fr.interface().buffered(&buffer); | 1013 | var fr: std.fs.File.Reader = .initMode(.{ .handle = fd }, &buffer, .streaming); |
| 1015 | return @intCast(br.takeInt(u64, .little) catch return error.SystemResources); | 1014 | return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources); |
| 1016 | } | 1015 | } |
| 1017 | 1016 | ||
| 1018 | const ErrInt = std.meta.Int(.unsigned, @sizeOf(anyerror) * 8); | 1017 | const ErrInt = std.meta.Int(.unsigned, @sizeOf(anyerror) * 8); |