From a007dd5d22570790523c61aaee5782bdbab2f7d3 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 18 Jul 2021 15:46:02 +0300 Subject: [PATCH] builder: support `-o -` to print the generated C/JS source to stdout --- cmd/tools/vtest-all.v | 9 ++++++++- vlib/v/builder/cc.v | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index aaf0164f81..dd6a5bfe50 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -62,6 +62,12 @@ fn get_all_commands() []Command { okmsg: 'V can output a .c file, without compiling further.' 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{ line: '$vexe -o vtmp cmd/v' okmsg: 'V can compile itself.' @@ -152,7 +158,8 @@ fn (mut cmd Command) run() { sw := time.new_stopwatch({}) cmd.ecode = os.system(cmd.line) 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 { return } diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index ffb8750166..6f867f799a 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -479,6 +479,13 @@ fn (mut v Builder) cc() { } 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` ends_with_c := v.pref.out_name.ends_with('.c') ends_with_js := v.pref.out_name.ends_with('.js')