[buck integration] Implement a way of getting the compilation database for dependencies of given targets

Reviewed By: jvillard

Differential Revision: D5553327

fbshipit-source-id: 4d03ae7
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent de86c12a9a
commit 76629ee9a4

@ -42,9 +42,7 @@ let add_flavor_to_target target =
else {target with flavors= flavor :: target.flavors}
in
match (Config.buck_compilation_database, Config.analyzer) with
| Some `Deps, _
-> add "uber-compilation-database"
| Some `NoDeps, _
| Some _, _
-> add "compilation-database"
| None, CompileOnly
-> target
@ -64,3 +62,29 @@ let add_flavors_to_buck_command build_cmd =
in
if not found_one_target then no_targets_found_error_and_exit build_cmd ;
cmd'
let call_buck_query_for_dependencies targets =
let build_deps_string targets =
List.map targets ~f:(fun target -> Printf.sprintf "deps('%s')" target)
|> String.concat ~sep:" union "
in
let buck_query =
[ "buck"
; "query"
; ( "\"kind('(apple_binary|apple_library|apple_test|cxx_binary|cxx_library|cxx_test)', "
^ build_deps_string targets ^ ")\"" ) ]
in
let buck_query_cmd = String.concat buck_query ~sep:" " in
let output, exit_or_signal = Utils.with_process_in buck_query_cmd In_channel.input_lines in
match exit_or_signal with
| Error _ as status
-> Logging.(die ExternalError)
"*** command failed:@\n*** %s@\n*** %s@." buck_query_cmd
(Unix.Exit_or_signal.to_string_hum status)
| Ok ()
-> 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)

@ -22,3 +22,7 @@ val add_flavors_to_buck_command : string list -> string list
becomes:
buck build //foo/bar:baz#infer-capture-all,some,flavor
*)
val get_dependency_targets : string list -> 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 *)

@ -66,6 +66,14 @@ let run_compilation_database compilation_database should_capture_file =
(** Computes the compilation database files. *)
let get_compilation_database_files_buck ~prog ~args =
let args =
match Config.buck_compilation_database with
| Some `Deps
-> let targets, no_targets = Buck.get_dependency_targets args in
no_targets @ targets
| _
-> args
in
match Buck.add_flavors_to_buck_command args with
| build :: args_with_flavor
-> (

Loading…
Cancel
Save