[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
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 698ebe8049
commit ed29bfef52

@ -16,7 +16,8 @@ let module L = Logging;
let module F = Format; let module F = Format;
let () = { 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 { if Config.print_builtins {
Builtin.print_and_exit () Builtin.print_and_exit ()
}; };

@ -16,8 +16,8 @@ module F = Format
(** Name of dir for logging the output in the specific executable *) (** Name of dir for logging the output in the specific executable *)
let log_dir_of_current_exe = let log_dir_of_current_exe (current_exe : CommandLineOption.exe) =
match Config.current_exe with match current_exe with
| Analyze -> "analyze" | Analyze -> "analyze"
| BuckCompilationDatabase -> "buck_compilation_database" | BuckCompilationDatabase -> "buck_compilation_database"
| Clang -> "clang" | Clang -> "clang"
@ -35,9 +35,9 @@ let err_file = ref "<BUG: logging to a file not setup, what you're looking for w
let out_formatter = ref F.std_formatter let out_formatter = ref F.std_formatter
let err_formatter = ref F.err_formatter let err_formatter = ref F.err_formatter
let set_log_file_identifier string_opt = let set_log_file_identifier (current_exe : CommandLineOption.exe) string_opt =
let should_setup_log_files = let should_setup_log_files =
match Config.current_exe with match current_exe with
| Analyze | Analyze
| Clang -> Config.debug_mode || Config.stats_mode | Clang -> Config.debug_mode || Config.stats_mode
| BuckCompilationDatabase -> true | BuckCompilationDatabase -> true
@ -48,7 +48,7 @@ let set_log_file_identifier string_opt =
| None -> "") ^ string_of_int (Unix.getpid ()) ^ "_" in | None -> "") ^ string_of_int (Unix.getpid ()) ^ "_" in
let exe_log_dir = let exe_log_dir =
let log_dir = Config.results_dir // Config.log_dir_name in 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; create_path exe_log_dir;
let log_file config_opt suffix = let log_file config_opt suffix =
(* the command-line option takes precedence if specified *) (* 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 *) (* 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) let log_file_names () = (!out_file, !err_file)

@ -73,7 +73,7 @@ val set_delayed_prints : print_action list -> unit
val reset_delayed_prints : unit -> unit val reset_delayed_prints : unit -> unit
(** Set a custom identifier to be part of the filename of the current logfiles. *) (** 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 (** print to the current out stream, as specified in set_log_file_identifier
(note: only prints in debug or in stats mode) *) (note: only prints in debug or in stats mode) *)

@ -45,9 +45,8 @@ let register_perf_stats_report source_file => {
}; };
let init_global_state_for_capture_and_linters source_file => { let init_global_state_for_capture_and_linters source_file => {
Logging.set_log_file_identifier ( Logging.set_log_file_identifier
Some (Filename.basename (DB.source_file_to_string source_file)) CommandLineOption.Clang (Some (Filename.basename (DB.source_file_to_string source_file)));
);
register_perf_stats_report source_file; register_perf_stats_report source_file;
Config.curr_language := Config.Clang; Config.curr_language := Config.Clang;
CLocation.curr_file := source_file; CLocation.curr_file := source_file;

@ -84,7 +84,7 @@ let normalize (args: array string) :list ClangCommand.t =>
let execute_clang_command (clang_cmd: 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 */ /* 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 { switch clang_cmd {
| CC1 args => | CC1 args =>
/* this command compiles some code; replace the invocation of clang with our own clang and /* this command compiles some code; replace the invocation of clang with our own clang and

Loading…
Cancel
Save