From 16010adab4c43114f1ff5f3a01ff634376dbb9ee Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 8 Nov 2016 14:33:57 -0800 Subject: [PATCH] [refactor] InferAnalyze init code to InferAnalyzeExe Summary: Move code that initializes the InferAnalyze executable from InferAnalyze.main to InferAnalyzeExe. This enables InferAnalyze.main to be called from other executables without conflicts due to initialization. Reviewed By: jvillard Differential Revision: D4137280 fbshipit-source-id: 3dd76db --- infer/src/backend/InferAnalyze.re | 60 ++-------------------------- infer/src/backend/InferAnalyze.rei | 2 - infer/src/backend/InferAnalyzeExe.re | 60 +++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/infer/src/backend/InferAnalyze.re b/infer/src/backend/InferAnalyze.re index 386b21370..1a3024931 100644 --- a/infer/src/backend/InferAnalyze.re +++ b/infer/src/backend/InferAnalyze.re @@ -65,77 +65,23 @@ let output_json_makefile_stats clusters => { Yojson.Basic.pretty_to_channel f file_stats }; -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@?" - | Some clname => L.stdout "Cluster %s@." clname - }; - let process_cluster_cmdline fname => switch (Cluster.load_from_file (DB.filename_from_string fname)) { | None => L.err "Cannot find cluster file %s@." fname | Some (nr, cluster) => analyze_cluster (nr - 1) cluster }; -let register_perf_stats_report () => { - let stats_dir = Filename.concat Config.results_dir Config.backend_stats_dir_name; - let cluster = - switch Config.cluster_cmdline { - | Some cl => "_" ^ cl - | None => "" - }; - let stats_base = Config.perf_stats_prefix ^ "_" ^ Filename.basename cluster ^ ".json"; - let stats_file = Filename.concat stats_dir stats_base; - create_dir Config.results_dir; - create_dir stats_dir; - PerfStats.register_report_at_exit stats_file -}; - let main () => { - Logging.set_log_file_identifier - CommandLineOption.Analyze (Option.map Filename.basename Config.cluster_cmdline); - if Config.print_builtins { - Builtin.print_and_exit () - }; switch Config.modified_targets { | Some file => MergeCapture.modified_file file | None => () }; - if (not (Sys.file_exists Config.results_dir)) { - L.err "ERROR: results directory %s does not exist@.@." Config.results_dir; - Config.print_usage_exit () - }; - register_perf_stats_report (); - BuiltinDefn.init (); - if Config.developer_mode { - Printexc.record_backtrace true - }; - print_prolog (); - RegisterCheckers.register (); - if (Config.allow_specs_cleanup == true && Config.cluster_cmdline == None) { - DB.Results_dir.clean_specs_dir () - }; switch Config.cluster_cmdline { | Some fname => process_cluster_cmdline fname | None => + if Config.allow_specs_cleanup { + DB.Results_dir.clean_specs_dir () + }; if Config.merge { MergeCapture.merge_captured_targets () }; diff --git a/infer/src/backend/InferAnalyze.rei b/infer/src/backend/InferAnalyze.rei index 3a1d17211..21e808878 100644 --- a/infer/src/backend/InferAnalyze.rei +++ b/infer/src/backend/InferAnalyze.rei @@ -12,5 +12,3 @@ open! Utils; /** Main module for the analysis after the capture phase */ let main: unit => unit; - -let output_json_makefile_stats: list DB.source_dir => unit; diff --git a/infer/src/backend/InferAnalyzeExe.re b/infer/src/backend/InferAnalyzeExe.re index f650406f9..7ae4e4a2d 100644 --- a/infer/src/backend/InferAnalyzeExe.re +++ b/infer/src/backend/InferAnalyzeExe.re @@ -10,4 +10,62 @@ open! Utils; /** Main module for the analysis after the capture phase */ -let () = InferAnalyze.main (); +let module L = Logging; + +let register_perf_stats_report () => { + let stats_dir = Filename.concat Config.results_dir Config.backend_stats_dir_name; + let cluster = + switch Config.cluster_cmdline { + | Some cl => "_" ^ cl + | None => "" + }; + let stats_base = Config.perf_stats_prefix ^ Filename.basename cluster ^ ".json"; + let stats_file = Filename.concat stats_dir stats_base; + create_dir Config.results_dir; + create_dir stats_dir; + PerfStats.register_report_at_exit stats_file +}; + +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@?" + | Some clname => L.stdout "Cluster %s@." clname + }; + +let () = { + Logging.set_log_file_identifier + CommandLineOption.Analyze (Option.map Filename.basename Config.cluster_cmdline); + if Config.print_builtins { + Builtin.print_and_exit () + }; + if (not (Sys.file_exists Config.results_dir)) { + L.err "ERROR: results directory %s does not exist@.@." Config.results_dir; + Config.print_usage_exit () + }; + register_perf_stats_report (); + BuiltinDefn.init (); + if Config.developer_mode { + Printexc.record_backtrace true + }; + print_prolog (); + RegisterCheckers.register (); + InferAnalyze.main () +};