builder: use os.new_process() instead of os.system() in v run (#12214)

pull/12218/head
czkz 2021-10-17 19:01:34 +03:00 committed by GitHub
parent a006090b08
commit 3a073329ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 19 deletions

View File

@ -118,26 +118,30 @@ fn (mut b Builder) run_compiled_executable_and_exit() {
if b.pref.is_verbose {
println('============ running $b.pref.out_name ============')
}
mut exefile := os.real_path(b.pref.out_name)
mut cmd := '"$exefile"'
if b.pref.backend.is_js() {
exefile = os.real_path('${b.pref.out_name}.js').replace('.js.js', '.js')
cmd = 'node "$exefile"'
}
for arg in b.pref.run_args {
// Determine if there are spaces in the parameters
if arg.index_byte(` `) > 0 {
cmd += ' "' + arg + '"'
} else {
cmd += ' ' + arg
}
}
if b.pref.is_verbose {
println('command to run executable: $cmd')
}
if b.pref.is_test || b.pref.is_run {
ret := os.system(cmd)
b.cleanup_run_executable_after_exit(exefile)
compiled_file := os.real_path(b.pref.out_name)
run_file := if b.pref.backend.is_js() {
node_basename := $if windows { 'node.exe' } $else { 'node' }
os.find_abs_path_of_executable(node_basename) or {
panic('Could not find `node` in system path. Do you have Node.js installed?')
}
} else {
compiled_file
}
mut run_args := []string{cap: b.pref.run_args.len + 1}
if b.pref.backend.is_js() {
run_args << compiled_file
}
run_args << b.pref.run_args
mut run_process := os.new_process(run_file)
run_process.set_args(run_args)
if b.pref.is_verbose {
println('running $run_process.filename with arguments $run_process.args')
}
run_process.wait()
ret := run_process.code
run_process.close()
b.cleanup_run_executable_after_exit(compiled_file)
exit(ret)
}
exit(0)