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

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

Loading…
Cancel
Save