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