diff --git a/infer/src/backend/clusterMakefile.ml b/infer/src/backend/clusterMakefile.ml index 32bb893fd..6dbedd577 100644 --- a/infer/src/backend/clusterMakefile.ml +++ b/infer/src/backend/clusterMakefile.ml @@ -25,12 +25,7 @@ let source_file_to_pname fname = let cluster_should_be_analyzed cluster = let fname = DB.source_dir_to_string cluster in - let in_ondemand_config = - match Lazy.force Ondemand.dirs_to_analyze with - | None -> - None - | Some set -> - Some (StringSet.mem fname set) in + let in_ondemand_config = Option.map (StringSet.mem fname) Ondemand.dirs_to_analyze in let check_modified () = let modified = DB.file_was_updated_after_start (DB.filename_from_string fname) in diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index e5afdb2f7..0fa5fe7af 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -14,23 +14,16 @@ open! Utils module L = Logging module F = Format -(** Read the directories to analyze from the ondemand file. *) -let read_dirs_to_analyze () = - match DB.read_changed_files_index with - | None -> - None - | Some lines -> - let res = ref StringSet.empty in - let do_line line = - let rel_file = DB.source_file_to_rel_path (DB.source_file_from_string line) in - let source_dir = DB.source_dir_from_source_file (DB.source_file_from_string rel_file) in - res := StringSet.add (DB.source_dir_to_string source_dir) !res in - IList.iter do_line lines; - Some !res - (** Directories to analyze from the ondemand file. *) let dirs_to_analyze = - lazy (read_dirs_to_analyze ()) + let process_changed_files changed_files = + DB.SourceFileSet.fold + (fun source_file source_dir_set -> + let source_dir = DB.source_dir_from_source_file source_file in + StringSet.add (DB.source_dir_to_string source_dir) source_dir_set + ) + changed_files StringSet.empty in + Option.map process_changed_files DB.changed_source_files_set type analyze_ondemand = DB.source_file -> Procdesc.t -> unit diff --git a/infer/src/backend/ondemand.mli b/infer/src/backend/ondemand.mli index 3196031ae..9b768e26c 100644 --- a/infer/src/backend/ondemand.mli +++ b/infer/src/backend/ondemand.mli @@ -12,7 +12,7 @@ open! Utils (** Module for on-demand analysis. *) (** Optional set of source dirs to analyze in on-demand mode. *) -val dirs_to_analyze : StringSet.t option Lazy.t +val dirs_to_analyze : StringSet.t option type analyze_ondemand = DB.source_file -> Procdesc.t -> unit diff --git a/infer/src/base/DB.ml b/infer/src/base/DB.ml index 429d09506..093d79b14 100644 --- a/infer/src/base/DB.ml +++ b/infer/src/base/DB.ml @@ -419,8 +419,10 @@ let fold_paths_matching ~dir ~p ~init ~f = let paths_matching dir p = fold_paths_matching ~dir ~p ~init:[] ~f:(fun x xs -> x :: xs) -let read_changed_files_index = - match Config.changed_files_index with - | None -> None - | Some fname -> - read_file (source_file_to_abs_path (source_file_from_string fname)) +let changed_source_files_set = + Option.map_default read_file None Config.changed_files_index |> + Option.map ( + IList.fold_left + (fun changed_files line -> SourceFileSet.add (source_file_from_string line) changed_files) + SourceFileSet.empty + ) diff --git a/infer/src/base/DB.mli b/infer/src/base/DB.mli index b63a086b8..60198a501 100644 --- a/infer/src/base/DB.mli +++ b/infer/src/base/DB.mli @@ -174,4 +174,5 @@ val fold_paths_matching : (** Return all file paths recursively under the given directory which match the given predicate *) val paths_matching : string -> (string -> bool) -> string list -val read_changed_files_index : string list option +(** Set of files read from --changed-files-index file, None if option not specified *) +val changed_source_files_set : SourceFileSet.t option diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index 858719288..a82d49179 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -16,24 +16,22 @@ let capture_text = if Config.analyzer = Config.Linters then "linting" else "translating" -let replace_header_file_with_source_file file_path = - Option.default file_path (DB.source_file_of_header file_path) - (** Read the files to compile from the changed files index. *) let should_capture_file_from_index () = - match DB.read_changed_files_index with + match DB.changed_source_files_set with | None -> (match Config.changed_files_index with | Some index -> Process.print_error_and_exit "Error reading the changed files index %s.\n%!" index | None -> function _ -> true) - | Some lines -> - let index_files_set = IList.fold_left - (fun changed_files line -> - let file = replace_header_file_with_source_file (DB.source_file_from_string line) in - DB.SourceFileSet.add file changed_files) - DB.SourceFileSet.empty lines in - function source_file -> DB.SourceFileSet.mem source_file index_files_set + | Some files_set -> + function source_file -> + DB.SourceFileSet.mem source_file files_set || + (* as fallback try to capture corresponding source file for headers *) + Option.map_default + (fun src -> DB.SourceFileSet.mem src files_set) + false + (DB.source_file_of_header source_file) (** The buck targets are assumed to start with //, aliases are not supported. *) let check_args_for_targets args =