diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-05-27 15:41:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-05-27 20:56:49 -0700 |
| commit | b7889f262a5bee642460eb33b1ae7f2b1f87864c (patch) | |
| tree | 2a159975546426872285a309424494fa6d2476b4 | |
| parent | aca7feb8fac2fae8f0b79a2cfac2a248bcd8451b (diff) | |
| download | zig-b7889f262a5bee642460eb33b1ae7f2b1f87864c.tar.gz zig-b7889f262a5bee642460eb33b1ae7f2b1f87864c.zip | |
zig build: respect --color argument
`--color off` now disables the CLI progress bar both in the parent
process and the build runner process.
| -rw-r--r-- | lib/compiler/build_runner.zig | 6 | ||||
| -rw-r--r-- | src/main.zig | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 8aa21df1d9..86ad68133a 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -289,7 +289,9 @@ pub fn main() !void { .windows_api => {}, } - const main_progress_node = std.Progress.start(.{}); + const main_progress_node = std.Progress.start(.{ + .disable_printing = (color == .off), + }); builder.debug_log_scopes = debug_log_scopes.items; builder.resolveInstallPrefix(install_prefix, dir_list); @@ -1223,7 +1225,7 @@ fn cleanExit() void { process.exit(0); } -const Color = enum { auto, off, on }; +const Color = std.zig.Color; const Summary = enum { all, new, failures, none }; fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config { diff --git a/src/main.zig b/src/main.zig index 987a7cec5a..cec15a087f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4702,6 +4702,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { const results_tmp_file_nonce = Package.Manifest.hex64(std.crypto.random.int(u64)); try child_argv.append("-Z" ++ results_tmp_file_nonce); + var color: Color = .auto; + { var i: usize = 0; while (i < args.len) : (i += 1) { @@ -4786,6 +4788,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { verbose_cimport = true; } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { verbose_llvm_cpu_features = true; + } else if (mem.eql(u8, arg, "--color")) { + if (i + 1 >= args.len) fatal("expected [auto|on|off] after {s}", .{arg}); + i += 1; + color = std.meta.stringToEnum(Color, args[i]) orelse { + fatal("expected [auto|on|off] after {s}, found '{s}'", .{ arg, args[i] }); + }; + try child_argv.appendSlice(&.{ arg, args[i] }); + continue; } else if (mem.eql(u8, arg, "--seed")) { if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); i += 1; @@ -4799,7 +4809,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { const work_around_btrfs_bug = native_os == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); - const color: Color = .auto; const root_prog_node = std.Progress.start(.{ .disable_printing = (color == .off), .root_name = "Compile Build Script", |
