From ed29bfef527a2b3924cc4ed34cfacd2d8b6ca0dc Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Fri, 28 Oct 2016 08:01:20 -0700 Subject: [PATCH] [logging] Provide binary type to logging module Summary: Now that it's possible to run clang wrapper as a function from another process, Logging module cannot rely on `Config.current_exe` to determine which directory it should write to. Reviewed By: jeremydubreil Differential Revision: D4095455 fbshipit-source-id: d989b06 --- infer/src/backend/InferAnalyze.re | 3 ++- infer/src/base/Logging.ml | 12 ++++++------ infer/src/base/Logging.mli | 2 +- infer/src/clang/Capture.re | 5 ++--- infer/src/clang/ClangWrapper.re | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/infer/src/backend/InferAnalyze.re b/infer/src/backend/InferAnalyze.re index 298e92241..8714cd08c 100644 --- a/infer/src/backend/InferAnalyze.re +++ b/infer/src/backend/InferAnalyze.re @@ -16,7 +16,8 @@ let module L = Logging; let module F = Format; let () = { - Logging.set_log_file_identifier (Option.map Filename.basename Config.cluster_cmdline); + Logging.set_log_file_identifier + CommandLineOption.Analyze (Option.map Filename.basename Config.cluster_cmdline); if Config.print_builtins { Builtin.print_and_exit () }; diff --git a/infer/src/base/Logging.ml b/infer/src/base/Logging.ml index 2791530f0..337bbc404 100644 --- a/infer/src/base/Logging.ml +++ b/infer/src/base/Logging.ml @@ -16,8 +16,8 @@ module F = Format (** Name of dir for logging the output in the specific executable *) -let log_dir_of_current_exe = - match Config.current_exe with +let log_dir_of_current_exe (current_exe : CommandLineOption.exe) = + match current_exe with | Analyze -> "analyze" | BuckCompilationDatabase -> "buck_compilation_database" | Clang -> "clang" @@ -35,9 +35,9 @@ let err_file = ref " Config.debug_mode || Config.stats_mode | BuckCompilationDatabase -> true @@ -48,7 +48,7 @@ let set_log_file_identifier string_opt = | None -> "") ^ string_of_int (Unix.getpid ()) ^ "_" in let exe_log_dir = let log_dir = Config.results_dir // Config.log_dir_name in - log_dir // log_dir_of_current_exe in + log_dir // (log_dir_of_current_exe current_exe) in create_path exe_log_dir; let log_file config_opt suffix = (* the command-line option takes precedence if specified *) @@ -77,7 +77,7 @@ let set_log_file_identifier string_opt = ) (* set up log files on startup if needed *) -let () = set_log_file_identifier None +let () = set_log_file_identifier Config.current_exe None let log_file_names () = (!out_file, !err_file) diff --git a/infer/src/base/Logging.mli b/infer/src/base/Logging.mli index b918a3056..148e7f835 100644 --- a/infer/src/base/Logging.mli +++ b/infer/src/base/Logging.mli @@ -73,7 +73,7 @@ val set_delayed_prints : print_action list -> unit val reset_delayed_prints : unit -> unit (** Set a custom identifier to be part of the filename of the current logfiles. *) -val set_log_file_identifier : string option -> unit +val set_log_file_identifier : CommandLineOption.exe -> string option -> unit (** print to the current out stream, as specified in set_log_file_identifier (note: only prints in debug or in stats mode) *) diff --git a/infer/src/clang/Capture.re b/infer/src/clang/Capture.re index 22f85eb50..2527ff23e 100644 --- a/infer/src/clang/Capture.re +++ b/infer/src/clang/Capture.re @@ -45,9 +45,8 @@ let register_perf_stats_report source_file => { }; let init_global_state_for_capture_and_linters source_file => { - Logging.set_log_file_identifier ( - Some (Filename.basename (DB.source_file_to_string source_file)) - ); + Logging.set_log_file_identifier + CommandLineOption.Clang (Some (Filename.basename (DB.source_file_to_string source_file))); register_perf_stats_report source_file; Config.curr_language := Config.Clang; CLocation.curr_file := source_file; diff --git a/infer/src/clang/ClangWrapper.re b/infer/src/clang/ClangWrapper.re index 138676629..0a828ba14 100644 --- a/infer/src/clang/ClangWrapper.re +++ b/infer/src/clang/ClangWrapper.re @@ -84,7 +84,7 @@ let normalize (args: array string) :list ClangCommand.t => let execute_clang_command (clang_cmd: ClangCommand.t) => { /* reset logging, otherwise we might print into the logs of the previous file that was compiled */ - Logging.set_log_file_identifier None; + Logging.set_log_file_identifier CommandLineOption.Clang None; switch clang_cmd { | CC1 args => /* this command compiles some code; replace the invocation of clang with our own clang and