From d2b4f3c8da7b908573676eb62e4c77079293572b Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 20 Sep 2017 07:43:39 -0700 Subject: [PATCH] [config] add option to force deletion of results dir Summary: Since D5381239, infer is careful not to delete directories that do not "look like" results directories on startup, in case the user passed, eg, `-o /`. In our repo, lots of results dir are created by build/test of infer, and when the version of infer changes and the expected contents of results directories change then it might start refusing to delete the results directories created with another version of infer. Add an option to force infer to delete the results directory no matter how dodgy it looks, and use it in our repo by adding the option in every .inferconfig. Reviewed By: mbouaziz Differential Revision: D5870984 fbshipit-source-id: 09412de --- .inferconfig | 1 + infer/src/backend/infer.ml | 9 +++++---- infer/src/base/Config.ml | 12 ++++++++++++ infer/src/base/Config.mli | 2 ++ infer/tests/build_systems/ant/.inferconfig | 1 + infer/tests/codetoanalyze/cpp/quandary/.inferconfig | 1 + infer/tests/codetoanalyze/java/.inferconfig | 1 + infer/tests/codetoanalyze/java/checkers/.inferconfig | 1 + infer/tests/codetoanalyze/java/infer/.inferconfig | 1 + infer/tests/codetoanalyze/java/quandary/.inferconfig | 1 + .../codetoanalyze/java/threadsafety/.inferconfig | 1 + infer/tests/codetoanalyze/java/tracing/.inferconfig | 1 + 12 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.inferconfig b/.inferconfig index b4e598b9e..f6e6fcb94 100644 --- a/.inferconfig +++ b/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "siof-safe-methods": ["getGlobalNonPODWhitelisted", "whitelisted::getGlobalNonPOD", "whitelisted::TemplatedObject::getGlobalNonPOD"], "skip-translation": [ diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index af3e62b27..e852db474 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -52,10 +52,11 @@ let remove_results_dir () = (* Look if file exists, it may not be a directory but that will be caught by the call to [is_results_dir]. If it's an empty directory, leave it alone. This allows users to create a temporary directory for the infer results without infer removing it to recreate it, which could be racy. *) if Sys.file_exists Config.results_dir = `Yes && not (Utils.directory_is_empty Config.results_dir) then ( - Result.iter_error (is_results_dir ()) ~f:(fun err -> - L.(die UserError) - "ERROR: '%s' exists but does not seem to be an infer results directory: %s@\nERROR: Please delete '%s' and try again@." - Config.results_dir err Config.results_dir ) ; + if not Config.force_delete_results_dir then + Result.iter_error (is_results_dir ()) ~f:(fun err -> + L.(die UserError) + "ERROR: '%s' exists but does not seem to be an infer results directory: %s@\nERROR: Please delete '%s' and try again@." + Config.results_dir err Config.results_dir ) ; Utils.rmtree Config.results_dir ) let setup_results_dir () = diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index c0200270e..e48aff934 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1106,6 +1106,16 @@ and flavors = ~in_help:CLOpt.([(Capture, manual_buck_flavors)]) "Buck integration using Buck flavors (clang only), eg $(i,`infer --flavors -- buck build //foo:bar#infer`)" +and force_delete_results_dir = + CLOpt.mk_bool ~long:"force-delete-results-dir" ~default:false + ~in_help: + (CLOpt.( + [ (Capture, manual_generic) + ; (Compile, manual_generic) + ; (Diff, manual_generic) + ; (Run, manual_generic) ])) + "Do not refuse to delete the results directory if it doesn't look like an infer results directory." + and from_json_report = CLOpt.mk_path_opt ~long:"from-json-report" ~in_help:CLOpt.([(Report, manual_generic)]) @@ -2067,6 +2077,8 @@ and filtering = !filtering and flavors = !flavors +and force_delete_results_dir = !force_delete_results_dir + and fragment_retains_view = !fragment_retains_view and from_json_report = !from_json_report diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 990bfc79d..73335260b 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -404,6 +404,8 @@ val filtering : bool val flavors : bool +val force_delete_results_dir : bool + val fragment_retains_view : bool val from_json_report : string option diff --git a/infer/tests/build_systems/ant/.inferconfig b/infer/tests/build_systems/ant/.inferconfig index 90264e7cb..a553feb67 100644 --- a/infer/tests/build_systems/ant/.inferconfig +++ b/infer/tests/build_systems/ant/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "skip-translation": [ { "language": "Java", diff --git a/infer/tests/codetoanalyze/cpp/quandary/.inferconfig b/infer/tests/codetoanalyze/cpp/quandary/.inferconfig index 2fdde237a..b434de8ee 100644 --- a/infer/tests/codetoanalyze/cpp/quandary/.inferconfig +++ b/infer/tests/codetoanalyze/cpp/quandary/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "quandary-sources": [ { "procedure": "__infer_taint_source", diff --git a/infer/tests/codetoanalyze/java/.inferconfig b/infer/tests/codetoanalyze/java/.inferconfig index 6d1e0898c..3613e92e3 100644 --- a/infer/tests/codetoanalyze/java/.inferconfig +++ b/infer/tests/codetoanalyze/java/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "never-returning-null": [ { "language": "Java", diff --git a/infer/tests/codetoanalyze/java/checkers/.inferconfig b/infer/tests/codetoanalyze/java/checkers/.inferconfig index 15e60379b..5d7cc8d97 100644 --- a/infer/tests/codetoanalyze/java/checkers/.inferconfig +++ b/infer/tests/codetoanalyze/java/checkers/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "modeled-expensive": [ { "language": "Java", diff --git a/infer/tests/codetoanalyze/java/infer/.inferconfig b/infer/tests/codetoanalyze/java/infer/.inferconfig index 07907b1fb..dc3c086c7 100644 --- a/infer/tests/codetoanalyze/java/infer/.inferconfig +++ b/infer/tests/codetoanalyze/java/infer/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "never-returning-null": [ { "language": "Java", diff --git a/infer/tests/codetoanalyze/java/quandary/.inferconfig b/infer/tests/codetoanalyze/java/quandary/.inferconfig index f4bd3a13f..927113ef2 100644 --- a/infer/tests/codetoanalyze/java/quandary/.inferconfig +++ b/infer/tests/codetoanalyze/java/quandary/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "quandary-sources": [ { "procedure": "codetoanalyze.java.quandary.ExternalSpecs.privateData*", diff --git a/infer/tests/codetoanalyze/java/threadsafety/.inferconfig b/infer/tests/codetoanalyze/java/threadsafety/.inferconfig index c60f430a4..ad61ed582 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/.inferconfig +++ b/infer/tests/codetoanalyze/java/threadsafety/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "threadsafe-aliases": ["MyThreadSafeAlias1", "codetoanalyze.java.checkers.MyThreadSafeAlias2"], "skip-translation": [ { diff --git a/infer/tests/codetoanalyze/java/tracing/.inferconfig b/infer/tests/codetoanalyze/java/tracing/.inferconfig index 07907b1fb..dc3c086c7 100644 --- a/infer/tests/codetoanalyze/java/tracing/.inferconfig +++ b/infer/tests/codetoanalyze/java/tracing/.inferconfig @@ -1,4 +1,5 @@ { + "force-delete-results-dir": true, "never-returning-null": [ { "language": "Java",