[buck integration] Add a dependency depth option

Reviewed By: jvillard

Differential Revision: D5611184

fbshipit-source-id: 5c88e29
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 79105952d6
commit 3589773bf7

@ -79,6 +79,13 @@ let issues_fields_symbols =
type os_type = Unix | Win32 | Cygwin type os_type = Unix | Win32 | Cygwin
type compilation_database_dependencies =
| Deps of int option
(* get the compilation database of the dependencies up to depth n
by [Deps (Some n)], or all by [Deps None] *)
| NoDeps
[@@deriving compare]
(** Constant configuration values *) (** Constant configuration values *)
let anonymous_block_num_sep = "______" let anonymous_block_num_sep = "______"
@ -725,11 +732,17 @@ and buck_build_args =
~in_help:CLOpt.([(Capture, manual_buck_flavors)]) ~in_help:CLOpt.([(Capture, manual_buck_flavors)])
"Pass values as command-line arguments to invocations of $(i,`buck build`)" "Pass values as command-line arguments to invocations of $(i,`buck build`)"
and buck_compilation_database_depth =
CLOpt.mk_int_opt ~long:"buck-compilation-database-depth"
~in_help:CLOpt.([(Capture, manual_buck_compilation_db)])
"Depth of dependencies used by the $(b,--buck-compilation-database deps) option. By default, all recursive dependencies are captured."
~meta:"int"
and buck_compilation_database = and buck_compilation_database =
CLOpt.mk_symbol_opt ~long:"buck-compilation-database" ~deprecated:["-use-compilation-database"] CLOpt.mk_symbol_opt ~long:"buck-compilation-database" ~deprecated:["-use-compilation-database"]
~in_help:CLOpt.([(Capture, manual_buck_compilation_db)]) ~in_help:CLOpt.([(Capture, manual_buck_compilation_db)])
"Buck integration using the compilation database, with or without dependencies." "Buck integration using the compilation database, with or without dependencies."
~symbols:[("deps", `Deps); ("no-deps", `NoDeps)] ~symbols:[("no-deps", `NoDeps); ("deps", `DepsTmp)]
and buck_out = and buck_out =
CLOpt.mk_path_opt ~long:"buck-out" CLOpt.mk_path_opt ~long:"buck-out"
@ -1878,7 +1891,14 @@ and buck_build_args = !buck_build_args
and buck_cache_mode = !buck && not !debug and buck_cache_mode = !buck && not !debug
and buck_compilation_database = !buck_compilation_database and buck_compilation_database =
match !buck_compilation_database with
| Some `DepsTmp
-> Some (Deps !buck_compilation_database_depth)
| Some `NoDeps
-> Some NoDeps
| None
-> None
and buck_out = !buck_out and buck_out = !buck_out

@ -64,6 +64,13 @@ val issues_fields_symbols :
type os_type = Unix | Win32 | Cygwin type os_type = Unix | Win32 | Cygwin
type compilation_database_dependencies =
| Deps of int option
(** get the compilation database of the dependencies up to depth n
by [Deps (Some n)], or all by [Deps None] *)
| NoDeps
[@@deriving compare]
type dynamic_dispatch_policy = [`None | `Interface | `Sound | `Lazy] type dynamic_dispatch_policy = [`None | `Interface | `Sound | `Lazy]
val env_inside_maven : Unix.env val env_inside_maven : Unix.env
@ -282,7 +289,7 @@ val buck_build_args : string list
val buck_cache_mode : bool val buck_cache_mode : bool
val buck_compilation_database : [`Deps | `NoDeps] option val buck_compilation_database : compilation_database_dependencies option
val buck_out : string option val buck_out : string option

@ -63,9 +63,14 @@ 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 get_dependency_targets_and_add_flavors targets = let get_dependency_targets_and_add_flavors targets ~depth =
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 ->
match depth with
| None (* full depth *)
-> Printf.sprintf "deps('%s')" target
| Some n
-> Printf.sprintf "deps('%s', %d)" target n )
|> String.concat ~sep:" union " |> String.concat ~sep:" union "
in in
let buck_query = let buck_query =
@ -75,6 +80,7 @@ let get_dependency_targets_and_add_flavors targets =
^ build_deps_string targets ^ ")\"" ) ] ^ build_deps_string targets ^ ")\"" ) ]
in in
let buck_query_cmd = String.concat buck_query ~sep:" " in let buck_query_cmd = String.concat buck_query ~sep:" " in
Logging.(debug Linters Medium) "*** Executing command:@\n*** %s@." buck_query_cmd ;
let output, exit_or_signal = Utils.with_process_in buck_query_cmd In_channel.input_lines in let output, exit_or_signal = Utils.with_process_in buck_query_cmd In_channel.input_lines in
match exit_or_signal with match exit_or_signal with
| Error _ as status | Error _ as status

@ -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_and_add_flavors : string list -> string list val get_dependency_targets_and_add_flavors : string list -> depth:int option -> 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 *)

@ -56,7 +56,7 @@ let run_compilation_database compilation_database should_capture_file =
if Config.linters_ignore_clang_failures then false if Config.linters_ignore_clang_failures then false
else else
match Config.buck_compilation_database with match Config.buck_compilation_database with
| Some `NoDeps | Some NoDeps
-> Config.clang_frontend_do_lint -> Config.clang_frontend_do_lint
| _ | _
-> false -> false
@ -76,8 +76,8 @@ let get_compilation_database_files_buck ~prog ~args =
let targets, no_targets = List.partition_tf ~f:Buck.is_target_string args in let targets, no_targets = List.partition_tf ~f:Buck.is_target_string args in
let targets = let targets =
match Config.buck_compilation_database with match Config.buck_compilation_database with
| Some `Deps | Some Deps depth
-> Buck.get_dependency_targets_and_add_flavors targets -> Buck.get_dependency_targets_and_add_flavors targets ~depth
| _ | _
-> Buck.add_flavors_to_buck_command targets -> Buck.add_flavors_to_buck_command targets
in in

Loading…
Cancel
Save