From 644066f4bef6fc8d7bd66b0c791da9755c5d2509 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 5 Jun 2017 03:41:12 -0700 Subject: [PATCH] [driver] make clear when the results dir becomes available Summary: The logic is not that simple and this will be needed in a later diff to create the log file as early as possible. Reviewed By: jberdine Differential Revision: D5173128 fbshipit-source-id: 830f105 --- infer/src/backend/infer.ml | 20 ++++++++++++++++---- infer/src/clang/Capture.re | 3 +-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index bb26c36d1..ecbcdbf24 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -548,16 +548,28 @@ let differential_mode () = Unix.mkdir_p out_path; Differential.to_files diff out_path +let assert_results_dir advice = + if Sys.file_exists Config.results_dir <> `Yes then ( + L.stderr "ERROR: results directory %s does not exist@\nERROR: %s@." Config.results_dir advice; + exit 1 + ) + +let setup_results_dir () = + match Config.command with + | Analyze -> assert_results_dir "have you run capture before?" + | Clang | Report | ReportDiff -> create_results_dir () + | Capture | Compile | Run -> + (* These have their own logic depending on the rest of the command line. It particular they + might delete the previous results directory. Let them do their thing. *) + () + let () = if Config.print_builtins then Builtin.print_and_exit (); + setup_results_dir (); match Config.command with | Analyze -> Logging.set_log_file_identifier CommandLineOption.Analyze (Option.map ~f:Filename.basename Config.cluster_cmdline); - if Sys.file_exists Config.results_dir <> `Yes then ( - L.stderr "ERROR: results directory %s does not exist@.@." Config.results_dir; - Config.print_usage_exit () - ); InferAnalyze.register_perf_stats_report (); analyze Analyze | Clang -> diff --git a/infer/src/clang/Capture.re b/infer/src/clang/Capture.re index 2861e2518..5824bc0bf 100644 --- a/infer/src/clang/Capture.re +++ b/infer/src/clang/Capture.re @@ -42,8 +42,7 @@ let register_perf_stats_report source_file => { let stats_dir = Filename.concat Config.results_dir Config.frontend_stats_dir_name; let abbrev_source_file = DB.source_file_encoding source_file; let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json"; - Utils.create_dir Config.results_dir; - Utils.create_dir stats_dir; + Unix.mkdir_p stats_dir; PerfStats.register_report_at_exit (Filename.concat stats_dir stats_file) };