authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 20:52:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 20:52:33-07:00
log7bbd152dcc67e825c1743b5415493fb36bed89c6
treee9ded5f6cdc57090e756b0f08ee768618dab61a1
parentb08fd0e8fca5ff9ac5531437f5749e74dc009a14

nobody likes my std.process.cleanExit idea

it's appropriate for the self-hosted compiler though, so this commit moves it from std lib to stage2 src code.

2 files changed, 19 insertions(+), 19 deletions(-)

lib/std/process.zig-13
......@@ -19,19 +19,6 @@ pub const exit = os.exit;
1919pub const changeCurDir = os.chdir;
2020pub const changeCurDirC = os.chdirC;
2121
22/// Indicate that we are now terminating with a successful exit code.
23/// In debug builds, this is a no-op, so that the calling code's
24/// cleanup mechanisms are tested and so that external tools that
25/// check for resource leaks can be accurate. In release builds, this
26/// calls exit(0), and does not return.
27pub fn cleanExit() void {
28 if (builtin.mode == .Debug) {
29 return;
30 } else {
31 exit(0);
32 }
33}
34
3522/// The result is a slice of `out_buffer`, from index `0`.
3623pub fn getCwd(out_buffer: []u8) ![]u8 {
3724 return os.getcwd(out_buffer);
src/main.zig+19-6
......@@ -437,7 +437,7 @@ pub fn buildOutputType(
437437 if (mem.startsWith(u8, arg, "-")) {
438438 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
439439 try io.getStdOut().writeAll(usage_build_generic);
440 return process.cleanExit();
440 return cleanExit();
441441 } else if (mem.eql(u8, arg, "--")) {
442442 if (arg_mode == .run) {
443443 runtime_args_start = i + 1;
......@@ -1506,7 +1506,7 @@ pub fn buildOutputType(
15061506 else => process.exit(1),
15071507 }
15081508 if (!watch)
1509 return process.cleanExit();
1509 return cleanExit();
15101510 },
15111511 else => {},
15121512 }
......@@ -1667,7 +1667,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {
16671667 if (mem.eql(u8, arg, "--help")) {
16681668 const stdout = io.getStdOut().writer();
16691669 try stdout.writeAll(usage_libc);
1670 return process.cleanExit();
1670 return cleanExit();
16711671 } else {
16721672 fatal("unrecognized parameter: '{}'", .{arg});
16731673 }
......@@ -1724,7 +1724,7 @@ pub fn cmdInit(
17241724 if (mem.startsWith(u8, arg, "-")) {
17251725 if (mem.eql(u8, arg, "--help")) {
17261726 try io.getStdOut().writeAll(usage_init);
1727 return process.cleanExit();
1727 return cleanExit();
17281728 } else {
17291729 fatal("unrecognized parameter: '{}'", .{arg});
17301730 }
......@@ -2012,7 +2012,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
20122012 const term = try child.spawnAndWait();
20132013 switch (term) {
20142014 .Exited => |code| {
2015 if (code == 0) return process.cleanExit();
2015 if (code == 0) return cleanExit();
20162016 try cmd.writer().print("failed with exit code {}:\n", .{code});
20172017 },
20182018 else => {
......@@ -2073,7 +2073,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
20732073 if (mem.eql(u8, arg, "--help")) {
20742074 const stdout = io.getStdOut().outStream();
20752075 try stdout.writeAll(usage_fmt);
2076 return process.cleanExit();
2076 return cleanExit();
20772077 } else if (mem.eql(u8, arg, "--color")) {
20782078 if (i + 1 >= args.len) {
20792079 fatal("expected [auto|on|off] after --color", .{});
......@@ -2804,3 +2804,16 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s
28042804 }
28052805 return info;
28062806}
2807
2808/// Indicate that we are now terminating with a successful exit code.
2809/// In debug builds, this is a no-op, so that the calling code's
2810/// cleanup mechanisms are tested and so that external tools that
2811/// check for resource leaks can be accurate. In release builds, this
2812/// calls exit(0), and does not return.
2813pub fn cleanExit() void {
2814 if (std.builtin.mode == .Debug) {
2815 return;
2816 } else {
2817 process.exit(0);
2818 }
2819}