[backend] change cluster type to source files and read list from cfg db

Summary:
This avoids relying on the directories in infer-out/captured/ being created,
and instead gets the list of captured source files from the DB. This gives a
better type to clusters: `SourceFile.t` instead of `DB.source_dir`, which makes
the code a bit nicer too.

Reviewed By: jeremydubreil

Differential Revision: D6620460

fbshipit-source-id: c0edbf6
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent d3c6543cc8
commit 764224139c

@ -628,3 +628,10 @@ let pp_proc_signatures fmt cfg =
let exists_for_source_file source = let exists_for_source_file source =
(* simplistic implementation that allocates the cfg as this is only used for reactive capture for now *) (* simplistic implementation that allocates the cfg as this is only used for reactive capture for now *)
load source |> Option.is_some load source |> Option.is_some
let get_captured_source_files () =
let db = ResultsDatabase.get_database () in
Sqlite3.prepare db "SELECT source_file FROM cfg"
|> SqliteUtils.sqlite_result_rev_list_step db ~log:"getting all source files"
|> List.filter_map ~f:(Option.map ~f:SourceFile.SQLite.deserialize)

@ -64,3 +64,5 @@ val specialize_with_block_args :
val pp_proc_signatures : Format.formatter -> t -> unit val pp_proc_signatures : Format.formatter -> t -> unit
val exists_for_source_file : SourceFile.t -> bool val exists_for_source_file : SourceFile.t -> bool
val get_captured_source_files : unit -> SourceFile.t list

@ -77,23 +77,14 @@ let print_legend () =
let cluster_should_be_analyzed ~changed_files cluster = let cluster_should_be_analyzed ~changed_files cluster =
let fname = DB.source_dir_to_string cluster in
(* whether [fname] is one of the [changed_files] *) (* whether [fname] is one of the [changed_files] *)
let is_changed_file = let is_changed_file = Option.map changed_files ~f:(SourceFile.Set.mem cluster) in
(* set of source dirs to analyze inside infer-out/captured/ *)
let source_dirs_to_analyze changed_files =
SourceFile.Set.fold
(fun source_file source_dir_set ->
let source_dir = DB.source_dir_from_source_file source_file in
String.Set.add source_dir_set (DB.source_dir_to_string source_dir) )
changed_files String.Set.empty
in
Option.map ~f:source_dirs_to_analyze changed_files
|> fun dirs_opt -> Option.map dirs_opt ~f:(fun dirs -> String.Set.mem dirs fname)
in
let check_modified () = let check_modified () =
let modified = DB.file_was_updated_after_start (DB.filename_from_string fname) in let modified =
if modified && Config.developer_mode then L.debug Analysis Medium "Modified: %s@." fname ; DB.source_dir_from_source_file cluster |> DB.source_dir_to_string |> DB.filename_from_string
|> DB.file_was_updated_after_start
in
if modified then L.debug Analysis Medium "Modified: %a@\n" SourceFile.pp cluster ;
modified modified
in in
match is_changed_file with match is_changed_file with
@ -128,7 +119,7 @@ let main ~changed_files ~makefile =
(* delete all specs when doing a full analysis so that we do not report on procedures that do (* delete all specs when doing a full analysis so that we do not report on procedures that do
not exist anymore *) not exist anymore *)
if not Config.reactive_mode then DB.Results_dir.clean_specs_dir () ; if not Config.reactive_mode then DB.Results_dir.clean_specs_dir () ;
let all_clusters = DB.find_source_dirs () in let all_clusters = Cfg.get_captured_source_files () in
let clusters_to_analyze = let clusters_to_analyze =
List.filter ~f:(cluster_should_be_analyzed ~changed_files) all_clusters List.filter ~f:(cluster_should_be_analyzed ~changed_files) all_clusters
in in
@ -142,7 +133,7 @@ let main ~changed_files ~makefile =
let is_java = let is_java =
lazy lazy
(List.exists (List.exists
~f:(fun cl -> DB.string_crc_has_extension ~ext:"java" (DB.source_dir_to_string cl)) ~f:(fun cl -> Filename.check_suffix ".java" (SourceFile.to_string cl))
all_clusters) all_clusters)
in in
print_legend () ; print_legend () ;

@ -14,7 +14,7 @@ module F = Format
(** Module to process clusters of procedures. *) (** Module to process clusters of procedures. *)
(** a cluster is a file *) (** a cluster is a file *)
type t = DB.source_dir type t = SourceFile.t
(** type stored in .cluster file: (n,cl) indicates cl is cluster n *) (** type stored in .cluster file: (n,cl) indicates cl is cluster n *)
type serializer_t = int * t type serializer_t = int * t

@ -13,7 +13,7 @@ module F = Format
(** Module to process clusters of procedures. *) (** Module to process clusters of procedures. *)
(** a cluster is a file *) (** a cluster is a file *)
type t = DB.source_dir type t = SourceFile.t
(** type stored in .cluster file: (n,cl) indicates cl is cluster n *) (** type stored in .cluster file: (n,cl) indicates cl is cluster n *)
type serializer_t = int * t type serializer_t = int * t

@ -42,7 +42,7 @@ let create_cluster_makefile (clusters: Cluster.t list) (fname: string) =
let outc = Out_channel.create fname in let outc = Out_channel.create fname in
let fmt = Format.formatter_of_out_channel outc in let fmt = Format.formatter_of_out_channel outc in
let do_cluster cluster_nr cluster = let do_cluster cluster_nr cluster =
F.fprintf fmt "#%s@\n" (DB.source_dir_to_string cluster) ; F.fprintf fmt "#%a@\n" SourceFile.pp cluster ;
Cluster.pp_cluster fmt (cluster_nr + 1, cluster) Cluster.pp_cluster fmt (cluster_nr + 1, cluster)
in in
pp_prolog fmt clusters ; pp_prolog fmt clusters ;

@ -202,7 +202,8 @@ let get_proc_desc exe_env pname =
(** Create an exe_env from a source dir *) (** Create an exe_env from a source dir *)
let from_cluster cluster = let from_cluster cluster =
let exe_env = create () in let exe_env = create () in
add_cg exe_env cluster ; exe_env add_cg exe_env (DB.source_dir_from_source_file cluster) ;
exe_env
(** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *) (** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *)

Loading…
Cancel
Save