| ... | @@ -1487,7 +1487,7 @@ pub fn buildOutputType( | ... | @@ -1487,7 +1487,7 @@ pub fn buildOutputType( |
| 1487 | try argv.appendSlice(all_args[i..]); | 1487 | try argv.appendSlice(all_args[i..]); |
| 1488 | } | 1488 | } |
| 1489 | // TODO On operating systems that support it, do an execve here rather than child process, | 1489 | // 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 |
| 1491 | const child = try std.ChildProcess.init(argv.items, gpa); | 1491 | const child = try std.ChildProcess.init(argv.items, gpa); |
| 1492 | defer child.deinit(); | 1492 | defer child.deinit(); |
| 1493 | | 1493 | |
| ... | @@ -1496,17 +1496,38 @@ pub fn buildOutputType( | ... | @@ -1496,17 +1496,38 @@ pub fn buildOutputType( |
| 1496 | child.stderr_behavior = .Inherit; | 1496 | child.stderr_behavior = .Inherit; |
| 1497 | | 1497 | |
| 1498 | const term = try child.spawnAndWait(); | 1498 | const term = try child.spawnAndWait(); |
| 1499 | switch (term) { | 1499 | switch (arg_mode) { |
| 1500 | .Exited => |code| { | 1500 | .run => { |
| 1501 | if (code != 0) { | 1501 | switch (term) { |
| 1502 | // TODO https://github.com/ziglang/zig/issues/6342 | 1502 | .Exited => |code| { |
| 1503 | process.exit(1); | 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 | }, |
| 1504 | } | 1527 | } |
| 1505 | }, | 1528 | }, |
| 1506 | else => process.exit(1), | 1529 | else => unreachable, |
| 1507 | } | 1530 | } |
| 1508 | if (!watch) | | |
| 1509 | return cleanExit(); | | |
| 1510 | }, | 1531 | }, |
| 1511 | else => {}, | 1532 | else => {}, |
| 1512 | } | 1533 | } |
| ... | @@ -2007,28 +2028,29 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v | ... | @@ -2007,28 +2028,29 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2007 | child.stdout_behavior = .Inherit; | 2028 | child.stdout_behavior = .Inherit; |
| 2008 | child.stderr_behavior = .Inherit; | 2029 | child.stderr_behavior = .Inherit; |
| 2009 | | 2030 | |
| 2010 | var cmd = std.ArrayList(u8).init(arena); | | |
| 2011 | | | |
| 2012 | const term = try child.spawnAndWait(); | 2031 | const term = try child.spawnAndWait(); |
| 2013 | switch (term) { | 2032 | switch (term) { |
| 2014 | .Exited => |code| { | 2033 | .Exited => |code| { |
| 2015 | if (code == 0) return cleanExit(); | 2034 | 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 }); |
| 2017 | }, | 2037 | }, |
| 2018 | else => { | 2038 | else => { |
| 2019 | try cmd.appendSlice("crashed:\n"); | 2039 | const cmd = try argvCmd(arena, child_argv); |
| | 2040 | fatal("the following build command crashed:\n{}", .{cmd}); |
| 2020 | }, | 2041 | }, |
| 2021 | } | 2042 | } |
| | 2043 | } |
| 2022 | | 2044 | |
| 2023 | try cmd.append('\n'); | 2045 | fn argvCmd(allocator: *Allocator, argv: []const []const u8) ![]u8 { |
| 2024 | for (child_argv[0 .. child_argv.len - 1]) |arg| { | 2046 | var cmd = std.ArrayList(u8).init(allocator); |
| | 2047 | defer cmd.deinit(); |
| | 2048 | for (argv[0 .. argv.len - 1]) |arg| { |
| 2025 | try cmd.appendSlice(arg); | 2049 | try cmd.appendSlice(arg); |
| 2026 | try cmd.append(' '); | 2050 | try cmd.append(' '); |
| 2027 | } | 2051 | } |
| 2028 | try cmd.appendSlice(child_argv[child_argv.len - 1]); | 2052 | try cmd.appendSlice(argv[argv.len - 1]); |
| 2029 | | 2053 | return cmd.toOwnedSlice(); |
| 2030 | if (true) // Working around erroneous stage1 compile error: unreachable code on child.deinit() | | |
| 2031 | fatal("The following build command {}", .{cmd.items}); | | |
| 2032 | } | 2054 | } |
| 2033 | | 2055 | |
| 2034 | pub const usage_fmt = | 2056 | pub const usage_fmt = |