[buck] store query args in argument file

Summary:
Avoid command-line-too-long for queries where the query expression itself is overly long.

Also, require the temporary filename prefix to ease debugging.

Reviewed By: jvillard

Differential Revision: D25495343

fbshipit-source-id: 0483aac2d
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 731b632632
commit 72a59553d2

@ -9,6 +9,26 @@ open! IStd
module F = Format
module L = Logging
let max_command_line_length = 50
let store_args_in_file ~identifier args =
let rec exceed_length ~max = function
| _ when max < 0 ->
true
| [] ->
false
| h :: t ->
exceed_length ~max:(max - String.length h) t
in
if exceed_length ~max:max_command_line_length args then (
let file = Filename.temp_file ~in_dir:(ResultsDir.get_path Temporary) identifier ".txt" in
let write_args outc = Out_channel.output_string outc (String.concat ~sep:"\n" args) in
Utils.with_file_out file ~f:write_args ;
L.debug Capture Quiet "Buck targets options stored in file '%s'@\n" file ;
[Printf.sprintf "@%s" file] )
else args
(** Wrap a call to buck while (i) logging standard error to our standard error in real time; (ii)
redirecting standard out to a file, the contents of which are returned; (iii) protect the child
process from [SIGQUIT].
@ -272,10 +292,10 @@ module Query = struct
| _ ->
[]
in
let cmd =
("buck" :: "query" :: buck_config)
@ List.rev_append Config.buck_build_args_no_inline (query :: buck_output_options)
let bounded_args =
store_args_in_file ~identifier:"buck_query_args" (buck_config @ buck_output_options @ [query])
in
let cmd = ["buck"; "query"] @ Config.buck_build_args_no_inline @ bounded_args in
wrap_buck_call ~label:"query" cmd |> parse_query_output ?buck_mode
end
@ -312,8 +332,6 @@ let get_accepted_buck_kinds_pattern (mode : BuckMode.t) =
"^(java|android)_library$"
let max_command_line_length = 50
(** for genrule_master_mode, this is the label expected on the capture genrules *)
let infer_enabled_label = "infer_enabled"
@ -480,25 +498,6 @@ let parse_command_and_targets (buck_mode : BuckMode.t) original_buck_args =
(command, parsed_args.rev_not_targets', targets)
let rec exceed_length ~max = function
| _ when max < 0 ->
true
| [] ->
false
| h :: t ->
exceed_length ~max:(max - String.length h) t
let store_args_in_file args =
if exceed_length ~max:max_command_line_length args then (
let file = Filename.temp_file ~in_dir:(ResultsDir.get_path Temporary) "buck_targets" ".txt" in
let write_args outc = Out_channel.output_string outc (String.concat ~sep:"\n" args) in
let () = Utils.with_file_out file ~f:write_args in
L.(debug Capture Quiet) "Buck targets options stored in file '%s'@\n" file ;
[Printf.sprintf "@%s" file] )
else args
let filter_compatible subcommand args =
match subcommand with
| `Targets ->

@ -38,8 +38,9 @@ val parse_command_and_targets : BuckMode.t -> string list -> string * string lis
(** parses given buck command, using the buck configuration returned by [config] above and returns a
triple [(buck_command, non_target_params, target_params)] *)
val store_args_in_file : string list -> string list
(** Given a list of arguments, stores them in a file if needed and returns the new command line *)
val store_args_in_file : identifier:string -> string list -> string list
(** Given a list of arguments, stores them in a file if needed and returns the new command line ;
[identifier] is the temporary filename prefix *)
val filter_compatible : [> `Targets] -> string list -> string list
(** keep only the options compatible with the given Buck subcommand *)

@ -114,7 +114,9 @@ let capture build_cmd =
else
let all_args = List.rev_append rev_not_targets targets in
let updated_buck_cmd =
command :: List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args)
command
:: List.rev_append Config.buck_build_args_no_inline
(Buck.store_args_in_file ~identifier:"clang_flavor_build" all_args)
in
L.debug Capture Quiet "Processed buck command '%a'@\n" (Pp.seq F.pp_print_string)
updated_buck_cmd ;

@ -170,7 +170,8 @@ let capture buck_mode build_cmd =
let updated_buck_cmd =
(* make buck tell us where in buck-out are the capture directories for merging *)
(prog :: command :: "--build-report" :: build_report_file :: Buck.config buck_mode)
@ List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args)
@ List.rev_append Config.buck_build_args_no_inline
(Buck.store_args_in_file ~identifier:"genrule_build" all_args)
in
L.(debug Capture Quiet)
"Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ;

@ -25,7 +25,8 @@ let capture build_cmd =
let updated_buck_cmd =
(* make buck tell us where in buck-out are the capture directories for merging *)
(prog :: command :: "--build-report" :: build_report_file :: Buck.config JavaFlavor)
@ List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args)
@ List.rev_append Config.buck_build_args_no_inline
(Buck.store_args_in_file ~identifier:"java_flavor_build" all_args)
in
L.(debug Capture Quiet)
"Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ;

@ -81,7 +81,7 @@ let get_compilation_database_files_buck db_deps ~prog ~args =
L.external_warning "WARNING: found no buck targets to analyze.@." ;
[]
| {command= "build" as command; rev_not_targets; targets} ->
let targets_args = Buck.store_args_in_file targets in
let targets_args = Buck.store_args_in_file ~identifier:"compdb_build_args" targets in
let build_args =
(command :: List.rev_append rev_not_targets (List.rev Config.buck_build_args_no_inline))
@ (* Infer doesn't support C++ modules nor precompiled headers yet (T35656509) *)

Loading…
Cancel
Save