@ -83,13 +83,6 @@ type mode =
let equal_mode = [ % compare . equal : mode ]
let pp_mode fmt mode =
let log_argfile_arg fname =
try
F . fprintf fmt " -- Contents of '%s'@ \n " fname ;
In_channel . iter_lines ~ f : ( F . fprintf fmt " %s@ \n " ) ( In_channel . create fname ) ;
F . fprintf fmt " -- /Contents of '%s'@. " fname
with exn -> F . fprintf fmt " Error reading file '%s':@ \n %a@. " fname Exn . pp exn
in
match mode with
| Analyze
| BuckGenrule _
@ -101,23 +94,11 @@ let pp_mode fmt mode =
-> (* these are pretty boring, do not log anything *)
()
| Javac ( _ , prog , args )
-> F . fprintf fmt " Javac driver mode:@ \n prog = %s@ \n " prog ;
let log_arg arg =
F . fprintf fmt " Arg: %s@ \n " arg ;
(* "@fname" means that fname is an arg file containing additional arguments to pass to
javac . * )
String . chop_prefix ~ prefix : " @ " arg
| > (* Sometimes these argfiles go away at the end of the build and we cannot inspect them after
the fact , so log them now . * )
Option . iter ~ f : log_argfile_arg
in
List . iter ~ f : log_arg args
-> F . fprintf fmt " Javac driver mode:@ \n prog = %s@ \n args = %a " prog Pp . cli_args args
| Maven ( prog , args )
-> F . fprintf fmt " Maven driver mode:@ \n prog = %s@ \n " prog ;
List . iter ~ f : ( F . fprintf fmt " Arg: %s@ \n " ) args
-> F . fprintf fmt " Maven driver mode:@ \n prog = %s@ \n args = %a " prog Pp . cli_args args
| Clang ( _ , prog , args )
-> F . fprintf fmt " Clang driver mode:@ \n prog = %s@ \n " prog ;
List . iter ~ f : ( F . fprintf fmt " Arg: %s@ \n " ) args
-> F . fprintf fmt " Clang driver mode:@ \n prog = %s@ \n args = %a " prog Pp . cli_args args
(* A clean command for each driver mode to be suggested to the user
in case nothing got captured . * )
@ -254,7 +235,8 @@ let capture_with_compilation_database db_files =
let compilation_database = CompilationDatabase . from_json_files db_files in
CaptureCompilationDatabase . capture_files_in_database compilation_database
let capture ~ changed_files = function
let capture ~ changed_files mode =
match mode with
| Analyze
-> ()
| BuckCompilationDB ( prog , args )
@ -264,12 +246,14 @@ let capture ~changed_files = function
| BuckGenrule path
-> L . progress " Capturing for Buck genrule compatibility...@. " ; JMain . from_arguments path
| Clang ( compiler , prog , args )
-> L . progress " Capturing in make/cc mode...@. " ; Clang . capture compiler ~ prog ~ args
-> if CLOpt . is_originator then L . progress " Capturing in make/cc mode...@. " ;
Clang . capture compiler ~ prog ~ args
| ClangCompilationDB db_files
-> L . progress " Capturing using compilation database...@. " ;
capture_with_compilation_database ~ changed_files db_files
| Javac ( compiler , prog , args )
-> L . progress " Capturing in javac mode...@. " ; Javac . capture compiler ~ prog ~ args
-> if CLOpt . is_originator then L . progress " Capturing in javac mode...@. " ;
Javac . capture compiler ~ prog ~ args
| Maven ( prog , args )
-> L . progress " Capturing in maven mode...@. " ; Maven . capture ~ prog ~ args
| Python args
@ -424,8 +408,8 @@ let analyze_and_report ?suppress_console_report ~changed_files mode =
| PythonCapture ( BBuck , _ ) , _ when not Config . flavors
-> (* In Buck mode when compilation db is not used, analysis is invoked from capture if buck flavors are not used *)
( false , false )
| _ when Config . maven
-> (* Called from Maven, only do capture . *)
| _ when Config . infer_is_clang | | Config . infer_is_javac
-> (* Called from another integration to do capture only . *)
( false , false )
| _ , ( CaptureOnly | CompileOnly )
-> ( false , false )
@ -461,15 +445,6 @@ let fail_on_issue_epilogue () =
| Error error
-> L . internal_error " Failed to read report file '%s': %s@. " issues_json error ; ()
let log_infer_args mode =
L . environment_info " INFER_ARGS = %s@ \n "
( Option . value ( Sys . getenv CLOpt . args_env_var ) ~ default : " <not found> " ) ;
List . iter ~ f : ( L . environment_info " anon arg: %s@ \n " ) Config . anon_args ;
List . iter ~ f : ( L . environment_info " rest arg: %s@ \n " ) Config . rest ;
L . environment_info " Project root = %s@ \n " Config . project_root ;
L . environment_info " CWD = %s@ \n " ( Sys . getcwd () ) ;
L . environment_info " Driver mode:@ \n %a@. " pp_mode mode
let assert_supported_mode required_analyzer requested_mode_string =
let analyzer_enabled =
match required_analyzer with
@ -560,9 +535,14 @@ let mode_of_build_command build_cmd =
let mode_from_command_line =
( lazy
( match Config . generated_classes with
| _ when Config . maven
-> (* infer is pretending to be javac in the Maven integration *)
let build_args = match Array . to_list Sys . argv with _ :: args -> args | [] -> [] in
| _ when Config . infer_is_clang
-> let prog , args =
match Array . to_list Sys . argv with prog :: args -> ( prog , args ) | [] -> assert false
(* Sys.argv is never empty *)
in
Clang ( Clang . Clang , prog , args )
| _ when Config . infer_is_javac
-> let build_args = match Array . to_list Sys . argv with _ :: args -> args | [] -> [] in
Javac ( Javac . Javac , " javac " , build_args )
| Some path
-> assert_supported_mode ` Java " Buck genrule " ;
@ -572,7 +552,8 @@ let mode_from_command_line =
let run_prologue mode =
if CLOpt . is_originator then L . environment_info " %a@ \n " Config . pp_version () ;
if Config . debug_mode | | Config . stats_mode then log_infer_args mode ;
if Config . debug_mode | | Config . stats_mode then
L . environment_info " Driver mode:@ \n %a@. " pp_mode mode ;
if Config . dump_duplicate_symbols then reset_duplicates_file () ;
(* infer might be called from a Makefile and itself uses `make` to run the analysis in parallel,
but cannot communicate with the parent make command . Since infer won't interfere with them
@ -580,7 +561,8 @@ let run_prologue mode =
mono - threaded execution . * )
Unix . unsetenv " MAKEFLAGS " ;
register_perf_stats_report () ;
if not Config . buck_cache_mode then touch_start_file_unless_continue () ;
if not Config . buck_cache_mode && not Config . infer_is_clang && not Config . infer_is_javac then
touch_start_file_unless_continue () ;
()
let run_epilogue mode =