mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
repl: use os.temp_dir() for the temporary .noprefix.vrepl.v files
This commit is contained in:
parent
e5839effbc
commit
03d5bfbc95
@ -5,6 +5,7 @@ module main
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import term
|
import term
|
||||||
|
import rand
|
||||||
import readline
|
import readline
|
||||||
import os.cmdline
|
import os.cmdline
|
||||||
import v.util
|
import v.util
|
||||||
@ -24,9 +25,9 @@ mut:
|
|||||||
temp_lines []string // all the temporary expressions/printlns
|
temp_lines []string // all the temporary expressions/printlns
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const is_stdin_a_pipe = (is_atty(0) == 0)
|
||||||
is_stdin_a_pipe = (is_atty(0) == 0)
|
|
||||||
)
|
const vexe = os.getenv('VEXE')
|
||||||
|
|
||||||
fn new_repl() Repl {
|
fn new_repl() Repl {
|
||||||
return Repl{
|
return Repl{
|
||||||
@ -112,7 +113,6 @@ fn run_repl(workdir string, vrepl_prefix string) {
|
|||||||
cleanup_files([file, temp_file])
|
cleanup_files([file, temp_file])
|
||||||
}
|
}
|
||||||
mut r := new_repl()
|
mut r := new_repl()
|
||||||
vexe := os.getenv('VEXE')
|
|
||||||
for {
|
for {
|
||||||
if r.indent == 0 {
|
if r.indent == 0 {
|
||||||
prompt = '>>> '
|
prompt = '>>> '
|
||||||
@ -185,10 +185,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
|
|||||||
if r.line.starts_with('print') {
|
if r.line.starts_with('print') {
|
||||||
source_code := r.current_source_code(false) + '\n$r.line\n'
|
source_code := r.current_source_code(false) + '\n$r.line\n'
|
||||||
os.write_file(file, source_code) or { panic(err) }
|
os.write_file(file, source_code) or { panic(err) }
|
||||||
s := os.exec('"$vexe" -repl run "$file"') or {
|
s := repl_run_vfile(file) or { return }
|
||||||
rerror(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
print_output(s)
|
print_output(s)
|
||||||
} else {
|
} else {
|
||||||
mut temp_line := r.line
|
mut temp_line := r.line
|
||||||
@ -255,10 +252,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
|
|||||||
temp_source_code = r.current_source_code(true) + '\n$temp_line\n'
|
temp_source_code = r.current_source_code(true) + '\n$temp_line\n'
|
||||||
}
|
}
|
||||||
os.write_file(temp_file, temp_source_code) or { panic(err) }
|
os.write_file(temp_file, temp_source_code) or { panic(err) }
|
||||||
s := os.exec('"$vexe" -repl run "$temp_file"') or {
|
s := repl_run_vfile(temp_file) or { return }
|
||||||
rerror(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !func_call && s.exit_code == 0 && !temp_flag {
|
if !func_call && s.exit_code == 0 && !temp_flag {
|
||||||
for r.temp_lines.len > 0 {
|
for r.temp_lines.len > 0 {
|
||||||
if !r.temp_lines[0].starts_with('print') {
|
if !r.temp_lines[0].starts_with('print') {
|
||||||
@ -313,9 +307,8 @@ fn main() {
|
|||||||
// so that the repl can be launched in parallel by several different
|
// so that the repl can be launched in parallel by several different
|
||||||
// threads by the REPL test runner.
|
// threads by the REPL test runner.
|
||||||
args := cmdline.options_after(os.args, ['repl'])
|
args := cmdline.options_after(os.args, ['repl'])
|
||||||
replfolder := os.real_path(cmdline.option(args, '-replfolder', '.'))
|
replfolder := os.real_path(cmdline.option(args, '-replfolder', os.temp_dir()))
|
||||||
replprefix := cmdline.option(args, '-replprefix', 'noprefix.')
|
replprefix := cmdline.option(args, '-replprefix', 'noprefix.${rand.ulid()}.')
|
||||||
os.chdir(replfolder)
|
|
||||||
if !os.exists(os.getenv('VEXE')) {
|
if !os.exists(os.getenv('VEXE')) {
|
||||||
println('Usage:')
|
println('Usage:')
|
||||||
println(' VEXE=vexepath vrepl\n')
|
println(' VEXE=vexepath vrepl\n')
|
||||||
@ -356,3 +349,14 @@ fn cleanup_files(files []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn repl_run_vfile(file string) ?os.Result {
|
||||||
|
$if trace_repl_temp_files ? {
|
||||||
|
eprintln('>> repl_run_vfile file: $file')
|
||||||
|
}
|
||||||
|
s := os.exec('"$vexe" -repl run "$file"') or {
|
||||||
|
rerror(err)
|
||||||
|
return error(err)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user