authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 15:41:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:49-07:00
logb7889f262a5bee642460eb33b1ae7f2b1f87864c
tree2a159975546426872285a309424494fa6d2476b4
parentaca7feb8fac2fae8f0b79a2cfac2a248bcd8451b

zig build: respect --color argument

`--color off` now disables the CLI progress bar both in the parent process and the build runner process.

2 files changed, 14 insertions(+), 3 deletions(-)

lib/compiler/build_runner.zig+4-2
...@@ -289,7 +289,9 @@ pub fn main() !void {...@@ -289,7 +289,9 @@ pub fn main() !void {
289 .windows_api => {},289 .windows_api => {},
290 }290 }
291291
292 const main_progress_node = std.Progress.start(.{});292 const main_progress_node = std.Progress.start(.{
293 .disable_printing = (color == .off),
294 });
293295
294 builder.debug_log_scopes = debug_log_scopes.items;296 builder.debug_log_scopes = debug_log_scopes.items;
295 builder.resolveInstallPrefix(install_prefix, dir_list);297 builder.resolveInstallPrefix(install_prefix, dir_list);
...@@ -1223,7 +1225,7 @@ fn cleanExit() void {...@@ -1223,7 +1225,7 @@ fn cleanExit() void {
1223 process.exit(0);1225 process.exit(0);
1224}1226}
12251227
1226const Color = enum { auto, off, on };1228const Color = std.zig.Color;
1227const Summary = enum { all, new, failures, none };1229const Summary = enum { all, new, failures, none };
12281230
1229fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {1231fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {
src/main.zig+10-1
...@@ -4702,6 +4702,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4702,6 +4702,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4702 const results_tmp_file_nonce = Package.Manifest.hex64(std.crypto.random.int(u64));4702 const results_tmp_file_nonce = Package.Manifest.hex64(std.crypto.random.int(u64));
4703 try child_argv.append("-Z" ++ results_tmp_file_nonce);4703 try child_argv.append("-Z" ++ results_tmp_file_nonce);
47044704
4705 var color: Color = .auto;
4706
4705 {4707 {
4706 var i: usize = 0;4708 var i: usize = 0;
4707 while (i < args.len) : (i += 1) {4709 while (i < args.len) : (i += 1) {
...@@ -4786,6 +4788,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4786,6 +4788,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4786 verbose_cimport = true;4788 verbose_cimport = true;
4787 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {4789 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
4788 verbose_llvm_cpu_features = true;4790 verbose_llvm_cpu_features = true;
4791 } else if (mem.eql(u8, arg, "--color")) {
4792 if (i + 1 >= args.len) fatal("expected [auto|on|off] after {s}", .{arg});
4793 i += 1;
4794 color = std.meta.stringToEnum(Color, args[i]) orelse {
4795 fatal("expected [auto|on|off] after {s}, found '{s}'", .{ arg, args[i] });
4796 };
4797 try child_argv.appendSlice(&.{ arg, args[i] });
4798 continue;
4789 } else if (mem.eql(u8, arg, "--seed")) {4799 } else if (mem.eql(u8, arg, "--seed")) {
4790 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});4800 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
4791 i += 1;4801 i += 1;
...@@ -4799,7 +4809,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4799,7 +4809,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
47994809
4800 const work_around_btrfs_bug = native_os == .linux and4810 const work_around_btrfs_bug = native_os == .linux and
4801 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();4811 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
4802 const color: Color = .auto;
4803 const root_prog_node = std.Progress.start(.{4812 const root_prog_node = std.Progress.start(.{
4804 .disable_printing = (color == .off),4813 .disable_printing = (color == .off),
4805 .root_name = "Compile Build Script",4814 .root_name = "Compile Build Script",