From fbf6910ab9b0d7143983590882af9f21337287af Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 5 Dec 2020 13:03:12 +0200 Subject: [PATCH] builder: remove executables after `v run file.v` --- vlib/v/builder/compile.v | 16 +++++++++------- vlib/v/pref/pref.v | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 8a687c5bac..ba04795eca 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -129,20 +129,22 @@ fn (mut b Builder) run_compiled_executable_and_exit() { if b.pref.is_verbose { println('command to run executable: $cmd') } - if b.pref.is_test { - exit(os.system(cmd)) - } - if b.pref.is_run { + if b.pref.is_test || b.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. + b.cleanup_run_executable_after_exit(exefile) exit(ret) } } exit(0) } +fn (mut v Builder) cleanup_run_executable_after_exit(exefile string) { + if os.is_file(exefile) { + v.pref.vrun_elog('remove run executable: $exefile') + os.rm(exefile) + } +} + // 'strings' => 'VROOT/vlib/strings' // 'installed_mod' => '~/.vmodules/installed_mod' // 'local_mod' => '/path/to/current/dir/local_mod' diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 721d2e5362..d30c8a9f31 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -486,7 +486,7 @@ pub fn parse_args(args []string) (&Preferences, string) { return res, command } -fn (pref &Preferences) vrun_elog(s string) { +pub fn (pref &Preferences) vrun_elog(s string) { if pref.is_verbose { eprintln('> v run -, $s') }