[java integration] use argfile when trying to store a lot of data in the environment

Reviewed By: jeremydubreil

Differential Revision: D5454536

fbshipit-source-id: 05a4e75
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 03120a337e
commit 58a7cc48c1

@ -826,14 +826,20 @@ let parse ?config_file ~usage action initial_command =
let curr_usage = parse_args ~usage action ?initial_command cl_args in let curr_usage = parse_args ~usage action ?initial_command cl_args in
add_parsed_args_to_args_to_export () ; curr_usage add_parsed_args_to_args_to_export () ; curr_usage
in in
(* we have to be careful not to add too much data to the environment because the size of the let to_export =
environment contributes to the length of the command to be run. if the environment + CLI is too (* We have to be careful not to add too much data to the environment because the size of the
big, running any command will fail with a cryptic "exit code 127" error. here, we hack around the environment contributes to the length of the command to be run. If the environment + CLI is
issue by refusing to add a string to the environment if it's sufficiently big (and praying that too big, running any command will fail with a cryptic "exit code 127" error. Use an argfile
this won't make the command fail). TODO (t20145863): use argfiles here *) to prevent this from happening *)
if List.is_empty !extra_env_args || String.length !args_to_export < 100000 then let file = Filename.temp_file "args_" "" in
Unix.putenv ~key:args_env_var ~data:!args_to_export ; let quoted_file_args =
(!curr_command, curr_usage) List.map (decode_env_to_argv !args_to_export) ~f:(fun arg ->
if String.contains arg '\'' then arg else F.sprintf "'%s'" arg )
in
Out_channel.with_file file ~f:(fun oc -> Out_channel.output_lines oc quoted_file_args) ;
"@" ^ file
in
Unix.putenv ~key:args_env_var ~data:to_export ; (!curr_command, curr_usage)
let wrap_line indent_string wrap_length line0 = let wrap_line indent_string wrap_length line0 =
let line = indent_string ^ line0 in let line = indent_string ^ line0 in

Loading…
Cancel
Save