[buck] create log files erase at the end of the run

Summary: This way, if infer crashes then the log files will be available for inspection, but if it succeeds we still get rid of the (non-deterministic) logs before Buck caches the results.

Reviewed By: sblackshear

Differential Revision: D5416032

fbshipit-source-id: 22e58be
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 5dd4b1c870
commit 297254d15e

@ -287,21 +287,15 @@ let setup_log_file () =
()
| _, `Buffer b
-> let fmt, chan, preexisting_logfile =
if Config.buck_cache_mode then
(* suppress log file in order not to cause flakiness in the Buck cache *)
let devnull_chan = Out_channel.create "/dev/null" in
let devnull_fmt = F.formatter_of_out_channel devnull_chan in
(devnull_fmt, devnull_chan, true)
else
(* assumes Config.results_dir exists already *)
let logfile_path = Config.results_dir ^/ Config.log_file in
let preexisting_logfile = PVariant.( = ) (Sys.file_exists logfile_path) `Yes in
let chan = Pervasives.open_out_gen [Open_append; Open_creat] 0o666 logfile_path in
let file_fmt =
let f = F.formatter_of_out_channel chan in
if Config.print_logs then dup_formatter f F.err_formatter else f
in
(file_fmt, chan, preexisting_logfile)
(* assumes Config.results_dir exists already *)
let logfile_path = Config.results_dir ^/ Config.log_file in
let preexisting_logfile = PVariant.( = ) (Sys.file_exists logfile_path) `Yes in
let chan = Pervasives.open_out_gen [Open_append; Open_creat] 0o666 logfile_path in
let file_fmt =
let f = F.formatter_of_out_channel chan in
if Config.print_logs then dup_formatter f F.err_formatter else f
in
(file_fmt, chan, preexisting_logfile)
in
log_file := (fmt, `Channel chan) ;
if preexisting_logfile then is_newline := false ;

@ -143,13 +143,15 @@ let clean_results_dir () =
List.mem ~equal:String.equal dirs_to_delete
in
let should_delete_file =
let files_to_delete = [Config.log_file] in
let suffixes_to_delete =
".txt" :: ".csv" :: ".json" :: (if Config.flavors then [] else [".cfg"; ".cg"])
in
fun name ->
(* Keep the JSON report *)
not (String.equal (Filename.basename name) Config.report_json)
&& List.exists ~f:(Filename.check_suffix name) suffixes_to_delete
&& ( List.mem ~equal:String.equal files_to_delete (Filename.basename name)
|| List.exists ~f:(Filename.check_suffix name) suffixes_to_delete )
in
let rec clean name =
let rec cleandir dir =

Loading…
Cancel
Save