diff --git a/infer/src/backend/clusterMakefile.ml b/infer/src/backend/clusterMakefile.ml index af225a178..325c80a82 100644 --- a/infer/src/backend/clusterMakefile.ml +++ b/infer/src/backend/clusterMakefile.ml @@ -21,12 +21,31 @@ let source_file_from_pname pname = let source_file_to_pname fname = Procname.from_string_c_fun (DB.source_file_to_string fname) -let pp_prolog fmt num_clusters = +let pp_prolog fmt clusters = F.fprintf fmt "INFERANALYZE= %s $(INFER_OPTIONS) -results_dir '%s'\n@." Sys.executable_name (Escape.escape_map (fun c -> if c = '#' then Some "\\#" else None) !Config.results_dir); F.fprintf fmt "OBJECTS="; - for i = 1 to num_clusters do F.fprintf fmt "%a " Cluster.pp_cl i done; + let filter cl = match cl with + [ce] -> + begin + match Cluster.get_ondemand_info ce with + | Some source_dir -> + let in_ondemand_config = match Ondemand.read_dirs_to_analyze () with + | None -> + true + | Some set -> + StringSet.mem (DB.source_dir_to_string source_dir) set in + in_ondemand_config + | None -> + true + end + | _ -> + true in + IList.iteri + (fun i cl -> + if filter cl then F.fprintf fmt "%a " Cluster.pp_cl (i+1)) + clusters; F.fprintf fmt "@.@.default: test@.@.all: test@.@."; F.fprintf fmt "test: $(OBJECTS)@.\techo \"Analysis done\"@.@." @@ -74,7 +93,7 @@ let create_cluster_makefile_and_exit !cluster_nr tot_clusters_nr cluster print_files fmt (IntSet.elements !dependent_clusters); (* L.err "cluster %d has %d dependencies@." !cluster_nr (IntSet.cardinal !dependent_clusters) *) in - pp_prolog fmt tot_clusters_nr; + pp_prolog fmt clusters; IList.iter do_cluster clusters; pp_epilog fmt (); exit 0 diff --git a/infer/src/backend/config.ml b/infer/src/backend/config.ml index 1ef25d252..c1c34862f 100644 --- a/infer/src/backend/config.ml +++ b/infer/src/backend/config.ml @@ -27,6 +27,12 @@ let from_env_variable var_name = let _ = Sys.getenv var_name in true with Not_found -> false +let get_env_variable var_name = + try + let v = Sys.getenv var_name in + if v = "" then None else Some v + with Not_found -> None + let attributes_dir_name = "attributes" let captured_dir_name = "captured" let sources_dir_name = "sources" diff --git a/infer/src/backend/iList.ml b/infer/src/backend/iList.ml index 51d2205db..8198e7c43 100644 --- a/infer/src/backend/iList.ml +++ b/infer/src/backend/iList.ml @@ -17,6 +17,7 @@ let for_all2 = List.for_all2 let hd = List.hd let iter = List.iter let iter2 = List.iter2 +let iteri = List.iteri let length = List.length let nth = List.nth let partition = List.partition diff --git a/infer/src/backend/iList.mli b/infer/src/backend/iList.mli index ad8e8cc0a..ac708dc57 100644 --- a/infer/src/backend/iList.mli +++ b/infer/src/backend/iList.mli @@ -36,6 +36,7 @@ val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool val hd : 'a list -> 'a val iter : ('a -> unit) -> 'a list -> unit val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit +val iteri : (int -> 'a -> unit) -> 'a list -> unit val length : 'a list -> int (** tail-recursive variant of List.fold_right *) diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index 3959b0f10..e062beaca 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -22,6 +22,25 @@ let () = Config.ondemand_enabled := let across_files () = true +(** Name of the ondemand file *) +let ondemand_file () = Config.get_env_variable "INFER_ONDEMAND_FILE" + +(** Read the directories to analyze from the ondemand file. *) +let read_dirs_to_analyze () = + let lines_opt = match ondemand_file () with + | None -> None + | Some fname -> Utils.read_file fname in + match lines_opt with + | None -> + None + | Some lines -> + let res = ref StringSet.empty in + let do_line line = + let source_dir = DB.source_dir_from_source_file (DB.source_file_from_string line) in + res := StringSet.add (DB.source_dir_to_string source_dir) !res in + IList.iter do_line lines; + Some !res + type analyze_ondemand = Procname.t -> unit type get_proc_desc = Procname.t -> Cfg.Procdesc.t option diff --git a/infer/src/backend/ondemand.mli b/infer/src/backend/ondemand.mli index 8d552ff3b..4bebe00ca 100644 --- a/infer/src/backend/ondemand.mli +++ b/infer/src/backend/ondemand.mli @@ -9,6 +9,11 @@ (** Module for on-demand analysis. *) +open Utils + +(** Optional set of source dirs to analyze in on-demand mode. *) +val read_dirs_to_analyze : unit -> StringSet.t option + type analyze_ondemand = Procname.t -> unit type get_proc_desc = Procname.t -> Cfg.Procdesc.t option