authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 23:13:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 23:13:18-07:00
log1123c909872569e9a956f9110685c417036118bd
treed5969ee7f636426c74ec7685d853b2d6191e5b8b
parent7bbd152dcc67e825c1743b5415493fb36bed89c6

stage2: print the test command after it fails


1 files changed, 41 insertions(+), 19 deletions(-)

src/main.zig+41-19
......@@ -1487,7 +1487,7 @@ pub fn buildOutputType(
14871487 try argv.appendSlice(all_args[i..]);
14881488 }
14891489 // TODO On operating systems that support it, do an execve here rather than child process,
1490 // when watch=false.
1490 // when watch=false and arg_mode == .run
14911491 const child = try std.ChildProcess.init(argv.items, gpa);
14921492 defer child.deinit();
14931493
......@@ -1496,17 +1496,38 @@ pub fn buildOutputType(
14961496 child.stderr_behavior = .Inherit;
14971497
14981498 const term = try child.spawnAndWait();
1499 switch (term) {
1500 .Exited => |code| {
1501 if (code != 0) {
1502 // TODO https://github.com/ziglang/zig/issues/6342
1503 process.exit(1);
1499 switch (arg_mode) {
1500 .run => {
1501 switch (term) {
1502 .Exited => |code| {
1503 if (code == 0) {
1504 if (!watch) return cleanExit();
1505 } else {
1506 // TODO https://github.com/ziglang/zig/issues/6342
1507 process.exit(1);
1508 }
1509 },
1510 else => process.exit(1),
1511 }
1512 },
1513 .zig_test => {
1514 switch (term) {
1515 .Exited => |code| {
1516 if (code == 0) {
1517 if (!watch) return cleanExit();
1518 } else {
1519 const cmd = try argvCmd(arena, argv.items);
1520 fatal("the following test command failed with exit code {}:\n{}", .{ code, cmd });
1521 }
1522 },
1523 else => {
1524 const cmd = try argvCmd(arena, argv.items);
1525 fatal("the following test command crashed:\n{}", .{cmd});
1526 },
15041527 }
15051528 },
1506 else => process.exit(1),
1529 else => unreachable,
15071530 }
1508 if (!watch)
1509 return cleanExit();
15101531 },
15111532 else => {},
15121533 }
......@@ -2007,28 +2028,29 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
20072028 child.stdout_behavior = .Inherit;
20082029 child.stderr_behavior = .Inherit;
20092030
2010 var cmd = std.ArrayList(u8).init(arena);
2011
20122031 const term = try child.spawnAndWait();
20132032 switch (term) {
20142033 .Exited => |code| {
20152034 if (code == 0) return cleanExit();
2016 try cmd.writer().print("failed with exit code {}:\n", .{code});
2035 const cmd = try argvCmd(arena, child_argv);
2036 fatal("the following build command failed with exit code {}:\n{}", .{ code, cmd });
20172037 },
20182038 else => {
2019 try cmd.appendSlice("crashed:\n");
2039 const cmd = try argvCmd(arena, child_argv);
2040 fatal("the following build command crashed:\n{}", .{cmd});
20202041 },
20212042 }
2043}
20222044
2023 try cmd.append('\n');
2024 for (child_argv[0 .. child_argv.len - 1]) |arg| {
2045fn argvCmd(allocator: *Allocator, argv: []const []const u8) ![]u8 {
2046 var cmd = std.ArrayList(u8).init(allocator);
2047 defer cmd.deinit();
2048 for (argv[0 .. argv.len - 1]) |arg| {
20252049 try cmd.appendSlice(arg);
20262050 try cmd.append(' ');
20272051 }
2028 try cmd.appendSlice(child_argv[child_argv.len - 1]);
2029
2030 if (true) // Working around erroneous stage1 compile error: unreachable code on child.deinit()
2031 fatal("The following build command {}", .{cmd.items});
2052 try cmd.appendSlice(argv[argv.len - 1]);
2053 return cmd.toOwnedSlice();
20322054}
20332055
20342056pub const usage_fmt =