[DB] Cleanup code related to --changed-files-index

Summary:
Clean up code related to --changed-files-index option:
1. Store DB.SourceFileSet.t in DB.changed_source_files_set
2. Refactor rest of the code to use it
3. Bunch of minor changes to make code more consise

Reviewed By: jberdine

Differential Revision: D4238736

fbshipit-source-id: 51e5684
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 9d6a6510e8
commit d4c634e50f

@ -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

@ -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

@ -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

@ -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
)

@ -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

@ -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 =

Loading…
Cancel
Save