From 86cb2f4938edb5ca0e893af2c30706dba2aae1ce Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 18 Nov 2016 09:58:49 -0800 Subject: [PATCH] [toplevel] fix various things Summary: - fix python calling function with wrong number of arguments (sic) - print legend of analysis output, this was lost in translation ('F', '.', ...) - add "Capturing in mode..." message before capture - remove version from "Analyzing..." message (users don't even paste the full output, so this is not as useful as initially hoped) Reviewed By: akotulski Differential Revision: D4205072 fbshipit-source-id: 2b6505c --- infer/lib/python/inferlib/capture/buck.py | 4 ++-- infer/src/backend/InferAnalyze.re | 21 ++++++++++++++++ infer/src/backend/InferAnalyze.rei | 4 ++++ infer/src/backend/InferAnalyzeExe.re | 20 +--------------- infer/src/backend/InferPrint.re | 2 -- infer/src/backend/PerfStats.ml | 1 + infer/src/backend/infer.ml | 29 +++++++++++++++++++---- 7 files changed, 54 insertions(+), 27 deletions(-) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 590ae14de..d7d12a6f9 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -202,8 +202,8 @@ class BuckAnalyzer: infer_out = self.args.infer_out json_report = os.path.join(infer_out, config.JSON_REPORT_FILENAME) bugs_out = os.path.join(infer_out, config.BUGS_FILENAME) - issues.print_and_save_errors(self.args.project_root, json_report, - bugs_out, self.args.pmd_xml) + issues.print_and_save_errors(infer_out, self.args.project_root, + json_report, bugs_out, self.args.pmd_xml) return os.EX_OK def capture_without_flavors(self): diff --git a/infer/src/backend/InferAnalyze.re b/infer/src/backend/InferAnalyze.re index 4c3de883e..fb0792433 100644 --- a/infer/src/backend/InferAnalyze.re +++ b/infer/src/backend/InferAnalyze.re @@ -71,6 +71,27 @@ let process_cluster_cmdline fname => | Some (nr, cluster) => analyze_cluster (nr - 1) cluster }; +let print_stdout_legend () => { + L.stdout "Starting analysis...@\n"; + L.stdout "@\n"; + L.stdout "legend:@\n"; + L.stdout " \"%s\" analyzing a file@\n" Config.log_analysis_file; + L.stdout " \"%s\" analyzing a procedure@\n" Config.log_analysis_procedure; + if Config.stats_mode { + L.stdout " \"%s\" analyzer crashed@\n" Config.log_analysis_crash; + L.stdout + " \"%s\" timeout: procedure analysis took too much time@\n" + Config.log_analysis_wallclock_timeout; + L.stdout + " \"%s\" timeout: procedure analysis took too many symbolic execution steps@\n" + Config.log_analysis_symops_timeout; + L.stdout + " \"%s\" timeout: procedure analysis took too many recursive iterations@\n" + Config.log_analysis_recursion_timeout + }; + L.stdout "@\n@?" +}; + let main makefile => { switch Config.modified_targets { | Some file => MergeCapture.modified_file file diff --git a/infer/src/backend/InferAnalyze.rei b/infer/src/backend/InferAnalyze.rei index f57081cf2..15bc62e63 100644 --- a/infer/src/backend/InferAnalyze.rei +++ b/infer/src/backend/InferAnalyze.rei @@ -12,5 +12,9 @@ open! Utils; /** Main module for the analysis after the capture phase */ +/** print the legend for the symbols on stdout ('F', '.', ...) */ +let print_stdout_legend: unit => unit; + + /** Given a name of the Makefile to use for multicore analysis, analyze the captured code */ let main: string => unit; diff --git a/infer/src/backend/InferAnalyzeExe.re b/infer/src/backend/InferAnalyzeExe.re index 6818de5ec..4589c7414 100644 --- a/infer/src/backend/InferAnalyzeExe.re +++ b/infer/src/backend/InferAnalyzeExe.re @@ -28,25 +28,7 @@ let register_perf_stats_report () => { let print_prolog () => switch Config.cluster_cmdline { - | None => - L.stdout "Starting analysis (Infer version %s)@\n" Version.versionString; - L.stdout "@\n"; - L.stdout "legend:@\n"; - L.stdout " \"%s\" analyzing a file@\n" Config.log_analysis_file; - L.stdout " \"%s\" analyzing a procedure@\n" Config.log_analysis_procedure; - if Config.stats_mode { - L.stdout " \"%s\" analyzer crashed@\n" Config.log_analysis_crash; - L.stdout - " \"%s\" timeout: procedure analysis took too much time@\n" - Config.log_analysis_wallclock_timeout; - L.stdout - " \"%s\" timeout: procedure analysis took too many symbolic execution steps@\n" - Config.log_analysis_symops_timeout; - L.stdout - " \"%s\" timeout: procedure analysis took too many recursive iterations@\n" - Config.log_analysis_recursion_timeout - }; - L.stdout "@\n@?" + | None => InferAnalyze.print_stdout_legend () | Some clname => L.stdout "Cluster %s@." clname }; diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 85ea620ec..8c5c84649 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -1381,8 +1381,6 @@ let compute_top_procedures = ref false; let register_perf_stats_report () => { let stats_dir = Filename.concat Config.results_dir Config.reporting_stats_dir_name; let stats_file = Filename.concat stats_dir (Config.perf_stats_prefix ^ ".json"); - create_dir Config.results_dir; - create_dir stats_dir; PerfStats.register_report_at_exit stats_file }; diff --git a/infer/src/backend/PerfStats.ml b/infer/src/backend/PerfStats.ml index 03301bd00..6d3be385f 100644 --- a/infer/src/backend/PerfStats.ml +++ b/infer/src/backend/PerfStats.ml @@ -146,6 +146,7 @@ let register_report_at_exit file = try let json_stats = to_json (stats ()) in try + create_path (Filename.dirname file); let stats_oc = open_out file in Yojson.Basic.pretty_to_channel stats_oc json_stats ; close_out stats_oc diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 96459d3cb..68124adf4 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -56,6 +56,18 @@ let build_mode_of_string path = | "xcodebuild" -> Xcode | cmd -> failwithf "Unsupported build command %s" cmd +let string_of_build_mode = function + | Analyze -> "analyze" + | Ant -> "ant" + | Buck -> "buck" + | ClangCompilationDatabase -> "clang-compilation-database" + | Gradle -> "gradle" + | Java -> "java" + | Javac -> "javac" + | Make -> "make/cc" + | Mvn -> "maven" + | Ndk -> "ndk-build" + | Xcode -> "xcodebuild" let remove_results_dir () = rmtree Config.results_dir @@ -118,7 +130,7 @@ let run_command cmd_list after_wait = let exit_code = match status with Unix.WEXITED i -> i | _ -> 1 in after_wait exit_code ; if exit_code <> 0 then ( - L.err "Failed to execute: %s@\n" (String.concat " " cmd_list) ; + L.do_err "Failed to execute: %s@\n" (String.concat " " cmd_list) ; exit exit_code ) @@ -140,9 +152,11 @@ let capture build_cmd = function | Analyze -> () | Buck when Config.use_compilation_database <> None -> + L.stdout "Capturing using Buck's compilation database...@\n"; let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck () in CaptureCompilationDatabase.capture_files_in_database json_cdb | ClangCompilationDatabase -> ( + L.stdout "Capturing using a compilation database file...@\n"; match Config.rest with | arg :: _ -> CaptureCompilationDatabase.capture_files_in_database [arg] | _ -> @@ -152,10 +166,12 @@ let capture build_cmd = function Config.print_usage_exit () ) | Xcode when Config.xcpretty -> + L.stdout "Capturing using xcpretty...@\n"; check_xcpretty (); let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_xcodebuild () in CaptureCompilationDatabase.capture_files_in_database json_cdb | build_mode -> + L.stdout "Capturing in %s mode...@." (string_of_build_mode build_mode); let in_buck_mode = build_mode = Buck in let infer_py = Config.lib_dir // "python" // "infer.py" in run_command ( @@ -207,6 +223,7 @@ let run_parallel_analysis () = let multicore_dir = Config.results_dir // Config.multicore_dir_name in rmtree multicore_dir ; create_path multicore_dir ; + InferAnalyze.print_stdout_legend (); InferAnalyze.main (multicore_dir // "Makefile") ; let cwd = Unix.getcwd () in Unix.chdir multicore_dir ; @@ -244,7 +261,11 @@ let report () = "--project-root"; Config.project_root; "--results-dir"; Config.results_dir ] in - Unix.waitpid (Unix.fork_exec ~prog ~args:(prog :: args) ()) |> ignore + match (Unix.waitpid (Unix.fork_exec ~prog ~args:(prog :: args) ())) with + | Result.Ok _ -> () + | Result.Error _ -> + L.stderr "** Error running the reporting script:@\n** %s %s@\n** See error above@." + prog (String.concat ~sep:" " args) let analyze = function | Buck when Config.use_compilation_database = None -> @@ -256,7 +277,7 @@ let analyze = function () | Analyze | Ant | Buck | ClangCompilationDatabase | Gradle | Make | Mvn | Ndk | Xcode -> if not (Sys.file_exists Config.(results_dir // captured_dir_name)) then ( - L.err "There was nothing to analyze, exiting" ; + L.stderr "There was nothing to analyze, exiting" ; Config.print_usage_exit () ); (match Config.analyzer with @@ -287,7 +308,7 @@ let () = create_results_dir () ; (* re-set log files, as default files were in results_dir removed above *) L.set_log_file_identifier Config.current_exe (Some (CLOpt.exe_name Config.current_exe)) ; - if Config.is_originator then L.out "%s@\n" Config.version_string ; + if Config.is_originator then L.do_out "%s@\n" Config.version_string ; register_perf_stats_report () ; touch_start_file () ; capture build_cmd build_mode ;