From 8f85396a31b82ef0e9e30c3d9b8d650adedbee03 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 24 Oct 2020 15:08:45 +0300 Subject: [PATCH] builder: use unique .tmp.c and .tmp.c.rsp files, and rm them on successfull non debug builds. --- vlib/v/builder/cc.v | 12 ++++++++++++ vlib/v/builder/compile.v | 4 +++- vlib/v/pref/pref.v | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index e860aebf44..06fc468160 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -78,6 +78,14 @@ fn (mut v Builder) find_win_cc() ? { fn (mut v Builder) post_process_c_compiler_output(res os.Result) { if res.exit_code == 0 { + for tmpfile in v.pref.cleanup_files { + if os.is_file(tmpfile) { + if v.pref.is_verbose { + eprintln('>> remove tmp file: $tmpfile') + } + os.rm(tmpfile) + } + } return } for emsg_marker in [c_verror_message_marker, 'error: include file '] { @@ -493,6 +501,10 @@ fn (mut v Builder) cc() { os.write_file(response_file, response_file_content) or { verror('Unable to write response file "$response_file"') } + if !debug_mode { + v.pref.cleanup_files << v.out_name_c + v.pref.cleanup_files << response_file + } start: todo() // TODO remove diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 16bbd47e8d..006c8a88eb 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -5,6 +5,7 @@ module builder import time import os +import rand import v.pref import v.util @@ -23,7 +24,8 @@ fn get_vtmp_folder() string { fn get_vtmp_filename(base_file_name string, postfix string) string { vtmp := get_vtmp_folder() - return os.real_path(os.join_path(vtmp, os.file_name(os.real_path(base_file_name)) + postfix)) + uniq := rand.u64() + return os.real_path(os.join_path(vtmp, os.file_name(os.real_path(base_file_name)) + '.${uniq}${postfix}')) } pub fn compile(command string, pref &pref.Preferences) { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 0ccd79860e..80548fa374 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -126,6 +126,7 @@ pub mut: show_timings bool // show how much time each compiler stage took is_ios_simulator bool is_apk bool // build as Android .apk format + cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successfull builds. } pub fn parse_args(args []string) (&Preferences, string) {