@ -59,23 +59,37 @@ let compile compiler build_prog build_args =
file in
let cli_file_args = cli_args @ [ " @ " ^ args_file ] in
let args = prog_args @ cli_file_args in
L . out " Current working directory: '%s'@. " ( Sys . getcwd () ) ;
let verbose_out_file = Filename . temp_file " javac_ " " .out " in
Unix . with_file verbose_out_file ~ mode : [ Unix . O_WRONLY ] ~ f : (
fun verbose_out_fd ->
L . out " Logging into %s@ \n " verbose_out_file ;
L . out " Current working directory: '%s'@. " ( Sys . getcwd () ) ;
try
L . out " Trying to execute: '%s' '%s'@. " prog ( String . concat ~ sep : " ' ' " args ) ;
Unix_ . fork_redirect_exec_wait ~ prog ~ args ~ stderr : verbose_out_fd ()
with exn ->
try
L . out " *** Failed!@ \n Trying to execute javac instead: '%s' '%s'@ \n Logging into %s@. "
" javac " ( String . concat ~ sep : " ' ' " cli_file_args ) verbose_out_file ;
Unix_ . fork_redirect_exec_wait ~ prog : " javac " ~ args : cli_file_args ~ stderr : verbose_out_fd ()
with _ ->
L . stderr " Failed to execute: %s %s@. " prog ( String . concat ~ sep : " " args ) ;
raise exn
) ;
let try_run cmd error_k =
let shell_cmd = Utils . shell_escape_command cmd in
let shell_cmd_redirected =
Printf . sprintf " %s 2>'%s' " shell_cmd verbose_out_file in
L . out " Trying to execute: %s@. " shell_cmd_redirected ;
let error_k_or_fail err_msg =
match error_k , err_msg with
| Some k , ( ` UnixError ( err , log ) ) ->
L . out " *** Failed: %s!@ \n %s@. " ( Unix . Exit_or_signal . to_string_hum ( Error err ) ) log ;
k ()
| Some k , ( ` ExceptionError exn ) ->
L . out " *** Failed: %a!@ \n " Exn . pp exn ;
k ()
| None , ( ` UnixError ( err , log ) ) ->
let verbose_errlog = Utils . with_file_in verbose_out_file ~ f : In_channel . input_all in
failwithf " @ \n *** ERROR Failed to execute compilation command: %s@ \n *** Command: %s@ \n \
* * * Output : @ \ n % s % s @ \ n * * * Infer needs a working compilation command to run . @. "
( Unix . Exit_or_signal . to_string_hum ( Error err ) ) shell_cmd log verbose_errlog ;
| None , ( ` ExceptionError exn ) ->
raise exn in
match Utils . with_process_in shell_cmd_redirected In_channel . input_all with
| ( log , Error err ) ->
error_k_or_fail ( ` UnixError ( err , log ) )
| exception exn ->
error_k_or_fail ( ` ExceptionError exn )
| ( log , Ok () ) ->
L . out " *** Success. Logs:@ \n %s " log in
let fallback () = try_run ( " javac " :: cli_file_args ) None in
try_run ( prog :: args ) ( Some fallback ) ;
verbose_out_file