diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index a5b33c4a47..dfb351ff4e 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -40,6 +40,7 @@ const ( ['haiku', '_haiku.v'], ['qnx', '_qnx.v'], ] + vtmp_folder = util.get_vtmp_folder() ) fn main() { @@ -174,7 +175,7 @@ fn (foptions &FormatOptions) format_file(file string) { formatted_content := fmt.fmt(file_ast, table, foptions.is_debug) file_name := os.file_name(file) ulid := rand.ulid() - vfmt_output_path := os.join_path(os.temp_dir(), 'vfmt_${ulid}_$file_name') + vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name') os.write_file(vfmt_output_path, formatted_content) if foptions.is_verbose { eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .') diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v index bba6e675d0..26f9dec6ff 100644 --- a/cmd/tools/vtest-cleancode.v +++ b/cmd/tools/vtest-cleancode.v @@ -82,11 +82,14 @@ fn main() { fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession { os.chdir(vroot) - util.prepare_tool_when_needed(tool_source) testing.eheader('Run `$tool_cmd` over most .v files') mut test_session := testing.new_test_session('$vargs $tool_args') test_session.files << flist test_session.skip_files << slist + util.prepare_tool_when_needed(tool_source) + // note that util.prepare_tool_when_needed will put its temporary files + // in the VTMP from the test session too, so they will be cleaned up + // at the end test_session.test() eprintln(test_session.benchmark.total_message('running `$tool_cmd` over most .v files')) return test_session diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index fdf901425b..f4ed3fa5d6 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -9,21 +9,8 @@ import rand import v.pref import v.util -fn get_vtmp_folder() string { - mut vtmp := os.getenv('VTMP') - if vtmp.len > 0 { - return vtmp - } - vtmp = os.join_path(os.temp_dir(), 'v') - if !os.exists(vtmp) || !os.is_dir(vtmp) { - os.mkdir_all(vtmp) - } - os.setenv('VTMP', vtmp, true) - return vtmp -} - fn (mut b Builder) get_vtmp_filename(base_file_name string, postfix string) string { - vtmp := get_vtmp_folder() + vtmp := util.get_vtmp_folder() mut uniq := '' if !b.pref.reuse_tmpc { uniq = '.$rand.u64()' diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 305532b8e6..7e430fb0e2 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -462,6 +462,19 @@ pub fn recompile_file(vexe string, file string) { } } +pub fn get_vtmp_folder() string { + mut vtmp := os.getenv('VTMP') + if vtmp.len > 0 { + return vtmp + } + vtmp = os.join_path(os.temp_dir(), 'v') + if !os.exists(vtmp) || !os.is_dir(vtmp) { + os.mkdir_all(vtmp) + } + os.setenv('VTMP', vtmp, true) + return vtmp +} + pub fn should_bundle_module(mod string) bool { return mod in bundle_modules || (mod.contains('.') && mod.all_before('.') in bundle_modules) }