From 297254d15e38c6aaed4d85b26248bf70f2e49bb3 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 13 Jul 2017 11:08:04 -0700 Subject: [PATCH] [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 --- infer/src/base/Logging.ml | 24 +++++++++--------------- infer/src/integration/Driver.ml | 4 +++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/infer/src/base/Logging.ml b/infer/src/base/Logging.ml index 250e994ff..5bd6c2b28 100644 --- a/infer/src/base/Logging.ml +++ b/infer/src/base/Logging.ml @@ -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 ; diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index e9091141e..e6437cab9 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -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 =