1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.pref: make -b unknown_backend an error, with a more informative diagnostic message

This commit is contained in:
Delyan Angelov 2022-12-01 15:28:03 +02:00
parent 02f5c59340
commit 161847ed1a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 16 additions and 9 deletions

View File

@ -34,15 +34,16 @@ If you have not set it, a suitable platform specific folder (like /tmp) will be
NB: the build flags are shared with the run command too: NB: the build flags are shared with the run command too:
-b <backend>, -backend <backend> -b <backend>, -backend <backend>
Specify the backend to use while building the executable. Specifies the backend that will be used for building the executable.
Current list of supported backends: Current list of supported backends:
* `c` (default) - V outputs C source code which is passed to a C compiler to be compiled. * `c` (default) - V outputs C source code, which is then passed to a C compiler.
* `interpret` - Same as `v interpret` to run the V program * `go` - V outputs Go source code, which is then passed to a Go compiler.
* `interpret` - V will interpret the V program directly, instead of compiling it first. Same as `v interpret file.v`.
* `js` - V outputs JS source code which can be passed to NodeJS to be ran. * `js` - V outputs JS source code which can be passed to NodeJS to be ran.
* `js_browser` - V outputs JS source code ready for the browser. * `js_browser` - V outputs JS source code ready for the browser.
* `js_node` - V outputs JS source code to run with nodejs. * `js_node` - V outputs JS source code to run with nodejs.
* `js_freestanding` - V outputs JS source code with no hard runtime dependency. * `js_freestanding` - V outputs JS source code with no hard runtime dependency.
* `native` - V outputs native executable (see -arch x64|arm64 and -os linux|macos) (EXPERIMENTAL). * `native` - V outputs a native executable directly (see -arch x64|arm64 and -os linux|macos) (EXPERIMENTAL).
-d <flag>[=<value>], -define <flag>[=<value>] -d <flag>[=<value>], -define <flag>[=<value>]
Define the provided flag. Define the provided flag.

View File

@ -47,12 +47,12 @@ pub enum ColorOutput {
pub enum Backend { pub enum Backend {
c // The (default) C backend c // The (default) C backend
golang // Go backend
interpret // Interpret the ast
js_node // The JavaScript NodeJS backend js_node // The JavaScript NodeJS backend
js_browser // The JavaScript browser backend js_browser // The JavaScript browser backend
js_freestanding // The JavaScript freestanding backend js_freestanding // The JavaScript freestanding backend
native // The Native backend native // The Native backend
interpret // Interpret the ast
golang // Go backend
} }
pub fn (b Backend) is_js() bool { pub fn (b Backend) is_js() bool {
@ -687,7 +687,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
'-b', '-backend' { '-b', '-backend' {
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 { continue } b := backend_from_string(sbackend) or {
eprintln('Unknown V backend: ${sbackend}')
eprintln('Valid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native')
exit(1)
}
if b.is_js() { if b.is_js() {
res.output_cross_c = true res.output_cross_c = true
} }
@ -960,15 +964,17 @@ fn is_source_file(path string) bool {
} }
pub fn backend_from_string(s string) !Backend { pub fn backend_from_string(s string) !Backend {
// TODO: unify the "different js backend" options into a single `-b js`
// + a separate option, to choose the wanted JS output.
match s { match s {
'c' { return .c } 'c' { return .c }
'js' { return .js_node }
'go' { return .golang } 'go' { return .golang }
'interpret' { return .interpret }
'js' { return .js_node }
'js_node' { return .js_node } 'js_node' { return .js_node }
'js_browser' { return .js_browser } 'js_browser' { return .js_browser }
'js_freestanding' { return .js_freestanding } 'js_freestanding' { return .js_freestanding }
'native' { return .native } 'native' { return .native }
'interpret' { return .interpret }
else { return error('Unknown backend type ${s}') } else { return error('Unknown backend type ${s}') }
} }
} }