diff --git a/infer/src/base/SourceFile.ml b/infer/src/base/SourceFile.ml index a9196f21c..fb9669170 100644 --- a/infer/src/base/SourceFile.ml +++ b/infer/src/base/SourceFile.ml @@ -276,17 +276,21 @@ let changed_sources_from_changed_files changed_files = with _exn -> changed_files_set ) -let read_config_changed_files () = - match Config.changed_files_index with - | None -> - None - | Some index -> ( - match Utils.read_file index with - | Ok lines -> - Some (changed_sources_from_changed_files lines) - | Error error -> - L.external_error "Error reading the changed files index '%s': %s@." index error ; - None ) +let read_config_changed_files = + let result = + lazy + ( match Config.changed_files_index with + | None -> + None + | Some index -> ( + match Utils.read_file index with + | Ok lines -> + Some (changed_sources_from_changed_files lines) + | Error error -> + L.external_error "Error reading the changed files index '%s': %s@." index error ; + None ) ) + in + fun () -> Lazy.force result module SQLite = struct diff --git a/infer/src/integration/JsonReports.ml b/infer/src/integration/JsonReports.ml index 66655d3d2..1e6f35baf 100644 --- a/infer/src/integration/JsonReports.ml +++ b/infer/src/integration/JsonReports.ml @@ -325,6 +325,15 @@ end module JsonConfigImpactPrinter = MakeJsonListPrinter (JsonConfigImpactPrinterElt) +let is_in_changed_files {Location.file} = + match SourceFile.read_config_changed_files () with + | None -> + (* when Config.changed_files_index is not given *) + true + | Some changed_files -> + SourceFile.Set.mem file changed_files + + let mk_error_filter filters proc_name file error_name = (Config.write_html || not (IssueType.(equal skip_function) error_name)) && filters.Inferconfig.path_filter file @@ -339,7 +348,7 @@ let collect_issues proc_name proc_location err_log issues_acc = let write_costs proc_name loc cost_opt (outfile : Utils.outfile) = - if not (Cost.is_report_suppressed proc_name) then + if (not (Cost.is_report_suppressed proc_name)) && is_in_changed_files loc then JsonCostsPrinter.pp outfile.fmt {loc; proc_name; cost_opt} @@ -357,7 +366,7 @@ let get_all_config_fields () = let write_config_impact all_config_fields proc_name loc config_impact_opt (outfile : Utils.outfile) = - if ExternalConfigImpactData.is_in_config_data_file proc_name then + if ExternalConfigImpactData.is_in_config_data_file proc_name && is_in_changed_files loc then let config_impact_opt = Option.map config_impact_opt ~f: diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp b/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp index 22dc4590c..972b2f4aa 100644 --- a/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp +++ b/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp @@ -1 +1 @@ -{"top":{"current":0,"previous":0},"unreachable":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":10,"previous":10},{"degree":100,"current":4,"previous":1},{"degree":200,"current":0,"previous":1}]} \ No newline at end of file +{"top":{"current":0,"previous":0},"unreachable":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":10,"previous":7},{"degree":100,"current":4,"previous":0},{"degree":200,"current":0,"previous":1}]} \ No newline at end of file