From ae82b67ef5faf0a1dc637062a4bc79d3c48c9b55 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 1 Jan 2024 23:30:21 +0200 Subject: [PATCH] v.pref: support a `-n` option, silencing only notices (#20331) --- vlib/v/builder/builder.v | 10 +++++----- vlib/v/help/build/build.txt | 6 ++++++ vlib/v/pref/pref.c.v | 10 +++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index f6e1badd41..818f5f8d9c 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -497,8 +497,8 @@ pub fn (mut b Builder) print_warnings_and_errors() { } if b.pref.check_only { - for file in b.parsed_files { - if !b.pref.skip_warnings { + if !b.pref.skip_notes { + for file in b.parsed_files { for err in file.notices { kind := if b.pref.is_verbose { '${err.reporter} notice #${b.nr_notices}:' @@ -521,8 +521,8 @@ pub fn (mut b Builder) print_warnings_and_errors() { } } - for file in b.parsed_files { - if !b.pref.skip_warnings { + if !b.pref.skip_warnings { + for file in b.parsed_files { for err in file.warnings { kind := if b.pref.is_verbose { '${err.reporter} warning #${b.nr_warnings}:' @@ -547,7 +547,7 @@ pub fn (mut b Builder) print_warnings_and_errors() { if b.pref.is_verbose && b.checker.nr_notices > 1 { println('${b.checker.nr_notices} notices') } - if b.checker.nr_notices > 0 && !b.pref.skip_warnings { + if b.checker.nr_notices > 0 && !b.pref.skip_notes { for err in b.checker.notices { kind := if b.pref.is_verbose { '${err.reporter} notice #${b.checker.nr_notices}:' diff --git a/vlib/v/help/build/build.txt b/vlib/v/help/build/build.txt index 0319b67f7e..1cb9cbcaf8 100644 --- a/vlib/v/help/build/build.txt +++ b/vlib/v/help/build/build.txt @@ -214,6 +214,12 @@ NB: the build flags are shared with the run command too: The instrumented version will print detailed timing stats while processing each .v file. + -n + Hide all notices. + + -N + Treat *all V notices* as errors. + -w Hide all warnings. diff --git a/vlib/v/pref/pref.c.v b/vlib/v/pref/pref.c.v index b26adfc46a..e27449ad8e 100644 --- a/vlib/v/pref/pref.c.v +++ b/vlib/v/pref/pref.c.v @@ -212,6 +212,7 @@ pub mut: // skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js) skip_warnings bool // like C's "-w", forces warnings to be ignored. + skip_notes bool // force notices to be ignored/not shown. warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error notes_are_errors bool // -N, treat *every* notice as an error @@ -720,9 +721,15 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin '-W' { res.warns_are_errors = true } + '-w' { + res.skip_warnings = true + } '-N' { res.notes_are_errors = true } + '-n' { + res.skip_notes = true + } '-no-rsp' { res.no_rsp = true } @@ -732,9 +739,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin '-keepc' { res.reuse_tmpc = true } - '-w' { - res.skip_warnings = true - } '-watch' { eprintln_exit('The -watch option is deprecated. Please use the watch command `v watch file.v` instead.') }