diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index de9fad74e..4df16874d 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -63,7 +63,7 @@ let add_flavors_to_buck_command build_cmd = if not found_one_target then no_targets_found_error_and_exit build_cmd ; cmd' -let call_buck_query_for_dependencies targets = +let get_dependency_targets_and_add_flavors targets = let build_deps_string targets = List.map targets ~f:(fun target -> Printf.sprintf "deps('%s')" target) |> String.concat ~sep:" union " @@ -82,9 +82,5 @@ let call_buck_query_for_dependencies targets = "*** command failed:@\n*** %s@\n*** %s@." buck_query_cmd (Unix.Exit_or_signal.to_string_hum status) | Ok () - -> List.map ~f:(fun name -> string_of_target {name; flavors= Config.append_buck_flavors}) output - -let get_dependency_targets args = - let targets, no_targets = List.partition_tf ~f:is_target_string args in - let targets = call_buck_query_for_dependencies targets in - (targets, no_targets) + -> List.map output ~f:(fun name -> + string_of_target (add_flavor_to_target {name; flavors= Config.append_buck_flavors}) ) diff --git a/infer/src/integration/Buck.mli b/infer/src/integration/Buck.mli index 1f38ca732..a01836a6b 100644 --- a/infer/src/integration/Buck.mli +++ b/infer/src/integration/Buck.mli @@ -23,6 +23,6 @@ val add_flavors_to_buck_command : string list -> string list buck build //foo/bar:baz#infer-capture-all,some,flavor *) -val get_dependency_targets : string list -> string list * string list +val get_dependency_targets_and_add_flavors : string list -> string list (** Runs buck query to get the dependency targets of the given targets [get_dependency_targets args] = targets with dependent targets, other args *) diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index b3963de48..8309deefc 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -64,28 +64,31 @@ let run_compilation_database compilation_database should_capture_file = Process.run_jobs_in_parallel ~fail_on_failed_job jobs_stack (run_compilation_file compilation_database) job_to_string +let buck_targets_in_file buck_targets = + let file = Filename.temp_file "buck_targets_" ".txt" in + let write_args outc = Out_channel.output_string outc (String.concat ~sep:"\n" buck_targets) in + Utils.with_file_out file ~f:write_args |> ignore ; + L.(debug Capture Quiet) "Buck targets options stored in file %s@\n" file ; + Printf.sprintf "@%s" file + (** Computes the compilation database files. *) let get_compilation_database_files_buck ~prog ~args = - let args = + let targets, no_targets = List.partition_tf ~f:Buck.is_target_string args in + let targets = match Config.buck_compilation_database with | Some `Deps - -> let targets, no_targets = Buck.get_dependency_targets args in - no_targets @ targets + -> Buck.get_dependency_targets_and_add_flavors targets | _ - -> args + -> Buck.add_flavors_to_buck_command targets in - match Buck.add_flavors_to_buck_command args with - | build :: args_with_flavor + match no_targets with + | "build" :: _ -> ( - let build_args = build :: "--config" :: "*//cxx.pch_enabled=false" :: args_with_flavor in + let targets_in_file = buck_targets_in_file targets in + let build_args = no_targets @ ["--config"; "*//cxx.pch_enabled=false"; targets_in_file] in Process.create_process_and_wait ~prog ~args:build_args ; - (* The option --keep-going is not accepted in the command buck targets *) - let args_with_flavor_no_keep_going = - List.filter ~f:(fun s -> not (String.equal s "--keep-going")) args_with_flavor - in let buck_targets_shell = - prog :: "targets" :: "--show-output" :: args_with_flavor_no_keep_going - |> Utils.shell_escape_command + [prog; "targets"; "--show-output"; targets_in_file] |> Utils.shell_escape_command in let output, exit_or_signal = Utils.with_process_in buck_targets_shell In_channel.input_lines