From 377d284cf211c8a8738d3fdb120dfd043fdf00e3 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 26 Aug 2016 13:14:10 -0700 Subject: [PATCH] Simplify originator detection Summary: This simplifies the determination of whether the current process is the originator of all the infer sub-processes. Reviewed By: jvillard Differential Revision: D3751324 fbshipit-source-id: 5e6dc6b --- infer/src/backend/config.ml | 6 ++--- infer/src/backend/config.mli | 2 ++ infer/src/backend/crashcontext.ml | 45 +++++++++++++------------------ infer/src/backend/infer.ml | 9 ++++--- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/infer/src/backend/config.ml b/infer/src/backend/config.ml index ad5aa99c3..fc2fa720c 100644 --- a/infer/src/backend/config.ml +++ b/infer/src/backend/config.ml @@ -352,9 +352,9 @@ let patterns_of_json_with_key json_key json = (** The working directory of the initial invocation of infer, to which paths passed as command line options are relative. *) -let init_work_dir = +let init_work_dir, is_originator = try - Sys.getenv "INFER_CWD" + (Sys.getenv "INFER_CWD", false) with Not_found -> let cwd = (* Use PWD if it denotes the same inode as ., to try to avoid paths with symlinks resolved *) @@ -372,7 +372,7 @@ let init_work_dir = Sys.getcwd () in Unix.putenv "INFER_CWD" cwd ; - cwd + (cwd, true) (** Resolve relative paths passed as command line options, i.e., with respect to the working directory of the initial invocation of infer. *) diff --git a/infer/src/backend/config.mli b/infer/src/backend/config.mli index c5df57d4b..0e60b59e7 100644 --- a/infer/src/backend/config.mli +++ b/infer/src/backend/config.mli @@ -131,6 +131,8 @@ val lazy_dynamic_dispatch : bool val report_custom_error : bool val sound_dynamic_dispatch : bool +val is_originator : bool + (** Configuration values specified by command-line options *) diff --git a/infer/src/backend/crashcontext.ml b/infer/src/backend/crashcontext.ml index bc2958723..bb9942ec1 100644 --- a/infer/src/backend/crashcontext.ml +++ b/infer/src/backend/crashcontext.ml @@ -110,30 +110,21 @@ let collect_all_summaries root_summaries_dir stacktrace_file stacktraces_dir = IList.iter process_stacktrace input_output_file_pairs let crashcontext_epilogue ~in_buck_mode = - (* check whether this is the top-level infer process *) - let top_level_infer = - (* if the '--buck' option was passed, then this is the top level process - iff the build command starts with 'buck' *) - if Config.buck then in_buck_mode - (* otherwise, we assume javac as the build command and thus only one - process *) - else true in - if top_level_infer then - (* if we are the top-level process, then find the output directory and - collect all crashcontext summaries under it in a single - crashcontext.json file. - Important: Note that when running under buck, this is not the final - infer-out/ directory, but instead it is buck-out/, which contains the - infer output directories for every buck target. *) - let root_summaries_dir = if in_buck_mode then begin - let project_root = match Config.project_root with - | Some root -> root - | None -> Filename.dirname Config.results_dir in - let buck_out = match Config.buck_out with - | Some dir -> dir - | None -> "buck-out" in - project_root // buck_out - end - else Config.results_dir in - collect_all_summaries - root_summaries_dir Config.stacktrace Config.stacktraces_dir + (* if we are the top-level process, then find the output directory and + collect all crashcontext summaries under it in a single + crashcontext.json file. + Important: Note that when running under buck, this is not the final + infer-out/ directory, but instead it is buck-out/, which contains the + infer output directories for every buck target. *) + let root_summaries_dir = if in_buck_mode then begin + let project_root = match Config.project_root with + | Some root -> root + | None -> Filename.dirname Config.results_dir in + let buck_out = match Config.buck_out with + | Some dir -> dir + | None -> "buck-out" in + project_root // buck_out + end + else Config.results_dir in + collect_all_summaries + root_summaries_dir Config.stacktrace Config.stacktraces_dir diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index da8cb2fd6..29e0ce906 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -117,10 +117,13 @@ let () = if exit_code = Config.infer_py_argparse_error_exit_code then (* swallow infer.py argument parsing error *) Config.print_usage_exit (); - if Config.analyzer = Some Config.Crashcontext then - Crashcontext.crashcontext_epilogue ~in_buck_mode; if exit_code <> 0 then ( prerr_endline ("Failed to execute: " ^ (String.concat " " (Array.to_list args_py))) ; exit exit_code ); - if Config.fail_on_bug then fail_on_issue_epilogue () + if Config.is_originator then ( + if Config.analyzer = Some Config.Crashcontext then + Crashcontext.crashcontext_epilogue ~in_buck_mode; + if Config.fail_on_bug then + fail_on_issue_epilogue (); + )