From 338a8563a11eb7d75e20995d12633d5c95e91088 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 22 Nov 2016 02:18:58 -0800 Subject: [PATCH] [clang] Don't filter entries when populating compilation database Summary: Sometimes, we'll need to have extra information in compilation database. To keep the code simple just keep information about all files and filter data when scheduling jobs. Perf shouldn't be much worse since we only start one process for infer invocation. Reviewed By: jvillard Differential Revision: D4130884 fbshipit-source-id: 9920c11 --- .../integration/CaptureCompilationDatabase.ml | 25 ++++++++----------- infer/src/integration/CompilationDatabase.ml | 7 +++--- infer/src/integration/CompilationDatabase.mli | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index f06c02ed2..e22f9181f 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -66,10 +66,14 @@ let add_flavor_to_targets args = else arg in IList.map process_arg args -let create_files_stack compilation_database = +let create_files_stack compilation_database changed_files = let stack = Stack.create () in - let add_to_stack file _ = - Stack.push file stack in + let should_add_file_to_cdb changed_files file_path = + match Config.changed_files_index with + | Some _ -> DB.SourceFileSet.mem (DB.source_file_from_string file_path) changed_files + | None -> true in + let add_to_stack file _ = if should_add_file_to_cdb changed_files file then + Stack.push file stack in CompilationDatabase.iter compilation_database add_to_stack; stack @@ -110,20 +114,15 @@ let run_compilation_file compilation_database file = with Not_found -> Process.print_error_and_exit "Failed to find compilation data for %s \n%!" file -let run_compilation_database compilation_database = +let run_compilation_database compilation_database changed_files = let number_of_files = CompilationDatabase.get_size compilation_database in Logging.out "Starting %s %d files \n%!" capture_text number_of_files; Logging.stdout "Starting %s %d files \n%!" capture_text number_of_files; - let jobs_stack = create_files_stack compilation_database in + let jobs_stack = create_files_stack compilation_database changed_files in let capture_text_upper = String.capitalize capture_text in let job_to_string = fun file -> capture_text_upper ^ " " ^ file in Process.run_jobs_in_parallel jobs_stack (run_compilation_file compilation_database) job_to_string -let should_add_file_to_cdb changed_files file_path = - match Config.changed_files_index with - | Some _ -> DB.SourceFileSet.mem (DB.source_file_from_string file_path) changed_files - | None -> true - (** Computes the compilation database files. *) let get_compilation_database_files_buck () = let cmd = IList.rev_append Config.rest (IList.rev Config.buck_build_args) in @@ -181,7 +180,5 @@ let get_compilation_database_files_xcodebuild () = let capture_files_in_database db_json_files = let changed_files = read_files_to_compile () in let compilation_database = CompilationDatabase.empty () in - IList.iter - (CompilationDatabase.decode_json_file - compilation_database (should_add_file_to_cdb changed_files)) db_json_files; - run_compilation_database compilation_database + IList.iter (CompilationDatabase.decode_json_file compilation_database) db_json_files; + run_compilation_database compilation_database changed_files diff --git a/infer/src/integration/CompilationDatabase.ml b/infer/src/integration/CompilationDatabase.ml index 91671f673..3b788bf1b 100644 --- a/infer/src/integration/CompilationDatabase.ml +++ b/infer/src/integration/CompilationDatabase.ml @@ -36,7 +36,7 @@ let parse_command_and_arguments command_and_arguments = to be compiled, the directory to be compiled in, and the compilation command as a list and as a string. We pack this information into the compilationDatabase map, and remove the clang invocation part, because we will use a clang wrapper. *) -let decode_json_file (database : t) should_add_file json_path = +let decode_json_file (database : t) json_path = let exit_format_error () = failwith ("Json file doesn't have the expected format") in let json = Yojson.Basic.from_file json_path in @@ -67,8 +67,7 @@ let decode_json_file (database : t) should_add_file json_path = | Some cmd -> cmd | None -> exit_format_error () in let command, args = parse_command_and_arguments cmd in - if should_add_file file then - let compilation_data = { dir; command; args;} in - database := StringMap.add file compilation_data !database + let compilation_data = { dir; command; args;} in + database := StringMap.add file compilation_data !database | _ -> exit_format_error () in parse_json json diff --git a/infer/src/integration/CompilationDatabase.mli b/infer/src/integration/CompilationDatabase.mli index 1efdee6e3..a046c66ab 100644 --- a/infer/src/integration/CompilationDatabase.mli +++ b/infer/src/integration/CompilationDatabase.mli @@ -25,4 +25,4 @@ val iter : t -> (string -> compilation_data -> unit) -> unit val find : t -> string -> compilation_data -val decode_json_file : t -> (string -> bool) -> string -> unit +val decode_json_file : t -> string -> unit