v.pref: support a -q option, silencing many repeated messages like the one for v -prod run file.v

This commit is contained in:
Delyan Angelov 2023-10-07 13:36:12 +03:00
parent 1e89b0b0dd
commit 49b8c2f9cd
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 56 additions and 55 deletions

View File

@ -65,6 +65,10 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
} }
} }
if os.getenv('V_NO_C_ERROR_INFO') != '' { if os.getenv('V_NO_C_ERROR_INFO') != '' {
eprintln('> V_NO_C_ERROR_INFO is obsoleted by either setting VQUIET to 1, or by passing `-q` on the command line')
exit(1)
}
if v.pref.is_quiet {
exit(1) exit(1)
} }
verror(' verror('

View File

@ -166,6 +166,14 @@ NB: the build flags are shared with the run command too:
-translated -translated
Enable features that are discouraged in regular V code but required for translated V code. Enable features that are discouraged in regular V code but required for translated V code.
-q
Tell V to be quieter, and to not show many otherwise helpful messages, that only get in your
way once you have read them a few dozen times. One example is the notice message, usually
shown for `v -prod run file.v`, that says that -prod should not be used with run .
Note, this option *does not affect* errors/warnings/notices, just messages that V prints in
order to be more user friendly, in common situations, that are error prone for new users, and
that just needlessly take vertical space, once you are well aware of them.
-v -v
Enable verbosity in the V compiler while compiling Enable verbosity in the V compiler while compiling

View File

@ -131,6 +131,7 @@ pub mut:
is_ios_simulator bool is_ios_simulator bool
is_apk bool // build as Android .apk format is_apk bool // build as Android .apk format
is_help bool // -h, -help or --help was passed is_help bool // -h, -help or --help was passed
is_quiet bool // do not show the repetitive explanatory messages like the one for `v -prod run file.v` .
is_cstrict bool // turn on more C warnings; slightly slower is_cstrict bool // turn on more C warnings; slightly slower
eval_argument string // `println(2+2)` on `v -e "println(2+2)"`. Note that this souce code, will be evaluated in vsh mode, so 'v -e 'println(ls(".")!)' is valid. eval_argument string // `println(2+2)` on `v -e "println(2+2)"`. Note that this souce code, will be evaluated in vsh mode, so 'v -e 'println(ls(".")!)' is valid.
test_runner string // can be 'simple' (fastest, but much less detailed), 'tap', 'normal' test_runner string // can be 'simple' (fastest, but much less detailed), 'tap', 'normal'
@ -309,6 +310,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.m64 = true // follow V model by default res.m64 = true // follow V model by default
} }
res.run_only = os.getenv('VTEST_ONLY_FN').split_any(',') res.run_only = os.getenv('VTEST_ONLY_FN').split_any(',')
if os.getenv('VQUIET') != '' {
res.is_quiet = true
}
mut command := '' mut command := ''
mut command_pos := -1 mut command_pos := -1
@ -339,8 +343,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
target_arch := cmdline.option(current_args, '-arch', '') target_arch := cmdline.option(current_args, '-arch', '')
i++ i++
target_arch_kind := arch_from_string(target_arch) or { target_arch_kind := arch_from_string(target_arch) or {
eprintln('unknown architecture target `${target_arch}`') eprintln_exit('unknown architecture target `${target_arch}`')
exit(1)
} }
res.arch = target_arch_kind res.arch = target_arch_kind
res.build_options << '${arg} ${target_arch}' res.build_options << '${arg} ${target_arch}'
@ -380,6 +383,13 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
// Note: help is *very important*, just respond to all variations: // Note: help is *very important*, just respond to all variations:
res.is_help = true res.is_help = true
} }
'-q' {
if command_pos != -1 {
// a -q flag after a command is for the command, not for v
continue
}
res.is_quiet = true
}
'-v' { '-v' {
if command_pos != -1 { if command_pos != -1 {
// a -v flag after the command, is intended for the command, not for V itself // a -v flag after the command, is intended for the command, not for V itself
@ -395,6 +405,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
} }
'-progress' { '-progress' {
// processed by testing tools in cmd/tools/modules/testing/common.v // processed by testing tools in cmd/tools/modules/testing/common.v
continue
} }
'-Wimpure-v' { '-Wimpure-v' {
res.warn_impure_v = true res.warn_impure_v = true
@ -513,7 +524,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.is_shared = true res.is_shared = true
} }
'--enable-globals' { '--enable-globals' {
eprintln_cond(show_output, '`--enable-globals` flag is deprecated, please use `-enable-globals` instead') eprintln_cond(show_output && !res.is_quiet, '`--enable-globals` flag is deprecated, please use `-enable-globals` instead')
res.enable_globals = true res.enable_globals = true
} }
'-enable-globals' { '-enable-globals' {
@ -704,8 +715,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.skip_warnings = true res.skip_warnings = true
} }
'-watch' { '-watch' {
eprintln('The -watch option is deprecated. Please use the watch command `v watch file.v` instead.') eprintln_exit('The -watch option is deprecated. Please use the watch command `v watch file.v` instead.')
exit(1)
} }
'-print-v-files' { '-print-v-files' {
res.print_v_files = true res.print_v_files = true
@ -721,8 +731,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.output_cross_c = true res.output_cross_c = true
continue continue
} }
eprintln('unknown operating system target `${target_os}`') eprintln_exit('unknown operating system target `${target_os}`')
exit(1)
} }
if target_os_kind == .wasm32 { if target_os_kind == .wasm32 {
res.is_bare = true res.is_bare = true
@ -757,11 +766,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
} }
i++ i++
} }
'-error-limit' {
eprintln('Note: the -error-limit option is deprecated, and will be removed in 2023/01/15. Use `-message-limit N` instead.')
res.message_limit = cmdline.option(current_args, arg, '5').int()
i++
}
'-message-limit' { '-message-limit' {
res.message_limit = cmdline.option(current_args, arg, '5').int() res.message_limit = cmdline.option(current_args, arg, '5').int()
i++ i++
@ -804,9 +808,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
sbackend := cmdline.option(current_args, arg, 'c') sbackend := cmdline.option(current_args, arg, 'c')
res.build_options << '${arg} ${sbackend}' res.build_options << '${arg} ${sbackend}'
b := backend_from_string(sbackend) or { b := backend_from_string(sbackend) or {
eprintln('Unknown V backend: ${sbackend}') eprintln_exit('Unknown V backend: ${sbackend}\nValid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native, wasm')
eprintln('Valid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native, wasm')
exit(1)
} }
if b.is_js() { if b.is_js() {
res.output_cross_c = true res.output_cross_c = true
@ -833,8 +835,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
path := cmdline.option(current_args, '-custom-prelude', '') path := cmdline.option(current_args, '-custom-prelude', '')
res.build_options << '${arg} ${path}' res.build_options << '${arg} ${path}'
prelude := os.read_file(path) or { prelude := os.read_file(path) or {
eprintln('cannot open custom prelude file: ${err}') eprintln_exit('cannot open custom prelude file: ${err}')
exit(1)
} }
res.custom_prelude = prelude res.custom_prelude = prelude
i++ i++
@ -874,8 +875,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
} }
else { else {
if command == 'build' && is_source_file(arg) { if command == 'build' && is_source_file(arg) {
eprintln('Use `v ${arg}` instead.') eprintln_exit('Use `v ${arg}` instead.')
exit(1)
} }
if arg.len != 0 && arg[0] == `-` { if arg.len != 0 && arg[0] == `-` {
if arg[1..] in pref.list_of_flags_with_param { if arg[1..] in pref.list_of_flags_with_param {
@ -892,8 +892,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
} }
} else if is_source_file(command) && is_source_file(arg) } else if is_source_file(command) && is_source_file(arg)
&& command !in known_external_commands && res.raw_vsh_tmp_prefix == '' { && command !in known_external_commands && res.raw_vsh_tmp_prefix == '' {
eprintln('Too many targets. Specify just one target: <target.v|target_directory>.') eprintln_exit('Too many targets. Specify just one target: <target.v|target_directory>.')
exit(1)
} }
continue continue
} }
@ -907,8 +906,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
continue continue
} }
extension := if command.len == 0 { '' } else { ' for command `${command}`' } extension := if command.len == 0 { '' } else { ' for command `${command}`' }
eprintln('Unknown argument `${arg}`${extension}') eprintln_exit('Unknown argument `${arg}`${extension}')
exit(1)
} }
} }
} }
@ -919,21 +917,18 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.is_run = true res.is_run = true
} }
if command == 'run' && res.is_prod && os.is_atty(1) > 0 { if command == 'run' && res.is_prod && os.is_atty(1) > 0 {
eprintln_cond(show_output, "Note: building an optimized binary takes much longer. It shouldn't be used with `v run`.") eprintln_cond(show_output && !res.is_quiet, "Note: building an optimized binary takes much longer. It shouldn't be used with `v run`.")
eprintln_cond(show_output, 'Use `v run` without optimization, or build an optimized binary with -prod first, then run it separately.') eprintln_cond(show_output && !res.is_quiet, 'Use `v run` without optimization, or build an optimized binary with -prod first, then run it separately.')
} }
if res.os in [.browser, .wasi] && res.backend != .wasm { if res.os in [.browser, .wasi] && res.backend != .wasm {
eprintln('OS `${res.os}` forbidden for backends other than wasm') eprintln_exit('OS `${res.os}` forbidden for backends other than wasm')
exit(1)
} }
if res.backend == .wasm && res.os !in [.browser, .wasi, ._auto] { if res.backend == .wasm && res.os !in [.browser, .wasi, ._auto] {
eprintln('Native WebAssembly backend OS must be `browser` or `wasi`') eprintln_exit('Native WebAssembly backend OS must be `browser` or `wasi`')
exit(1)
} }
if command != 'doc' && res.out_name.ends_with('.v') { if command != 'doc' && res.out_name.ends_with('.v') {
eprintln('Cannot save output binary in a .v file.') eprintln_exit('Cannot save output binary in a .v file.')
exit(1)
} }
if res.fast_math { if res.fast_math {
if res.ccompiler_type == .msvc { if res.ccompiler_type == .msvc {
@ -949,8 +944,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
if res.is_run || res.is_crun { if res.is_run || res.is_crun {
if command_pos + 2 > args.len { if command_pos + 2 > args.len {
eprintln('v run: no v files listed') eprintln_exit('v run: no v files listed')
exit(1)
} }
res.path = args[command_pos + 1] res.path = args[command_pos + 1]
res.run_args = args[command_pos + 2..] res.run_args = args[command_pos + 2..]
@ -962,14 +956,14 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
must_exist(res.path) must_exist(res.path)
if !res.path.ends_with('.v') && os.is_executable(res.path) && os.is_file(res.path) if !res.path.ends_with('.v') && os.is_executable(res.path) && os.is_file(res.path)
&& os.is_file(res.path + '.v') { && os.is_file(res.path + '.v') {
eprintln_cond(show_output, 'It looks like you wanted to run "${res.path}.v", so we went ahead and did that since "${res.path}" is an executable.') eprintln_cond(show_output && !res.is_quiet, 'It looks like you wanted to run "${res.path}.v", so we went ahead and did that since "${res.path}" is an executable.')
res.path += '.v' res.path += '.v'
} }
} else if is_source_file(command) { } else if is_source_file(command) {
res.path = command res.path = command
} }
if !res.is_bare && res.bare_builtin_dir != '' { if !res.is_bare && res.bare_builtin_dir != '' {
eprintln_cond(show_output, '`-bare-builtin-dir` must be used with `-freestanding`') eprintln_cond(show_output && !res.is_quiet, '`-bare-builtin-dir` must be used with `-freestanding`')
} }
if command.ends_with('.vsh') || (res.raw_vsh_tmp_prefix != '' && !res.is_run) { if command.ends_with('.vsh') || (res.raw_vsh_tmp_prefix != '' && !res.is_run) {
// `v build.vsh gcc` is the same as `v run build.vsh gcc`, // `v build.vsh gcc` is the same as `v run build.vsh gcc`,
@ -981,8 +975,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
} else if command == 'interpret' { } else if command == 'interpret' {
res.backend = .interpret res.backend = .interpret
if command_pos + 2 > args.len { if command_pos + 2 > args.len {
eprintln('v interpret: no v files listed') eprintln_exit('v interpret: no v files listed')
exit(1)
} }
res.path = args[command_pos + 1] res.path = args[command_pos + 1]
res.run_args = args[command_pos + 2..] res.run_args = args[command_pos + 2..]
@ -991,7 +984,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
must_exist(res.path) must_exist(res.path)
if !res.path.ends_with('.v') && os.is_executable(res.path) && os.is_file(res.path) if !res.path.ends_with('.v') && os.is_executable(res.path) && os.is_file(res.path)
&& os.is_file(res.path + '.v') { && os.is_file(res.path + '.v') {
eprintln('It looks like you wanted to run "${res.path}.v", so we went ahead and did that since "${res.path}" is an executable.') eprintln_cond(show_output && !res.is_quiet, 'It looks like you wanted to run "${res.path}.v", so we went ahead and did that since "${res.path}" is an executable.')
res.path += '.v' res.path += '.v'
} }
} }
@ -999,8 +992,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
if command == 'build-module' { if command == 'build-module' {
res.build_mode = .build_module res.build_mode = .build_module
if command_pos + 1 >= args.len { if command_pos + 1 >= args.len {
eprintln('v build-module: no module specified') eprintln_exit('v build-module: no module specified')
exit(1)
} }
res.path = args[command_pos + 1] res.path = args[command_pos + 1]
} }
@ -1024,6 +1016,12 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
return res, command return res, command
} }
[noreturn]
pub fn eprintln_exit(s string) {
eprintln(s)
exit(1)
}
pub fn eprintln_cond(condition bool, s string) { pub fn eprintln_cond(condition bool, s string) {
if !condition { if !condition {
return return
@ -1090,8 +1088,7 @@ pub fn arch_from_string(arch_str string) !Arch {
fn must_exist(path string) { fn must_exist(path string) {
if !os.exists(path) { if !os.exists(path) {
eprintln('v expects that `${path}` exists, but it does not') eprintln_exit('v expects that `${path}` exists, but it does not')
exit(1)
} }
} }
@ -1167,9 +1164,6 @@ fn (mut prefs Preferences) parse_define(define string) {
if define_parts.len == 1 { if define_parts.len == 1 {
prefs.compile_defines << define prefs.compile_defines << define
prefs.compile_defines_all << define prefs.compile_defines_all << define
if define == 'no_bounds_checking' {
prefs.no_bounds_checking = true
}
return return
} }
if define_parts.len == 2 { if define_parts.len == 2 {
@ -1180,25 +1174,20 @@ fn (mut prefs Preferences) parse_define(define string) {
prefs.compile_defines << define_parts[0] prefs.compile_defines << define_parts[0]
} }
else { else {
println( eprintln_exit(
'V error: Unknown define argument value `${define_parts[1]}` for ${define_parts[0]}.' + 'V error: Unknown define argument value `${define_parts[1]}` for ${define_parts[0]}.' +
' Expected `0` or `1`.') ' Expected `0` or `1`.')
exit(1)
} }
} }
return return
} }
println('V error: Unknown define argument: ${define}. Expected at most one `=`.') eprintln_exit('V error: Unknown define argument: ${define}. Expected at most one `=`.')
exit(1)
} }
fn (mut prefs Preferences) diagnose_deprecated_defines(define_parts []string) { fn (mut prefs Preferences) diagnose_deprecated_defines(define_parts []string) {
if define_parts[0] == 'force_embed_file' { // if define_parts[0] == 'no_bounds_checking' {
eprintln('`-d force_embed_file` was deprecated in 2022/06/01. Now \$embed_file(file) always embeds the file, unless you pass `-d embed_only_metadata`.') // eprintln('`-d no_bounds_checking` was deprecated in 2022/10/30. Use `-no-bounds-checking` instead.')
} // }
if define_parts[0] == 'no_bounds_checking' {
eprintln('`-d no_bounds_checking` was deprecated in 2022/10/30. Use `-no-bounds-checking` instead.')
}
} }
pub fn supported_test_runners_list() string { pub fn supported_test_runners_list() string {