v run: recompile and execute changed file.v just once.

pull/1499/head^2
Delyan Angelov 2019-08-06 19:04:55 +03:00 committed by Alexander Medvednikov
parent c7312d9d1c
commit d072178cef
1 changed files with 52 additions and 23 deletions

View File

@ -189,7 +189,24 @@ fn main() {
// v.gen_doc_html_for_module(args.last()) // v.gen_doc_html_for_module(args.last())
exit(0) exit(0)
} }
if 'run' in args {
vsource := v.dir
vtarget := final_target_out_name( v.out_name )
if os.file_exists(vtarget) && ( os.file_last_mod_unix(vsource) <= os.file_last_mod_unix(vtarget) ) {
//println('ALREADY BUILD FROM vsource: $vsource | vtarget: $vtarget')
v.run_compiled_executable_and_exit()
}
v.compile()
v.run_compiled_executable_and_exit()
}
v.compile() v.compile()
if v.pref.is_test {
v.run_compiled_executable_and_exit()
}
} }
fn (v mut V) compile() { fn (v mut V) compile() {
@ -609,35 +626,47 @@ void reload_so() {
if v.pref.is_verbose { if v.pref.is_verbose {
v.log('flags=') v.log('flags=')
println(v.table.flags) println(v.table.flags)
} }
v.cc() v.cc()
if v.pref.is_test || v.pref.is_run { }
if v.pref.is_verbose {
println('============ running $v.out_name ============') fn final_target_out_name(out_name string) string {
} mut cmd := if out_name.starts_with('/') {
mut cmd := if v.out_name.starts_with('/') { out_name
v.out_name }
} else {
else { './' + out_name
'./' + v.out_name }
} $if windows {
$if windows { cmd = out_name
cmd = v.out_name cmd = cmd.replace('/', '\\')
cmd = cmd.replace('/', '\\') }
} return cmd
if os.args.len > 3 { }
cmd += ' ' + os.args.right(3).join(' ')
} fn (v V) run_compiled_executable_and_exit() {
if v.pref.is_verbose {
println('============ running $v.out_name ============')
}
mut cmd := final_target_out_name(v.out_name)
if os.args.len > 3 {
cmd += ' ' + os.args.right(3).join(' ')
}
if v.pref.is_test {
ret := os.system(cmd) ret := os.system(cmd)
if ret != 0 { if ret != 0 {
if !v.pref.is_test {
s := os.exec(cmd)
println(s)
println('failed to run the compiled program')
}
exit(1) exit(1)
} }
}
if v.pref.is_run {
ret := os.system(cmd)
// TODO: make the runner wrapping as transparent as possible
// (i.e. use execve when implemented). For now though, the runner
// just returns the same exit code as the child process
// (see man system, man 2 waitpid: C macro WEXITSTATUS section)
exit( ret >> 8 )
} }
exit(0)
} }
fn (c &V) cc_windows_cross() { fn (c &V) cc_windows_cross() {