[buckjava2] refactor

Reviewed By: jberdine

Differential Revision: D15516135

fbshipit-source-id: e8067cf66
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent 768e2b0332
commit bc61543875

@ -56,7 +56,7 @@ let add source_file cfg tenv integer_type_widths =
if not (Caml.Hashtbl.mem existing_proc_names proc_name) then proc_name :: proc_names if not (Caml.Hashtbl.mem existing_proc_names proc_name) then proc_name :: proc_names
else proc_names ) else proc_names )
in in
(Tenv.merge ~dst:old_tenv ~src:tenv, proc_names) (Tenv.merge_per_file ~dst:old_tenv ~src:tenv, proc_names)
| None -> | None ->
(tenv, new_proc_names) (tenv, new_proc_names)
in in

@ -100,13 +100,14 @@ module SQLite : SqliteUtils.Data with type t = per_file = struct
FileLocal (Marshal.from_string b 0) FileLocal (Marshal.from_string b 0)
end end
let merge ~src ~dst = let merge ~src ~dst = TypenameHash.iter (fun pname cfg -> TypenameHash.replace dst pname cfg) src
let merge_per_file ~src ~dst =
match (src, dst) with match (src, dst) with
| Global, Global -> | Global, Global ->
Global Global
| FileLocal src_tenv, FileLocal dst_tenv -> | FileLocal src_tenv, FileLocal dst_tenv ->
TypenameHash.iter (fun pname cfg -> TypenameHash.replace dst_tenv pname cfg) src_tenv ; merge ~src:src_tenv ~dst:dst_tenv ; FileLocal dst_tenv
FileLocal dst_tenv
| Global, FileLocal _ | FileLocal _, Global -> | Global, FileLocal _ | FileLocal _, Global ->
L.die InternalError "Cannot merge Global tenv with FileLocal tenv" L.die InternalError "Cannot merge Global tenv with FileLocal tenv"
@ -125,9 +126,10 @@ let global_tenv : t option ref = ref None
let global_tenv_path = Config.(results_dir ^/ global_tenv_filename) |> DB.filename_from_string let global_tenv_path = Config.(results_dir ^/ global_tenv_filename) |> DB.filename_from_string
let read path = Serialization.read_from_file tenv_serializer path
let load_global () : t option = let load_global () : t option =
if is_none !global_tenv then if is_none !global_tenv then global_tenv := read global_tenv_path ;
global_tenv := Serialization.read_from_file tenv_serializer global_tenv_path ;
!global_tenv !global_tenv

@ -20,6 +20,9 @@ val load : SourceFile.t -> t option
val store_debug_file_for_source : SourceFile.t -> t -> unit val store_debug_file_for_source : SourceFile.t -> t -> unit
val read : DB.filename -> t option
(** read and return a type environment from the given file *)
val load_global : unit -> t option val load_global : unit -> t option
(** load the global type environment (Java) *) (** load the global type environment (Java) *)
@ -54,8 +57,11 @@ val pp_per_file : Format.formatter -> per_file -> unit
[@@warning "-32"] [@@warning "-32"]
(** print per file type environment *) (** print per file type environment *)
val merge : src:per_file -> dst:per_file -> per_file val merge : src:t -> dst:t -> unit
(** Merge [src] into [dst] possibly overwriting pre existing procs in [dst]. *)
val merge_per_file : src:per_file -> dst:per_file -> per_file
(** Best-effort merge of [src] into [dst]. If a procedure is both in [dst] and [src], the one in (** Best-effort merge of [src] into [dst]. If a procedure is both in [dst] and [src], the one in
[src] will get overwritten. *) [dst] will get overwritten. *)
module SQLite : SqliteUtils.Data with type t = per_file module SQLite : SqliteUtils.Data with type t = per_file

@ -42,7 +42,8 @@ let merge_source_files_table ~db_file =
~log:(Printf.sprintf "copying source_files of database '%s'" db_file) ~log:(Printf.sprintf "copying source_files of database '%s'" db_file)
let merge ~db_file = let merge infer_out_src =
let db_file = infer_out_src ^/ ResultsDatabase.database_filename in
let main_db = ResultsDatabase.get_database () in let main_db = ResultsDatabase.get_database () in
Sqlite3.exec main_db (Printf.sprintf "ATTACH '%s' AS attached" db_file) Sqlite3.exec main_db (Printf.sprintf "ATTACH '%s' AS attached" db_file)
|> SqliteUtils.check_result_code main_db ~log:(Printf.sprintf "attaching database '%s'" db_file) ; |> SqliteUtils.check_result_code main_db ~log:(Printf.sprintf "attaching database '%s'" db_file) ;
@ -53,7 +54,7 @@ let merge ~db_file =
() ()
let merge_buck_flavors_results infer_deps_file = let iter_infer_deps infer_deps_file ~f =
let one_line line = let one_line line =
match String.split ~on:'\t' line with match String.split ~on:'\t' line with
| [_; _; target_results_dir] -> | [_; _; target_results_dir] ->
@ -62,7 +63,7 @@ let merge_buck_flavors_results infer_deps_file =
Filename.dirname (Config.project_root ^/ "buck-out") ^/ target_results_dir Filename.dirname (Config.project_root ^/ "buck-out") ^/ target_results_dir
else target_results_dir else target_results_dir
in in
merge ~db_file:(infer_out_src ^/ ResultsDatabase.database_filename) f infer_out_src
| _ -> | _ ->
assert false assert false
in in
@ -71,3 +72,6 @@ let merge_buck_flavors_results infer_deps_file =
List.iter ~f:one_line lines List.iter ~f:one_line lines
| Error error -> | Error error ->
L.internal_error "Couldn't read deps file '%s': %s" infer_deps_file error L.internal_error "Couldn't read deps file '%s': %s" infer_deps_file error
let merge_buck_flavors_results infer_deps_file = iter_infer_deps infer_deps_file ~f:merge

@ -10,3 +10,5 @@ open! IStd
val merge_buck_flavors_results : string -> unit val merge_buck_flavors_results : string -> unit
(** Merge the results from sub-invocations of infer inside buck-out/. Takes as argument the (** Merge the results from sub-invocations of infer inside buck-out/. Takes as argument the
infer_deps file. *) infer_deps file. *)
val iter_infer_deps : string -> f:(string -> unit) -> unit

Loading…
Cancel
Save