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

builder: support -o - to print the generated C/JS source to stdout

This commit is contained in:
Delyan Angelov 2021-07-18 15:46:02 +03:00
parent a5c784830b
commit a007dd5d22
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 15 additions and 1 deletions

View File

@ -62,6 +62,12 @@ fn get_all_commands() []Command {
okmsg: 'V can output a .c file, without compiling further.' okmsg: 'V can output a .c file, without compiling further.'
rmfile: 'hhww.c' rmfile: 'hhww.c'
} }
$if linux || macos {
res << Command{
line: '$vexe -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
okmsg: 'V prints the generated source code to stdout with `-o -` .'
}
}
res << Command{ res << Command{
line: '$vexe -o vtmp cmd/v' line: '$vexe -o vtmp cmd/v'
okmsg: 'V can compile itself.' okmsg: 'V can compile itself.'
@ -152,7 +158,8 @@ fn (mut cmd Command) run() {
sw := time.new_stopwatch({}) sw := time.new_stopwatch({})
cmd.ecode = os.system(cmd.line) cmd.ecode = os.system(cmd.line)
spent := sw.elapsed().milliseconds() spent := sw.elapsed().milliseconds()
println(term_highlight('> Running: "$cmd.line" took: $spent ms.')) println('> Running: "$cmd.line" took: $spent ms ... ' +
if cmd.ecode != 0 { term.failed('FAILED') } else { term_highlight('OK') })
if vtest_nocleanup { if vtest_nocleanup {
return return
} }

View File

@ -479,6 +479,13 @@ fn (mut v Builder) cc() {
} }
return return
} }
if v.pref.out_name.ends_with('/-') {
// output to stdout
content := os.read_file(v.out_name_c) or { panic(err) }
println(content)
os.rm(v.out_name_c) or {}
return
}
// whether to just create a .c or .js file and exit, for example: `v -o v.c cmd.v` // whether to just create a .c or .js file and exit, for example: `v -o v.c cmd.v`
ends_with_c := v.pref.out_name.ends_with('.c') ends_with_c := v.pref.out_name.ends_with('.c')
ends_with_js := v.pref.out_name.ends_with('.js') ends_with_js := v.pref.out_name.ends_with('.js')