diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 5cc6216f4..598580154 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -412,6 +412,8 @@ let os_type = match Sys.os_type with "Win32" -> Win32 | "Cygwin" -> Cygwin | _ - directory of the initial invocation of infer. *) let resolve = Utils.filename_to_absolute ~root:CLOpt.init_work_dir +let infer_top_results_dir_env_var = "INFER_TOP_RESULTS_DIR" + let infer_inside_maven_env_var = "INFER_INSIDE_MAVEN" let maven = CLOpt.is_env_var_set infer_inside_maven_env_var @@ -1742,6 +1744,8 @@ let config_file = -> find (Sys.getcwd ()) |> Option.map ~f:(fun dir -> dir ^/ CommandDoc.inferconfig_file) let post_parsing_initialization command_opt = + if CommandLineOption.is_originator then + Unix.putenv ~key:infer_top_results_dir_env_var ~data:!results_dir ; ( match !version with | `Full -> (* TODO(11791235) change back to stdout once buck integration is fixed *) diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 03833c9b3..ed5edb7f4 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -133,6 +133,8 @@ val incremental_procs : 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 diff --git a/infer/src/base/Logging.ml b/infer/src/base/Logging.ml index 548a0251e..298d08c66 100644 --- a/infer/src/base/Logging.ml +++ b/infer/src/base/Logging.ml @@ -270,8 +270,14 @@ let setup_log_file () = () | _, `Console -> let fmt, chan, preexisting_logfile = - (* assumes Config.results_dir exists already *) - let logfile_path = Config.results_dir ^/ Config.log_file in + 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 + (* assumes the results dir exists already *) + let logfile_path = 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 =