From 4ed185e557a41ddc67c099baf4bd44d005633359 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 15 Feb 2017 23:08:45 -0800 Subject: [PATCH] [infer][java] for the buck integration, remove the files that are invalidating the Buck cache Summary: Sevel auxiliary files made it to the output directory of the analysis of individual targets when analyzing Java projects build with Buck. However, these files are then taken into account= to compute the target rule key and then to decide whether to analyze the dependent targets. Since these auxiliary files were containing time sentive information, every cach miss on a given target would then invalitate the cache entries for all the dependent targets. This diff cleans up the output directory to only keep the specs files, the `global.tenv` and the `report.json` files which are the only artifacts needed to analyze the dependent targets This diff makes a minimal number of changes to see how it behaves in prod, but I intend to refoctor this more when continuing to add support for running Infer with genrules Reviewed By: sblackshear Differential Revision: D4562615 fbshipit-source-id: 4628420 --- infer/src/backend/InferPrint.re | 4 ++- infer/src/backend/infer.ml | 28 ++++++++++++------- infer/src/base/Config.ml | 1 + infer/src/base/Config.mli | 1 + infer/src/java/jMain.ml | 2 +- .../build_systems/genrule/module1/Class1.java | 9 ++++++ .../build_systems/genrule/module2/Class2.java | 9 ++++++ 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 31da4f3af..dfe71a104 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -1401,6 +1401,8 @@ let main report_csv::report_csv report_json::report_json => { (Stats, init_stats_format_list ()), (Summary, init_summary_format_list ()) ]; - register_perf_stats_report (); + if (not Config.buck_cache_mode) { + register_perf_stats_report () + }; print_issues formats_by_report_kind }; diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 43f388b4b..a1bbad73c 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -120,8 +120,9 @@ let create_results_dir () = Unix.mkdir_p (Config.results_dir ^/ Config.specs_dir_name) let clean_results_dir () = - let dirs = ["classnames"; "filelists"; "multicore"; "sources"] in - let suffixes = [".cfg"; ".cg"] in + let dirs = ["classnames"; "filelists"; "multicore"; "sources"; "log"; + "attributes"; "backend_stats"; "reporting_stats"; "frontend_stats"] in + let suffixes = [".cfg"; ".cg"; ".txt"; ".csv"; ".json"] in let rec clean name = match Unix.opendir name with | dir -> ( @@ -139,8 +140,13 @@ let clean_results_dir () = Unix.closedir dir in cleandir dir ) + | exception Unix.Unix_error (Unix.ENOTDIR, _, _) + when String.equal (Filename.basename name) "report.json" -> + (* Keep the JSON report *) + () | exception Unix.Unix_error (Unix.ENOTDIR, _, _) -> - if List.exists ~f:(Filename.check_suffix name) suffixes then + if not (String.equal (Filename.basename name) "report.json") + && List.exists ~f:(Filename.check_suffix name) suffixes then Unix.unlink name | exception Unix.Unix_error (Unix.ENOENT, _, _) -> () in @@ -395,7 +401,7 @@ let () = remove_results_dir () ; create_results_dir () ; (* re-set log files, as default files were in results_dir removed above *) - L.set_log_file_identifier CLOpt.(Infer Driver) None ; + if not Config.buck_cache_mode then L.set_log_file_identifier CLOpt.(Infer Driver) None; if Config.print_builtins then Builtin.print_and_exit () ; if CLOpt.is_originator then L.do_out "%s@\n" Config.version_string ; if Config.debug_mode || Config.stats_mode then log_infer_args driver_mode ; @@ -404,17 +410,19 @@ let () = anyway, pretend that we are not called from another make to prevent make falling back to a mono-threaded execution. *) Unix.unsetenv "MAKEFLAGS"; - register_perf_stats_report () ; - touch_start_file () ; + if not Config.buck_cache_mode then register_perf_stats_report () ; + if Config.buck_cache_mode && Config.reactive_mode then + failwith "The reactive analysis mode is not compatible with the Buck integration for Java"; + if not Config.buck_cache_mode then touch_start_file () ; capture driver_mode ; analyze driver_mode ; if CLOpt.is_originator then ( - StatsAggregator.generate_files () ; let in_buck_mode = match driver_mode with | PythonCapture (BBuck, _) -> true | _ -> false in + StatsAggregator.generate_files () ; if Config.equal_analyzer Config.analyzer Config.Crashcontext then Crashcontext.crashcontext_epilogue ~in_buck_mode; - if in_buck_mode then - clean_results_dir () ; if Config.fail_on_bug then fail_on_issue_epilogue () ; - ) + ); + if Config.buck_cache_mode then + clean_results_dir () diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 5c233dc3c..6e95ee757 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1466,6 +1466,7 @@ and bootclasspath = !bootclasspath and bo_debug = !bo_debug and buck = !buck and buck_build_args = !buck_build_args +and buck_cache_mode = !buck && not !debug and buck_out = !buck_out and bufferoverrun = !bufferoverrun and bugs_csv = !bugs_csv diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 8e3160067..c318693c8 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -156,6 +156,7 @@ val bootclasspath : string option val bo_debug : int val buck : bool val buck_build_args : string list +val buck_cache_mode : bool val buck_out : string option val bufferoverrun : bool val bugs_csv : string option diff --git a/infer/src/java/jMain.ml b/infer/src/java/jMain.ml index 408265bcd..65682c41c 100644 --- a/infer/src/java/jMain.ml +++ b/infer/src/java/jMain.ml @@ -26,7 +26,7 @@ let register_perf_stats_report source_file = let init_global_state source_file = - register_perf_stats_report source_file ; + if not Config.buck_cache_mode then register_perf_stats_report source_file ; Config.curr_language := Config.Java; DB.Results_dir.init source_file; Ident.NameGenerator.reset (); diff --git a/infer/tests/build_systems/genrule/module1/Class1.java b/infer/tests/build_systems/genrule/module1/Class1.java index c0dc8b738..2b5f77ae4 100644 --- a/infer/tests/build_systems/genrule/module1/Class1.java +++ b/infer/tests/build_systems/genrule/module1/Class1.java @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + package genrule.module1; import genrule.annotations.Nullable; diff --git a/infer/tests/build_systems/genrule/module2/Class2.java b/infer/tests/build_systems/genrule/module2/Class2.java index 94be356af..ffa3333e2 100644 --- a/infer/tests/build_systems/genrule/module2/Class2.java +++ b/infer/tests/build_systems/genrule/module2/Class2.java @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + package genrule.module2; import genrule.module1.Class1;