diff --git a/cmd/v/v.v b/cmd/v/v.v index 9a3c13006dbca4..e3bfc214db244c 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -183,6 +183,17 @@ fn main() { if prefs.is_help { invoke_help_and_exit(args) } + $if windows { + // An invalid `-cc` setting should take precedence over an unknown command, + // but must not affect commands that do not compile code. + if builder.should_find_windows_host_c_compiler(prefs) && prefs.ccompiler_set_by_flag + && prefs.ccompiler != 'msvc' { + mut probe := builder.Builder{ + pref: unsafe { prefs } + } + probe.find_win_cc() or { builder.verror(err.msg()) } + } + } other_commands := ['run', 'crun', 'build', 'build-module', 'help', 'version', 'new', 'init', 'install', 'link', 'list', 'outdated', 'remove', 'search', 'show', 'unlink', 'update', diff --git a/cmd/v/v_windows_test.v b/cmd/v/v_windows_test.v new file mode 100644 index 00000000000000..3cb01a85d65b7d --- /dev/null +++ b/cmd/v/v_windows_test.v @@ -0,0 +1,24 @@ +module main + +import os + +fn test_invalid_c_compiler_is_reported_before_command_dispatch() { + $if !windows { + return + } + missing_compiler := 'missing_compiler_27868' + expected_error := 'builder error: C compiler `${missing_compiler}` was requested with `-cc`, but was not found.' + for command in ['', 'not-a-command'] { + result := os.execute('${os.quoted_path(@VEXE)} -cc ${missing_compiler} ${command}') + assert result.exit_code == 1 + assert result.output.contains(expected_error), result.output + } + help_result := os.execute('${os.quoted_path(@VEXE)} -cc ${missing_compiler} help') + assert help_result.exit_code == 1 + assert help_result.output.contains('provide only one help topic.'), help_result.output + assert !help_result.output.contains(expected_error), help_result.output + + version_result := os.execute('${os.quoted_path(@VEXE)} -cc ${missing_compiler} version') + assert version_result.exit_code == 0, version_result.output + assert !version_result.output.contains(expected_error), version_result.output +}