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;...@@ -19,19 +19,6 @@ pub const exit = os.exit;
19pub const changeCurDir = os.chdir;19pub const changeCurDir = os.chdir;
20pub const changeCurDirC = os.chdirC;20pub 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
35/// The result is a slice of `out_buffer`, from index `0`.22/// The result is a slice of `out_buffer`, from index `0`.
36pub fn getCwd(out_buffer: []u8) ![]u8 {23pub fn getCwd(out_buffer: []u8) ![]u8 {
37 return os.getcwd(out_buffer);24 return os.getcwd(out_buffer);
src/main.zig+19-6
...@@ -437,7 +437,7 @@ pub fn buildOutputType(...@@ -437,7 +437,7 @@ pub fn buildOutputType(
437 if (mem.startsWith(u8, arg, "-")) {437 if (mem.startsWith(u8, arg, "-")) {
438 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {438 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
439 try io.getStdOut().writeAll(usage_build_generic);439 try io.getStdOut().writeAll(usage_build_generic);
440 return process.cleanExit();440 return cleanExit();
441 } else if (mem.eql(u8, arg, "--")) {441 } else if (mem.eql(u8, arg, "--")) {
442 if (arg_mode == .run) {442 if (arg_mode == .run) {
443 runtime_args_start = i + 1;443 runtime_args_start = i + 1;
...@@ -1506,7 +1506,7 @@ pub fn buildOutputType(...@@ -1506,7 +1506,7 @@ pub fn buildOutputType(
1506 else => process.exit(1),1506 else => process.exit(1),
1507 }1507 }
1508 if (!watch)1508 if (!watch)
1509 return process.cleanExit();1509 return cleanExit();
1510 },1510 },
1511 else => {},1511 else => {},
1512 }1512 }
...@@ -1667,7 +1667,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {...@@ -1667,7 +1667,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {
1667 if (mem.eql(u8, arg, "--help")) {1667 if (mem.eql(u8, arg, "--help")) {
1668 const stdout = io.getStdOut().writer();1668 const stdout = io.getStdOut().writer();
1669 try stdout.writeAll(usage_libc);1669 try stdout.writeAll(usage_libc);
1670 return process.cleanExit();1670 return cleanExit();
1671 } else {1671 } else {
1672 fatal("unrecognized parameter: '{}'", .{arg});1672 fatal("unrecognized parameter: '{}'", .{arg});
1673 }1673 }
...@@ -1724,7 +1724,7 @@ pub fn cmdInit(...@@ -1724,7 +1724,7 @@ pub fn cmdInit(
1724 if (mem.startsWith(u8, arg, "-")) {1724 if (mem.startsWith(u8, arg, "-")) {
1725 if (mem.eql(u8, arg, "--help")) {1725 if (mem.eql(u8, arg, "--help")) {
1726 try io.getStdOut().writeAll(usage_init);1726 try io.getStdOut().writeAll(usage_init);
1727 return process.cleanExit();1727 return cleanExit();
1728 } else {1728 } else {
1729 fatal("unrecognized parameter: '{}'", .{arg});1729 fatal("unrecognized parameter: '{}'", .{arg});
1730 }1730 }
...@@ -2012,7 +2012,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2012,7 +2012,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2012 const term = try child.spawnAndWait();2012 const term = try child.spawnAndWait();
2013 switch (term) {2013 switch (term) {
2014 .Exited => |code| {2014 .Exited => |code| {
2015 if (code == 0) return process.cleanExit();2015 if (code == 0) return cleanExit();
2016 try cmd.writer().print("failed with exit code {}:\n", .{code});2016 try cmd.writer().print("failed with exit code {}:\n", .{code});
2017 },2017 },
2018 else => {2018 else => {
...@@ -2073,7 +2073,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {...@@ -2073,7 +2073,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2073 if (mem.eql(u8, arg, "--help")) {2073 if (mem.eql(u8, arg, "--help")) {
2074 const stdout = io.getStdOut().outStream();2074 const stdout = io.getStdOut().outStream();
2075 try stdout.writeAll(usage_fmt);2075 try stdout.writeAll(usage_fmt);
2076 return process.cleanExit();2076 return cleanExit();
2077 } else if (mem.eql(u8, arg, "--color")) {2077 } else if (mem.eql(u8, arg, "--color")) {
2078 if (i + 1 >= args.len) {2078 if (i + 1 >= args.len) {
2079 fatal("expected [auto|on|off] after --color", .{});2079 fatal("expected [auto|on|off] after --color", .{});
...@@ -2804,3 +2804,16 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s...@@ -2804,3 +2804,16 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s
2804 }2804 }
2805 return info;2805 return info;
2806}2806}
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}