From df2add46aa3dda577498c74902ede5e973d3c4a7 Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Mon, 11 Jul 2022 17:51:18 +0200 Subject: [PATCH] feat: `-q`/`--quiet` for quietening progress output --- lib/build_runner.zig | 3 +++ lib/std/build.zig | 6 ++++++ src/Compilation.zig | 10 +++++++++- src/glibc.zig | 1 + src/libcxx.zig | 2 ++ src/libtsan.zig | 1 + src/libunwind.zig | 1 + src/main.zig | 9 +++++++++ src/musl.zig | 1 + src/test.zig | 1 + 10 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/build_runner.zig b/lib/build_runner.zig index f47822f0b7e2..d07af8466c83 100644 --- a/lib/build_runner.zig +++ b/lib/build_runner.zig @@ -122,6 +122,8 @@ pub fn main() !void { return usageAndErr(builder, false, stderr_stream); }; builder.libc_file = libc_file; + } else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) { + builder.quiet = true; } else if (mem.eql(u8, arg, "--color")) { const next_arg = nextArg(args, &arg_idx) orelse { std.debug.print("expected [auto|on|off] after --color", .{}); @@ -285,6 +287,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void \\ Windows programs on Linux hosts. (default: no) \\ \\ -h, --help Print this help and exit + \\ -q, --quiet Disable progress output during compilation \\ --verbose Print commands before executing them \\ --color [auto|off|on] Enable or disable colored error messages \\ --prominent-compile-errors Output compile errors formatted for a human to read diff --git a/lib/std/build.zig b/lib/std/build.zig index c3deff5a0918..fb051f32553c 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -44,6 +44,7 @@ pub const Builder = struct { verbose_llvm_cpu_features: bool, /// The purpose of executing the command is for a human to read compile errors from the terminal prominent_compile_errors: bool, + quiet: bool, color: enum { auto, on, off } = .auto, reference_trace: ?u32 = null, use_stage1: ?bool = null, @@ -188,6 +189,7 @@ pub const Builder = struct { .verbose_cimport = false, .verbose_llvm_cpu_features = false, .prominent_compile_errors = false, + .quiet = false, .invalid_user_input = false, .allocator = allocator, .user_input_options = UserInputOptionsMap.init(allocator), @@ -2449,6 +2451,10 @@ pub const LibExeObjStep = struct { }; zig_args.append(cmd) catch unreachable; + if (builder.quiet) { + try zig_args.append("-q"); + } + if (builder.color != .auto) { try zig_args.append("--color"); try zig_args.append(@tagName(builder.color)); diff --git a/src/Compilation.zig b/src/Compilation.zig index 0ff94818756d..395a73ef0dfe 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -150,6 +150,8 @@ crt_files: std.StringHashMapUnmanaged(CRTFile) = .{}, /// Keeping track of this possibly open resource so we can close it later. owned_link_dir: ?std.fs.Dir, +quiet: bool, + /// This is for stage1 and should be deleted upon completion of self-hosting. /// Don't use this for anything other than stage1 compatibility. color: Color = .auto, @@ -987,6 +989,7 @@ pub const InitOptions = struct { libc_installation: ?*const LibCInstallation = null, machine_code_model: std.builtin.CodeModel = .default, clang_preprocessor_mode: ClangPreprocessorMode = .no, + quiet: bool, /// This is for stage1 and should be deleted upon completion of self-hosting. color: Color = .auto, reference_trace: ?u32 = null, @@ -1898,6 +1901,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .verbose_llvm_cpu_features = options.verbose_llvm_cpu_features, .disable_c_depfile = options.disable_c_depfile, .owned_link_dir = owned_link_dir, + .quiet = options.quiet, .color = options.color, .reference_trace = options.reference_trace, .time_report = options.time_report, @@ -2320,7 +2324,9 @@ pub fn update(comp: *Compilation) !void { var progress: std.Progress = .{ .dont_print_on_dumb = true }; const main_progress_node = progress.start("", 0); defer main_progress_node.end(); - if (comp.color == .off) progress.terminal = null; + if (comp.quiet) + // Disable progress output entirely + progress.terminal = null; try comp.performAllTheWork(main_progress_node); @@ -5177,6 +5183,7 @@ fn buildOutputFromZig( .want_pie = comp.bin_file.options.pie, .emit_h = null, .strip = comp.compilerRtStrip(), + .quiet = comp.quiet, .is_native_os = comp.bin_file.options.is_native_os, .is_native_abi = comp.bin_file.options.is_native_abi, .self_exe_path = comp.self_exe_path, @@ -5460,6 +5467,7 @@ pub fn build_crt_file( .Lib => comp.bin_file.options.lto, .Obj, .Exe => false, }, + .quiet = comp.quiet, .emit_h = null, .strip = comp.compilerRtStrip(), .is_native_os = comp.bin_file.options.is_native_os, diff --git a/src/glibc.zig b/src/glibc.zig index 3dd7565e9600..9adb67cb0bde 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -1095,6 +1095,7 @@ fn buildSharedLib( .want_tsan = false, .emit_h = null, .strip = comp.compilerRtStrip(), + .quiet = comp.quiet, .is_native_os = false, .is_native_abi = false, .self_exe_path = comp.self_exe_path, diff --git a/src/libcxx.zig b/src/libcxx.zig index b0261aaed68d..e4cbf4939d0b 100644 --- a/src/libcxx.zig +++ b/src/libcxx.zig @@ -235,6 +235,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { .want_lto = comp.bin_file.options.lto, .function_sections = comp.bin_file.options.function_sections, .emit_h = null, + .quiet = comp.quiet, .strip = comp.compilerRtStrip(), .is_native_os = comp.bin_file.options.is_native_os, .is_native_abi = comp.bin_file.options.is_native_abi, @@ -389,6 +390,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { .want_lto = comp.bin_file.options.lto, .function_sections = comp.bin_file.options.function_sections, .emit_h = null, + .quiet = comp.quiet, .strip = comp.compilerRtStrip(), .is_native_os = comp.bin_file.options.is_native_os, .is_native_abi = comp.bin_file.options.is_native_abi, diff --git a/src/libtsan.zig b/src/libtsan.zig index 16e40c16f82c..423e066dd5a1 100644 --- a/src/libtsan.zig +++ b/src/libtsan.zig @@ -217,6 +217,7 @@ pub fn buildTsan(comp: *Compilation) !void { .want_pic = true, .want_pie = true, .emit_h = null, + .quiet = comp.quiet, .strip = comp.compilerRtStrip(), .is_native_os = comp.bin_file.options.is_native_os, .is_native_abi = comp.bin_file.options.is_native_abi, diff --git a/src/libunwind.zig b/src/libunwind.zig index 11666eec3c91..fdfc4b8eb97c 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -113,6 +113,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { .want_lto = false, .function_sections = comp.bin_file.options.function_sections, .emit_h = null, + .quiet = comp.quiet, .strip = comp.compilerRtStrip(), .is_native_os = comp.bin_file.options.is_native_os, .is_native_abi = comp.bin_file.options.is_native_abi, diff --git a/src/main.zig b/src/main.zig index 056b5826e35b..740b3e52876c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -326,6 +326,7 @@ const usage_build_generic = \\ \\General Options: \\ -h, --help Print this help and exit + \\ -q, --quiet Disable progress output during compilation \\ --watch Enable compiler REPL \\ --color [auto|off|on] Enable or disable colored error messages \\ -femit-bin[=path] (default) Output machine code @@ -634,6 +635,7 @@ fn buildOutputType( var strip: ?bool = null; var function_sections = false; var no_builtin = false; + var quiet = false; var watch = false; var debug_compile_errors = false; var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); @@ -916,6 +918,8 @@ fn buildOutputType( if (mem.eql(u8, next_arg, "--")) break; try extra_cflags.append(next_arg); } + } else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) { + quiet = true; } else if (mem.eql(u8, arg, "--color")) { const next_arg = args_iter.next() orelse { fatal("expected [auto|on|off] after --color", .{}); @@ -2928,6 +2932,7 @@ fn buildOutputType( .verbose_cimport = verbose_cimport, .verbose_llvm_cpu_features = verbose_llvm_cpu_features, .machine_code_model = machine_code_model, + .quiet = quiet, .color = color, .time_report = time_report, .stack_report = stack_report, @@ -3713,6 +3718,7 @@ pub const usage_build = pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var prominent_compile_errors: bool = false; var use_stage1: ?bool = null; + var quiet: bool = false; // We want to release all the locks before executing the child process, so we make a nice // big block here to ensure the cleanup gets run when we extract out our argv. @@ -3779,6 +3785,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi try child_argv.append(arg); } else if (mem.eql(u8, arg, "-fno-reference-trace")) { try child_argv.append(arg); + } else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) { + quiet = true; } } try child_argv.append(arg); @@ -3907,6 +3915,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi .main_pkg = &main_pkg, .emit_bin = emit_bin, .emit_h = null, + .quiet = quiet, .optimize_mode = .Debug, .self_exe_path = self_exe_path, .thread_pool = &thread_pool, diff --git a/src/musl.zig b/src/musl.zig index 12ff530f8e8e..89ea864447ea 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -222,6 +222,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { .want_tsan = false, .emit_h = null, .strip = comp.compilerRtStrip(), + .quiet = comp.quiet, .is_native_os = false, .is_native_abi = false, .self_exe_path = comp.self_exe_path, diff --git a/src/test.zig b/src/test.zig index b6245592a54b..4bb5053370b6 100644 --- a/src/test.zig +++ b/src/test.zig @@ -1542,6 +1542,7 @@ pub const TestContext = struct { .emit_h = emit_h, .main_pkg = &main_pkg, .keep_source_files_loaded = true, + .quiet = false, .is_native_os = case.target.isNativeOs(), .is_native_abi = case.target.isNativeAbi(), .dynamic_linker = target_info.dynamic_linker.get(),