[config] better way to refer to the toplevel results dir

Summary:
The same logic for reading the env var and defaulting to the local
results dir was duplicated in a bunch of places.

Reviewed By: artempyanykh

Differential Revision: D16458976

fbshipit-source-id: 41f1a4f9c
master
Jules Villard 5 years ago committed by Facebook Github Bot
parent 4fe9b2c8dd
commit 75dab37300

@ -2485,9 +2485,7 @@ let inferconfig_file =
let post_parsing_initialization command_opt =
if CommandLineOption.is_originator then (
(* let subprocesses know where the toplevel process' results dir is *)
Unix.putenv ~key:infer_top_results_dir_env_var ~data:!results_dir ;
if CommandLineOption.is_originator then
(* make sure subprocesses read from the same .inferconfig as the toplevel process *)
Option.iter inferconfig_file ~f:(fun filename ->
let abs_filename =
@ -2496,7 +2494,7 @@ let post_parsing_initialization command_opt =
CLOpt.init_work_dir ^/ filename
else filename
in
Unix.putenv ~key:CommandDoc.inferconfig_env_var ~data:abs_filename ) ) ;
Unix.putenv ~key:CommandDoc.inferconfig_env_var ~data:abs_filename ) ;
( match !version with
| `Full when !buck ->
(* Buck reads stderr in some versions, stdout in others *)
@ -3293,3 +3291,10 @@ let is_in_custom_symbols list_name symbol =
let execution_id = Random.self_init () ; Random.int64 Int64.max_value
let toplevel_results_dir =
if CLOpt.is_originator then (
(* let subprocesses know where the toplevel process' results dir is *)
Unix.putenv ~key:infer_top_results_dir_env_var ~data:results_dir ;
results_dir )
else Sys.getenv infer_top_results_dir_env_var |> Option.value ~default:results_dir

@ -99,8 +99,6 @@ val idempotent_getters : bool
val infer_py_argparse_error_exit_code : int
val infer_top_results_dir_env_var : string
val initial_analysis_time : float
val ivar_attributes : string
@ -687,6 +685,12 @@ val threadsafe_aliases : Yojson.Basic.t
val topl_properties : string list
val toplevel_results_dir : string
(** In some integrations, eg Buck, infer subprocesses started by the build system (started by the
toplevel infer process) will have their own results directory; this points to the results
directory of the toplevel infer process, which can be useful for, eg, storing debug info. In
other cases this is equal to {!results_dir}. *)
val trace_error : bool
val trace_events : bool

@ -11,10 +11,7 @@ module CLOpt = CommandLineOption
module IO = struct
let log_file_extension = ".log"
let events_dir =
Option.value (Sys.getenv Config.infer_top_results_dir_env_var) ~default:Config.results_dir
^/ Config.events_dir_name
let events_dir = Config.toplevel_results_dir ^/ Config.events_dir_name
let out_chan = ref None

@ -320,14 +320,9 @@ let setup_log_file () =
()
| None ->
let fmt, chan, preexisting_logfile =
let results_dir =
(* if invoked in a sub-dir (e.g., in Buck integrations), log inside the original log
file *)
Sys.getenv Config.infer_top_results_dir_env_var
|> Option.value ~default:Config.results_dir
in
(* if invoked in a sub-dir (e.g., in Buck integrations), log inside the original log file *)
(* assumes the results dir exists already *)
let logfile_path = results_dir ^/ Config.log_file in
let logfile_path = Config.toplevel_results_dir ^/ Config.log_file in
let preexisting_logfile = PolyVariantEqual.( = ) (Sys.file_exists logfile_path) `Yes in
let chan = Pervasives.open_out_gen [Open_append; Open_creat] 0o666 logfile_path in
let file_fmt =

@ -11,9 +11,7 @@ module L = Logging
let memcached_socket_relative = "memcached.socket"
(** find the results_dir of the top-level infer process *)
let results_dir =
Sys.getenv Config.infer_top_results_dir_env_var |> Option.value ~default:Config.results_dir
let results_dir = Config.toplevel_results_dir
(** log file for memcached *)
let memcached_log = results_dir ^ "/memcached.log"
@ -26,8 +24,8 @@ let shell = "sh"
type server = {input: In_channel.t; output: Out_channel.t}
(* Unix socket paths have a historical length limit of ~100 chars (!?*@&*$). However, this applies
to the argument passed in the system call to create the socket. Thus a workaround is to cd into
(* Unix socket paths have a historical length limit of ~100 chars (!?*@&*$). However, this applies
to the argument passed in the system call to create the socket. Thus a workaround is to cd into
the parent dir of the socket and then create it, hence this function. *)
let in_results_dir ~f =
let cwd = Unix.getcwd () in

@ -224,13 +224,8 @@ let register_gc_stats logger =
let logger =
lazy
(let log_file =
let results_dir =
(* if invoked in a sub-dir (e.g., in Buck integrations), log inside the original log
file *)
Sys.getenv Config.infer_top_results_dir_env_var
|> Option.value ~default:Config.results_dir
in
results_dir ^/ Config.trace_events_file
(* if invoked in a sub-dir (e.g., in Buck integrations), log inside the original log file *)
Config.toplevel_results_dir ^/ Config.trace_events_file
in
let is_toplevel_process = CommandLineOption.is_originator && not !ProcessPoolState.in_child in
( if is_toplevel_process then

Loading…
Cancel
Save