From 45f5dd658e7a24da7d6cbcd5a1e2364ee948ab1a Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 19 Oct 2016 07:49:59 -0700 Subject: [PATCH] [clang] Find source files that import header files we want to analyse Reviewed By: martinoluca Differential Revision: D4038097 fbshipit-source-id: 332b7d5 --- .../src/integration/BuckCompilationDatabase.ml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/infer/src/integration/BuckCompilationDatabase.ml b/infer/src/integration/BuckCompilationDatabase.ml index 1043a59af..5d055a08a 100644 --- a/infer/src/integration/BuckCompilationDatabase.ml +++ b/infer/src/integration/BuckCompilationDatabase.ml @@ -31,6 +31,21 @@ let swap_command cmd = (* The command in the compilation database json emitted by buck can only be clang or clang++ *) failwithf "Unexpected command name in Buck compilation database: %s" cmd + +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.abs_source_file_from_path file + (** Read the files to compile from the changed files index. *) let read_files_to_compile () = let changed_files = DB.SourceFileSet.empty in @@ -43,7 +58,8 @@ let read_files_to_compile () = | Some lines -> IList.fold_left (fun changed_files line -> - DB.SourceFileSet.add (DB.abs_source_file_from_path line) changed_files) + let file = replace_header_file_with_source_file (DB.abs_source_file_from_path line) in + DB.SourceFileSet.add file changed_files) changed_files lines (** Add file to compilation database, only if it is in changed_files. *)