[DB] Move header -> source function to DB.

Summary:
Implement heuristics to get from corresponding source files for header files.
We already had initial implementation for CaptureCompilationDatabase - moved it and extended it
to handle C/C++/objC/objC++

Reviewed By: jberdine

Differential Revision: D4231864

fbshipit-source-id: 4516287
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent ca9ce58150
commit 3d9e5821ef

@ -131,6 +131,30 @@ let source_file_is_cpp_model file =
string_is_prefix Config.relative_cpp_models_dir path
| _ -> false
let source_file_exists_cache = Hashtbl.create 256
let source_file_path_exists abs_path =
try Hashtbl.find source_file_exists_cache abs_path
with Not_found ->
let result = Sys.file_exists abs_path in
Hashtbl.add source_file_exists_cache abs_path result;
result
let source_file_of_header header_file =
let abs_path = source_file_to_abs_path header_file in
let source_file_exts = ["c"; "cc"; "cpp"; "cxx"; "m"; "mm"] in
let header_file_exts = ["h"; "hh"; "hpp"; "hxx"] in
let file_no_ext, ext_opt = Core.Std.Filename.split_extension abs_path in
let file_opt = match ext_opt with
| Some ext when IList.mem string_equal ext header_file_exts -> (
let possible_files = IList.map (fun ext -> file_no_ext ^ "." ^ ext) source_file_exts in
try Some (IList.find source_file_path_exists possible_files)
with Not_found -> None
)
| _ -> None in
Option.map source_file_from_abs_path file_opt
(** {2 Source Dirs} *)
(** source directory: the directory inside the results dir corresponding to a source file *)

@ -120,6 +120,10 @@ val source_file_is_infer_model : source_file -> bool
(** Returns true if the file is a C++ model *)
val source_file_is_cpp_model : source_file -> bool
(** Return approximate source file corresponding to the parameter if it's header file and
file exists. returns None otherwise *)
val source_file_of_header : source_file -> source_file option
(** {2 Source Dirs} *)
(** source directory: the directory inside the results dir corresponding to a source file *)

@ -17,18 +17,7 @@ let capture_text =
else "translating"
let replace_header_file_with_source_file file_path =
let file_path = DB.source_file_to_abs_path file_path in
let possible_file_replacements file_path =
IList.map (fun suffix -> (Filename.chop_extension file_path) ^ suffix ) [".m"; ".mm"] in
let file =
if Filename.check_suffix file_path ".h" || Filename.check_suffix file_path ".hh" then
try
IList.find Sys.file_exists (possible_file_replacements file_path)
with Not_found ->
Logging.out "Couldn't find any replacement source file for file %s " file_path;
file_path
else file_path in
DB.source_file_from_abs_path file
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 () =

Loading…
Cancel
Save