| ... | ... | @@ -755,24 +755,19 @@ fn runCommand( |
| 755 | 755 | // Capture stdout and stderr to GeneratedFile objects. |
| 756 | 756 | const Stream = struct { |
| 757 | 757 | captured: ?*Output, |
| 758 | | is_null: bool, |
| 759 | | bytes: []const u8, |
| 758 | bytes: ?[]const u8, |
| 760 | 759 | }; |
| 761 | 760 | for ([_]Stream{ |
| 762 | 761 | .{ |
| 763 | 762 | .captured = self.captured_stdout, |
| 764 | | .is_null = result.stdio.stdout_null, |
| 765 | 763 | .bytes = result.stdio.stdout, |
| 766 | 764 | }, |
| 767 | 765 | .{ |
| 768 | 766 | .captured = self.captured_stderr, |
| 769 | | .is_null = result.stdio.stderr_null, |
| 770 | 767 | .bytes = result.stdio.stderr, |
| 771 | 768 | }, |
| 772 | 769 | }) |stream| { |
| 773 | 770 | if (stream.captured) |output| { |
| 774 | | assert(!stream.is_null); |
| 775 | | |
| 776 | 771 | const output_components = .{ "o", digest.?, output.basename }; |
| 777 | 772 | const output_path = try b.cache_root.join(arena, &output_components); |
| 778 | 773 | output.generated_file.path = output_path; |
| ... | ... | @@ -784,7 +779,7 @@ fn runCommand( |
| 784 | 779 | b.cache_root, sub_path_dirname, @errorName(err), |
| 785 | 780 | }); |
| 786 | 781 | }; |
| 787 | | b.cache_root.handle.writeFile(sub_path, stream.bytes) catch |err| { |
| 782 | b.cache_root.handle.writeFile(sub_path, stream.bytes.?) catch |err| { |
| 788 | 783 | return step.fail("unable to write file '{}{s}': {s}", .{ |
| 789 | 784 | b.cache_root, sub_path, @errorName(err), |
| 790 | 785 | }); |
| ... | ... | @@ -797,8 +792,7 @@ fn runCommand( |
| 797 | 792 | switch (self.stdio) { |
| 798 | 793 | .check => |checks| for (checks.items) |check| switch (check) { |
| 799 | 794 | .expect_stderr_exact => |expected_bytes| { |
| 800 | | assert(!result.stdio.stderr_null); |
| 801 | | if (!mem.eql(u8, expected_bytes, result.stdio.stderr)) { |
| 795 | if (!mem.eql(u8, expected_bytes, result.stdio.stderr.?)) { |
| 802 | 796 | return step.fail( |
| 803 | 797 | \\ |
| 804 | 798 | \\========= expected this stderr: ========= |
| ... | ... | @@ -809,14 +803,13 @@ fn runCommand( |
| 809 | 803 | \\{s} |
| 810 | 804 | , .{ |
| 811 | 805 | expected_bytes, |
| 812 | | result.stdio.stderr, |
| 806 | result.stdio.stderr.?, |
| 813 | 807 | try Step.allocPrintCmd(arena, self.cwd, final_argv), |
| 814 | 808 | }); |
| 815 | 809 | } |
| 816 | 810 | }, |
| 817 | 811 | .expect_stderr_match => |match| { |
| 818 | | assert(!result.stdio.stderr_null); |
| 819 | | if (mem.indexOf(u8, result.stdio.stderr, match) == null) { |
| 812 | if (mem.indexOf(u8, result.stdio.stderr.?, match) == null) { |
| 820 | 813 | return step.fail( |
| 821 | 814 | \\ |
| 822 | 815 | \\========= expected to find in stderr: ========= |
| ... | ... | @@ -827,14 +820,13 @@ fn runCommand( |
| 827 | 820 | \\{s} |
| 828 | 821 | , .{ |
| 829 | 822 | match, |
| 830 | | result.stdio.stderr, |
| 823 | result.stdio.stderr.?, |
| 831 | 824 | try Step.allocPrintCmd(arena, self.cwd, final_argv), |
| 832 | 825 | }); |
| 833 | 826 | } |
| 834 | 827 | }, |
| 835 | 828 | .expect_stdout_exact => |expected_bytes| { |
| 836 | | assert(!result.stdio.stdout_null); |
| 837 | | if (!mem.eql(u8, expected_bytes, result.stdio.stdout)) { |
| 829 | if (!mem.eql(u8, expected_bytes, result.stdio.stdout.?)) { |
| 838 | 830 | return step.fail( |
| 839 | 831 | \\ |
| 840 | 832 | \\========= expected this stdout: ========= |
| ... | ... | @@ -845,14 +837,13 @@ fn runCommand( |
| 845 | 837 | \\{s} |
| 846 | 838 | , .{ |
| 847 | 839 | expected_bytes, |
| 848 | | result.stdio.stdout, |
| 840 | result.stdio.stdout.?, |
| 849 | 841 | try Step.allocPrintCmd(arena, self.cwd, final_argv), |
| 850 | 842 | }); |
| 851 | 843 | } |
| 852 | 844 | }, |
| 853 | 845 | .expect_stdout_match => |match| { |
| 854 | | assert(!result.stdio.stdout_null); |
| 855 | | if (mem.indexOf(u8, result.stdio.stdout, match) == null) { |
| 846 | if (mem.indexOf(u8, result.stdio.stdout.?, match) == null) { |
| 856 | 847 | return step.fail( |
| 857 | 848 | \\ |
| 858 | 849 | \\========= expected to find in stdout: ========= |
| ... | ... | @@ -863,7 +854,7 @@ fn runCommand( |
| 863 | 854 | \\{s} |
| 864 | 855 | , .{ |
| 865 | 856 | match, |
| 866 | | result.stdio.stdout, |
| 857 | result.stdio.stdout.?, |
| 867 | 858 | try Step.allocPrintCmd(arena, self.cwd, final_argv), |
| 868 | 859 | }); |
| 869 | 860 | } |
| ... | ... | @@ -982,12 +973,8 @@ fn spawnChildAndCollect( |
| 982 | 973 | } |
| 983 | 974 | |
| 984 | 975 | const StdIoResult = struct { |
| 985 | | // These use boolean flags instead of optionals as a workaround for |
| 986 | | // https://github.com/ziglang/zig/issues/14783 |
| 987 | | stdout: []const u8, |
| 988 | | stderr: []const u8, |
| 989 | | stdout_null: bool, |
| 990 | | stderr_null: bool, |
| 976 | stdout: ?[]const u8, |
| 977 | stderr: ?[]const u8, |
| 991 | 978 | test_results: Step.TestResults, |
| 992 | 979 | test_metadata: ?TestMetadata, |
| 993 | 980 | }; |
| ... | ... | @@ -1115,10 +1102,8 @@ fn evalZigTest( |
| 1115 | 1102 | child.stdin = null; |
| 1116 | 1103 | |
| 1117 | 1104 | return .{ |
| 1118 | | .stdout = &.{}, |
| 1119 | | .stderr = &.{}, |
| 1120 | | .stdout_null = true, |
| 1121 | | .stderr_null = true, |
| 1105 | .stdout = null, |
| 1106 | .stderr = null, |
| 1122 | 1107 | .test_results = .{ |
| 1123 | 1108 | .test_count = test_count, |
| 1124 | 1109 | .fail_count = fail_count, |
| ... | ... | @@ -1204,12 +1189,8 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { |
| 1204 | 1189 | .none => {}, |
| 1205 | 1190 | } |
| 1206 | 1191 | |
| 1207 | | // These are not optionals, as a workaround for |
| 1208 | | // https://github.com/ziglang/zig/issues/14783 |
| 1209 | | var stdout_bytes: []const u8 = undefined; |
| 1210 | | var stderr_bytes: []const u8 = undefined; |
| 1211 | | var stdout_null = true; |
| 1212 | | var stderr_null = true; |
| 1192 | var stdout_bytes: ?[]const u8 = null; |
| 1193 | var stderr_bytes: ?[]const u8 = null; |
| 1213 | 1194 | |
| 1214 | 1195 | if (child.stdout) |stdout| { |
| 1215 | 1196 | if (child.stderr) |stderr| { |
| ... | ... | @@ -1228,33 +1209,27 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { |
| 1228 | 1209 | |
| 1229 | 1210 | stdout_bytes = try poller.fifo(.stdout).toOwnedSlice(); |
| 1230 | 1211 | stderr_bytes = try poller.fifo(.stderr).toOwnedSlice(); |
| 1231 | | stdout_null = false; |
| 1232 | | stderr_null = false; |
| 1233 | 1212 | } else { |
| 1234 | 1213 | stdout_bytes = try stdout.reader().readAllAlloc(arena, self.max_stdio_size); |
| 1235 | | stdout_null = false; |
| 1236 | 1214 | } |
| 1237 | 1215 | } else if (child.stderr) |stderr| { |
| 1238 | 1216 | stderr_bytes = try stderr.reader().readAllAlloc(arena, self.max_stdio_size); |
| 1239 | | stderr_null = false; |
| 1240 | 1217 | } |
| 1241 | 1218 | |
| 1242 | | if (!stderr_null and stderr_bytes.len > 0) { |
| 1219 | if (stderr_bytes) |bytes| if (bytes.len > 0) { |
| 1243 | 1220 | // Treat stderr as an error message. |
| 1244 | 1221 | const stderr_is_diagnostic = self.captured_stderr == null and switch (self.stdio) { |
| 1245 | 1222 | .check => |checks| !checksContainStderr(checks.items), |
| 1246 | 1223 | else => true, |
| 1247 | 1224 | }; |
| 1248 | 1225 | if (stderr_is_diagnostic) { |
| 1249 | | try self.step.result_error_msgs.append(arena, stderr_bytes); |
| 1226 | try self.step.result_error_msgs.append(arena, bytes); |
| 1250 | 1227 | } |
| 1251 | | } |
| 1228 | }; |
| 1252 | 1229 | |
| 1253 | 1230 | return .{ |
| 1254 | 1231 | .stdout = stdout_bytes, |
| 1255 | 1232 | .stderr = stderr_bytes, |
| 1256 | | .stdout_null = stdout_null, |
| 1257 | | .stderr_null = stderr_null, |
| 1258 | 1233 | .test_results = .{}, |
| 1259 | 1234 | .test_metadata = null, |
| 1260 | 1235 | }; |