| author | |
| committer | |
| log | 2f52f95b928c1dcb42afb22243c27fb9661cbd1b |
| tree | c47cd6837a9f881ef190f9672aab26ccc3904c26 |
| parent | 352976ed236030d88d5a7332433b0b37bf4bc41c |
| parent | 6ba1fdf7e0d8dfc348a163219b3c3215c3644dd6 |
| signature |
std/build: support --color4 files changed, 31 insertions(+), 27 deletions(-)
lib/std/build.zig+6| ... | ... | @@ -45,6 +45,7 @@ pub const Builder = struct { |
| 45 | 45 | verbose_llvm_ir: bool, |
| 46 | 46 | verbose_cimport: bool, |
| 47 | 47 | verbose_llvm_cpu_features: bool, |
| 48 | color: enum { auto, on, off } = .auto, | |
| 48 | 49 | invalid_user_input: bool, |
| 49 | 50 | zig_exe: []const u8, |
| 50 | 51 | default_step: *Step, |
| ... | ... | @@ -1946,6 +1947,11 @@ pub const LibExeObjStep = struct { |
| 1946 | 1947 | }; |
| 1947 | 1948 | zig_args.append(cmd) catch unreachable; |
| 1948 | 1949 | |
| 1950 | if (builder.color != .auto) { | |
| 1951 | try zig_args.append("--color"); | |
| 1952 | try zig_args.append(@tagName(builder.color)); | |
| 1953 | } | |
| 1954 | ||
| 1949 | 1955 | if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder)); |
| 1950 | 1956 | |
| 1951 | 1957 | var prev_has_extra_flags = false; |
lib/std/special/build_runner.zig+10| ... | ... | @@ -82,6 +82,15 @@ pub fn main() !void { |
| 82 | 82 | return usageAndErr(builder, false, stderr_stream); |
| 83 | 83 | }; |
| 84 | 84 | builder.addSearchPrefix(search_prefix); |
| 85 | } else if (mem.eql(u8, arg, "--color")) { | |
| 86 | const next_arg = nextArg(args, &arg_idx) orelse { | |
| 87 | warn("expected [auto|on|off] after --color", .{}); | |
| 88 | return usageAndErr(builder, false, stderr_stream); | |
| 89 | }; | |
| 90 | builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse { | |
| 91 | warn("expected [auto|on|off] after --color, found '{}'", .{next_arg}); | |
| 92 | return usageAndErr(builder, false, stderr_stream); | |
| 93 | }; | |
| 85 | 94 | } else if (mem.eql(u8, arg, "--override-lib-dir")) { |
| 86 | 95 | builder.override_lib_dir = nextArg(args, &arg_idx) orelse { |
| 87 | 96 | warn("Expected argument after --override-lib-dir\n\n", .{}); |
| ... | ... | @@ -171,6 +180,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void |
| 171 | 180 | \\ --verbose Print commands before executing them |
| 172 | 181 | \\ --prefix [path] Override default install prefix |
| 173 | 182 | \\ --search-prefix [path] Add a path to look for binaries, libraries, headers |
| 183 | \\ --color [auto|off|on] Enable or disable colored error messages | |
| 174 | 184 | \\ |
| 175 | 185 | \\Project-Specific Options: |
| 176 | 186 | \\ |
src/Compilation.zig+3-3| ... | ... | @@ -103,7 +103,7 @@ owned_link_dir: ?std.fs.Dir, |
| 103 | 103 | |
| 104 | 104 | /// This is for stage1 and should be deleted upon completion of self-hosting. |
| 105 | 105 | /// Don't use this for anything other than stage1 compatibility. |
| 106 | color: @import("main.zig").Color = .Auto, | |
| 106 | color: @import("main.zig").Color = .auto, | |
| 107 | 107 | |
| 108 | 108 | test_filter: ?[]const u8, |
| 109 | 109 | test_name_prefix: ?[]const u8, |
| ... | ... | @@ -385,7 +385,7 @@ pub const InitOptions = struct { |
| 385 | 385 | machine_code_model: std.builtin.CodeModel = .default, |
| 386 | 386 | clang_preprocessor_mode: ClangPreprocessorMode = .no, |
| 387 | 387 | /// This is for stage1 and should be deleted upon completion of self-hosting. |
| 388 | color: @import("main.zig").Color = .Auto, | |
| 388 | color: @import("main.zig").Color = .auto, | |
| 389 | 389 | test_filter: ?[]const u8 = null, |
| 390 | 390 | test_name_prefix: ?[]const u8 = null, |
| 391 | 391 | subsystem: ?std.Target.SubSystem = null, |
| ... | ... | @@ -1179,7 +1179,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1179 | 1179 | var progress: std.Progress = .{}; |
| 1180 | 1180 | var main_progress_node = try progress.start("", null); |
| 1181 | 1181 | defer main_progress_node.end(); |
| 1182 | if (self.color == .Off) progress.terminal = null; | |
| 1182 | if (self.color == .off) progress.terminal = null; | |
| 1183 | 1183 | |
| 1184 | 1184 | var c_comp_progress_node = main_progress_node.start("Compile C Objects", self.c_source_files.len); |
| 1185 | 1185 | defer c_comp_progress_node.end(); |
src/main.zig+12-24| ... | ... | @@ -28,9 +28,9 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn { |
| 28 | 28 | pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB |
| 29 | 29 | |
| 30 | 30 | pub const Color = enum { |
| 31 | Auto, | |
| 32 | Off, | |
| 33 | On, | |
| 31 | auto, | |
| 32 | off, | |
| 33 | on, | |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | const usage = |
| ... | ... | @@ -414,7 +414,7 @@ fn buildOutputType( |
| 414 | 414 | run, |
| 415 | 415 | }, |
| 416 | 416 | ) !void { |
| 417 | var color: Color = .Auto; | |
| 417 | var color: Color = .auto; | |
| 418 | 418 | var optimize_mode: std.builtin.Mode = .Debug; |
| 419 | 419 | var provided_name: ?[]const u8 = null; |
| 420 | 420 | var link_mode: ?std.builtin.LinkMode = null; |
| ... | ... | @@ -622,15 +622,9 @@ fn buildOutputType( |
| 622 | 622 | } |
| 623 | 623 | i += 1; |
| 624 | 624 | const next_arg = args[i]; |
| 625 | if (mem.eql(u8, next_arg, "auto")) { | |
| 626 | color = .Auto; | |
| 627 | } else if (mem.eql(u8, next_arg, "on")) { | |
| 628 | color = .On; | |
| 629 | } else if (mem.eql(u8, next_arg, "off")) { | |
| 630 | color = .Off; | |
| 631 | } else { | |
| 625 | color = std.meta.stringToEnum(Color, next_arg) orelse { | |
| 632 | 626 | fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg}); |
| 633 | } | |
| 627 | }; | |
| 634 | 628 | } else if (mem.eql(u8, arg, "--subsystem")) { |
| 635 | 629 | if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); |
| 636 | 630 | i += 1; |
| ... | ... | @@ -2411,7 +2405,7 @@ const Fmt = struct { |
| 2411 | 2405 | |
| 2412 | 2406 | pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void { |
| 2413 | 2407 | const stderr_file = io.getStdErr(); |
| 2414 | var color: Color = .Auto; | |
| 2408 | var color: Color = .auto; | |
| 2415 | 2409 | var stdin_flag: bool = false; |
| 2416 | 2410 | var check_flag: bool = false; |
| 2417 | 2411 | var input_files = ArrayList([]const u8).init(gpa); |
| ... | ... | @@ -2431,15 +2425,9 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void { |
| 2431 | 2425 | } |
| 2432 | 2426 | i += 1; |
| 2433 | 2427 | const next_arg = args[i]; |
| 2434 | if (mem.eql(u8, next_arg, "auto")) { | |
| 2435 | color = .Auto; | |
| 2436 | } else if (mem.eql(u8, next_arg, "on")) { | |
| 2437 | color = .On; | |
| 2438 | } else if (mem.eql(u8, next_arg, "off")) { | |
| 2439 | color = .Off; | |
| 2440 | } else { | |
| 2428 | color = std.meta.stringToEnum(Color, next_arg) orelse { | |
| 2441 | 2429 | fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg}); |
| 2442 | } | |
| 2430 | }; | |
| 2443 | 2431 | } else if (mem.eql(u8, arg, "--stdin")) { |
| 2444 | 2432 | stdin_flag = true; |
| 2445 | 2433 | } else if (mem.eql(u8, arg, "--check")) { |
| ... | ... | @@ -2663,9 +2651,9 @@ fn printErrMsgToFile( |
| 2663 | 2651 | color: Color, |
| 2664 | 2652 | ) !void { |
| 2665 | 2653 | const color_on = switch (color) { |
| 2666 | .Auto => file.isTty(), | |
| 2667 | .On => true, | |
| 2668 | .Off => false, | |
| 2654 | .auto => file.isTty(), | |
| 2655 | .on => true, | |
| 2656 | .off => false, | |
| 2669 | 2657 | }; |
| 2670 | 2658 | const lok_token = parse_error.loc(); |
| 2671 | 2659 | const span_first = lok_token; |