authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-12 17:20:18-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
logec56696503e702e063af8740a77376b2e7694c29
tree0781bc186578adb488bbce306970e4ba971ea06c
parente68ae8d7a1e78a25392e271d7ca894e0f09aa218

std.process.cleanExit: take an Io parameter

In case exit(0) will be called, this provides the opportunity for the application's Io instance to be the one to clear the terminal in case std.Progress or similar was used.

5 files changed, 33 insertions(+), 33 deletions(-)

lib/compiler/libc.zig+2-2
......@@ -50,7 +50,7 @@ pub fn main() !void {
5050 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
5151 try stdout.writeAll(usage_libc);
5252 try stdout.flush();
53 return std.process.cleanExit();
53 return std.process.cleanExit(io);
5454 } else if (mem.eql(u8, arg, "-target")) {
5555 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
5656 i += 1;
......@@ -110,7 +110,7 @@ pub fn main() !void {
110110 try stdout.writeByte('\n');
111111 }
112112 try stdout.flush();
113 return std.process.cleanExit();
113 return std.process.cleanExit(io);
114114 }
115115
116116 if (input_file) |libc_file| {
lib/compiler/objcopy.zig+2-2
......@@ -235,7 +235,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
235235 const hdr = try server.receiveMessage();
236236 switch (hdr.tag) {
237237 .exit => {
238 return std.process.cleanExit();
238 return std.process.cleanExit(io);
239239 },
240240 .update => {
241241 if (seen_update) fatal("zig objcopy only supports 1 update for now", .{});
......@@ -250,7 +250,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
250250 }
251251 }
252252 }
253 return std.process.cleanExit();
253 return std.process.cleanExit(io);
254254}
255255
256256const usage =
lib/compiler/reduce.zig+3-3
......@@ -75,7 +75,7 @@ pub fn main() !void {
7575 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
7676 const stdout = Io.File.stdout();
7777 try stdout.writeAll(usage);
78 return std.process.cleanExit();
78 return std.process.cleanExit(io);
7979 } else if (mem.eql(u8, arg, "--")) {
8080 argv = args[i + 1 ..];
8181 break;
......@@ -278,10 +278,10 @@ pub fn main() !void {
278278 try tree.render(gpa, &rendered.writer, fixups);
279279 try Io.Dir.cwd().writeFile(io, .{ .sub_path = root_source_file_path, .data = rendered.written() });
280280
281 return std.process.cleanExit();
281 return std.process.cleanExit(io);
282282 }
283283 std.debug.print("no more transformations found\n", .{});
284 return std.process.cleanExit();
284 return std.process.cleanExit(io);
285285}
286286
287287fn sortTransformations(transformations: []Walk.Transformation, rng: std.Random) void {
src/fmt.zig+1-1
......@@ -60,7 +60,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
6060 if (mem.startsWith(u8, arg, "-")) {
6161 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6262 try Io.File.stdout().writeStreamingAll(io, usage_fmt);
63 return process.cleanExit();
63 return process.cleanExit(io);
6464 } else if (mem.eql(u8, arg, "--color")) {
6565 if (i + 1 >= args.len) {
6666 fatal("expected [auto|on|off] after --color", .{});
src/main.zig+25-25
......@@ -1038,7 +1038,7 @@ fn buildOutputType(
10381038 } else if (mem.startsWith(u8, arg, "-")) {
10391039 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
10401040 try Io.File.stdout().writeStreamingAll(io, usage_build_generic);
1041 return cleanExit();
1041 return cleanExit(io);
10421042 } else if (mem.eql(u8, arg, "--")) {
10431043 if (arg_mode == .run) {
10441044 // args_iter.i is 1, referring the next arg after "--" in ["--", ...]
......@@ -3646,7 +3646,7 @@ fn buildOutputType(
36463646 all_args,
36473647 runtime_args_start,
36483648 );
3649 return cleanExit();
3649 return cleanExit(io);
36503650 },
36513651 .ip4 => |ip4_addr| {
36523652 const addr: Io.net.IpAddress = .{ .ip4 = ip4_addr };
......@@ -3672,7 +3672,7 @@ fn buildOutputType(
36723672 all_args,
36733673 runtime_args_start,
36743674 );
3675 return cleanExit();
3675 return cleanExit(io);
36763676 },
36773677 }
36783678
......@@ -3755,7 +3755,7 @@ fn buildOutputType(
37553755 }
37563756
37573757 // Skip resource deallocation in release builds; let the OS do it.
3758 return cleanExit();
3758 return cleanExit(io);
37593759}
37603760
37613761const CreateModule = struct {
......@@ -4176,7 +4176,7 @@ fn serve(
41764176 defer if (comp.debugIncremental()) ids.mutex.unlock(io);
41774177
41784178 switch (hdr.tag) {
4179 .exit => return cleanExit(),
4179 .exit => return cleanExit(io),
41804180 .update => {
41814181 tracy.frameMark();
41824182 file_system_inputs.clearRetainingCapacity();
......@@ -4462,7 +4462,7 @@ fn runOrTest(
44624462 switch (term) {
44634463 .Exited => |code| {
44644464 if (code == 0) {
4465 return cleanExit();
4465 return cleanExit(io);
44664466 } else {
44674467 process.exit(code);
44684468 }
......@@ -4476,7 +4476,7 @@ fn runOrTest(
44764476 switch (term) {
44774477 .Exited => |code| {
44784478 if (code == 0) {
4479 return cleanExit();
4479 return cleanExit(io);
44804480 } else {
44814481 const cmd = try std.mem.join(arena, " ", argv.items);
44824482 fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
......@@ -4688,7 +4688,7 @@ fn cmdTranslateC(
46884688 var file_reader = zig_file.reader(io, &.{});
46894689 _ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);
46904690 try stdout_writer.interface.flush();
4691 return cleanExit();
4691 return cleanExit(io);
46924692 }
46934693}
46944694
......@@ -4735,7 +4735,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
47354735 template = .minimal;
47364736 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
47374737 try Io.File.stdout().writeStreamingAll(io, usage_init);
4738 return cleanExit();
4738 return cleanExit(io);
47394739 } else {
47404740 fatal("unrecognized parameter: '{s}'", .{arg});
47414741 }
......@@ -4780,7 +4780,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
47804780 if (ok_count == template_paths.len) {
47814781 std.log.info("see `zig build --help` for a menu of options", .{});
47824782 }
4783 return cleanExit();
4783 return cleanExit(io);
47844784 },
47854785 .minimal => {
47864786 writeSimpleTemplateFile(io, Package.Manifest.basename,
......@@ -4813,11 +4813,11 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
48134813 // their `build.zig.zon` *after* writing their `build.zig`. So this one isn't fatal.
48144814 error.PathAlreadyExists => {
48154815 std.log.info("successfully populated '{s}', preserving existing '{s}'", .{ Package.Manifest.basename, Package.build_zig_basename });
4816 return cleanExit();
4816 return cleanExit(io);
48174817 },
48184818 };
48194819 std.log.info("successfully populated '{s}' and '{s}'", .{ Package.Manifest.basename, Package.build_zig_basename });
4820 return cleanExit();
4820 return cleanExit(io);
48214821 },
48224822 }
48234823}
......@@ -5284,7 +5284,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
52845284 process.exit(1);
52855285 }
52865286
5287 if (fetch_only) return cleanExit();
5287 if (fetch_only) return cleanExit(io);
52885288
52895289 var source_buf = std.array_list.Managed(u8).init(gpa);
52905290 defer source_buf.deinit();
......@@ -5420,7 +5420,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
54205420
54215421 switch (term) {
54225422 .Exited => |code| {
5423 if (code == 0) return cleanExit();
5423 if (code == 0) return cleanExit(io);
54245424 // Indicates that the build runner has reported compile errors
54255425 // and this parent process does not need to report any further
54265426 // diagnostics.
......@@ -5691,7 +5691,7 @@ fn jitCmd(
56915691 .Exited => |code| {
56925692 if (code == 0) {
56935693 if (options.capture != null) return;
5694 return cleanExit();
5694 return cleanExit(io);
56955695 }
56965696 const cmd = try std.mem.join(arena, " ", child_argv.items);
56975697 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
......@@ -6151,7 +6151,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
61516151 if (mem.startsWith(u8, arg, "-")) {
61526152 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
61536153 try Io.File.stdout().writeStreamingAll(io, usage_ast_check);
6154 return cleanExit();
6154 return cleanExit(io);
61556155 } else if (mem.eql(u8, arg, "-t")) {
61566156 want_output_text = true;
61576157 } else if (mem.eql(u8, arg, "--zon")) {
......@@ -6222,7 +6222,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62226222 if (zir.hasCompileErrors()) {
62236223 process.exit(1);
62246224 } else {
6225 return cleanExit();
6225 return cleanExit(io);
62266226 }
62276227 }
62286228 if (!build_options.enable_debug_extensions) {
......@@ -6273,7 +6273,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62736273 if (zir.hasCompileErrors()) {
62746274 process.exit(1);
62756275 } else {
6276 return cleanExit();
6276 return cleanExit(io);
62776277 }
62786278 },
62796279 .zon => {
......@@ -6288,7 +6288,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62886288 }
62896289
62906290 if (!want_output_text) {
6291 return cleanExit();
6291 return cleanExit(io);
62926292 }
62936293
62946294 if (!build_options.enable_debug_extensions) {
......@@ -6297,7 +6297,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62976297
62986298 try @import("print_zoir.zig").renderToWriter(zoir, arena, stdout_bw);
62996299 try stdout_bw.flush();
6300 return cleanExit();
6300 return cleanExit(io);
63016301 },
63026302 }
63036303}
......@@ -6325,7 +6325,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
63256325 if (mem.startsWith(u8, arg, "-")) {
63266326 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
63276327 try Io.File.stdout().writeStreamingAll(io, detect_cpu_usage);
6328 return cleanExit();
6328 return cleanExit(io);
63296329 } else if (mem.eql(u8, arg, "--llvm")) {
63306330 use_llvm = true;
63316331 } else {
......@@ -6475,7 +6475,7 @@ fn cmdDumpLlvmInts(
64756475 }
64766476 try stdout_bw.flush();
64776477
6478 return cleanExit();
6478 return cleanExit(io);
64796479}
64806480
64816481/// This is only enabled for debug builds.
......@@ -6909,7 +6909,7 @@ fn cmdFetch(
69096909 if (mem.startsWith(u8, arg, "-")) {
69106910 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
69116911 try Io.File.stdout().writeStreamingAll(io, usage_fetch);
6912 return cleanExit();
6912 return cleanExit(io);
69136913 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
69146914 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
69156915 i += 1;
......@@ -7020,7 +7020,7 @@ fn cmdFetch(
70207020 var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer);
70217021 try stdout.interface.print("{s}\n", .{package_hash_slice});
70227022 try stdout.interface.flush();
7023 return cleanExit();
7023 return cleanExit(io);
70247024 },
70257025 .yes, .exact => |name| name: {
70267026 if (name) |n| break :name n;
......@@ -7159,7 +7159,7 @@ fn cmdFetch(
71597159 fatal("unable to write {s} file: {t}", .{ Package.Manifest.basename, err });
71607160 };
71617161
7162 return cleanExit();
7162 return cleanExit(io);
71637163}
71647164
71657165fn createEmptyDependenciesModule(