From 69f8ebaef65938a7d06e70c3efe8ac61c00d6e26 Mon Sep 17 00:00:00 2001 From: Vincent Siles Date: Fri, 21 Sep 2018 09:13:51 -0700 Subject: [PATCH] have infer automatically figure out when `--merge` is needed Reviewed By: jvillard Differential Revision: D9942867 fbshipit-source-id: 0652925c1 --- infer/src/atd/runstate.atd | 1 + infer/src/base/RunState.ml | 7 ++++++- infer/src/base/RunState.mli | 6 ++++++ infer/src/integration/Driver.ml | 8 +++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/infer/src/atd/runstate.atd b/infer/src/atd/runstate.atd index 3ded5f6b9..fe76e0b45 100644 --- a/infer/src/atd/runstate.atd +++ b/infer/src/atd/runstate.atd @@ -20,4 +20,5 @@ type run_info = { type t = { run_sequence: run_info list; (** successive runs that re-used the same results directory *) results_dir_format: string; (** to check if the versions of the results dir are compatible *) + should_merge_capture: bool; (** add --merge to 'infer analyze' if last command was a capture that needs --merge *) } diff --git a/infer/src/base/RunState.ml b/infer/src/base/RunState.ml index 2d41f671b..c6b2c168e 100644 --- a/infer/src/base/RunState.ml +++ b/infer/src/base/RunState.ml @@ -14,7 +14,8 @@ let state0 = { run_sequence= [] ; results_dir_format= Printf.sprintf "db_filename: %s\ndb_schema: %s" ResultsDatabase.database_filename - ResultsDatabase.schema_hum } + ResultsDatabase.schema_hum + ; should_merge_capture= false } let state : Runstate_t.t ref = ref state0 @@ -66,3 +67,7 @@ let load_and_validate () = let reset () = state := state0 + +let set_merge_capture onoff = Runstate_t.(state := {!state with should_merge_capture= onoff}) + +let get_merge_capture () = !state.Runstate_t.should_merge_capture diff --git a/infer/src/base/RunState.mli b/infer/src/base/RunState.mli index 5074a8985..80ff0ccd2 100644 --- a/infer/src/base/RunState.mli +++ b/infer/src/base/RunState.mli @@ -10,6 +10,12 @@ open! IStd val add_run_to_sequence : unit -> unit (** add an entry with the current run date *) +val set_merge_capture : bool -> unit +(** update the 'merge after capture' smart option *) + +val get_merge_capture : unit -> bool +(** fetch the value of the 'merge after capture' smart option *) + val store : unit -> unit (** save the current state to disk *) diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 203f06154..a6fd4a842 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -279,6 +279,7 @@ let capture ~changed_files = function updated_buck_cmd ) else build_cmd ) ) in + if in_buck_mode && Config.flavors then ( RunState.set_merge_capture true ; RunState.store () ) ; run_command ~prog:infer_py ~args ~cleanup:(function | Error (`Exit_non_zero exit_code) @@ -394,10 +395,15 @@ let analyze_and_report ?suppress_console_report ~changed_files mode = | PythonCapture (BBuck, _) when Config.flavors && InferCommand.equal Run Config.command -> (* if doing capture + analysis of buck with flavors, we always need to merge targets before the analysis phase *) true + | Analyze -> + RunState.get_merge_capture () | _ -> (* else rely on the command line value *) Config.merge in - if should_merge then MergeCapture.merge_captured_targets () ; + if should_merge then ( + MergeCapture.merge_captured_targets () ; + RunState.set_merge_capture false ; + RunState.store () ) ; if should_analyze then if SourceFiles.is_empty () && Config.capture then error_nothing_to_analyze mode else execute_analyze ~changed_files ;