[buck integration] Pass targets to buck in a file

Reviewed By: jvillard

Differential Revision: D5601861

fbshipit-source-id: fecd094
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 3a7d50e15b
commit cb4cf39d49

@ -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 ; if not found_one_target then no_targets_found_error_and_exit build_cmd ;
cmd' cmd'
let call_buck_query_for_dependencies targets = let get_dependency_targets_and_add_flavors targets =
let build_deps_string targets = let build_deps_string targets =
List.map targets ~f:(fun target -> Printf.sprintf "deps('%s')" target) List.map targets ~f:(fun target -> Printf.sprintf "deps('%s')" target)
|> String.concat ~sep:" union " |> String.concat ~sep:" union "
@ -82,9 +82,5 @@ let call_buck_query_for_dependencies targets =
"*** command failed:@\n*** %s@\n*** %s@." buck_query_cmd "*** command failed:@\n*** %s@\n*** %s@." buck_query_cmd
(Unix.Exit_or_signal.to_string_hum status) (Unix.Exit_or_signal.to_string_hum status)
| Ok () | Ok ()
-> List.map ~f:(fun name -> string_of_target {name; flavors= Config.append_buck_flavors}) output -> List.map output ~f:(fun name ->
string_of_target (add_flavor_to_target {name; flavors= Config.append_buck_flavors}) )
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)

@ -23,6 +23,6 @@ val add_flavors_to_buck_command : string list -> string list
buck build //foo/bar:baz#infer-capture-all,some,flavor 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 (** Runs buck query to get the dependency targets of the given targets
[get_dependency_targets args] = targets with dependent targets, other args *) [get_dependency_targets args] = targets with dependent targets, other args *)

@ -64,28 +64,31 @@ let run_compilation_database compilation_database should_capture_file =
Process.run_jobs_in_parallel ~fail_on_failed_job jobs_stack Process.run_jobs_in_parallel ~fail_on_failed_job jobs_stack
(run_compilation_file compilation_database) job_to_string (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. *) (** Computes the compilation database files. *)
let get_compilation_database_files_buck ~prog ~args = 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 match Config.buck_compilation_database with
| Some `Deps | Some `Deps
-> let targets, no_targets = Buck.get_dependency_targets args in -> Buck.get_dependency_targets_and_add_flavors targets
no_targets @ targets
| _ | _
-> args -> Buck.add_flavors_to_buck_command targets
in in
match Buck.add_flavors_to_buck_command args with match no_targets with
| build :: args_with_flavor | "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 ; 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 = let buck_targets_shell =
prog :: "targets" :: "--show-output" :: args_with_flavor_no_keep_going [prog; "targets"; "--show-output"; targets_in_file] |> Utils.shell_escape_command
|> Utils.shell_escape_command
in in
let output, exit_or_signal = let output, exit_or_signal =
Utils.with_process_in buck_targets_shell In_channel.input_lines Utils.with_process_in buck_targets_shell In_channel.input_lines

Loading…
Cancel
Save