Add `--filter-report-paths` argument to restrict results to a given list of paths

Reviewed By: akotulski

Differential Revision: D4697727

fbshipit-source-id: e23d3fa
master
Martino Luca 8 years ago committed by Facebook Github Bot
parent 6c67c850d5
commit 6e84a4b3cb

@ -277,6 +277,16 @@ let module ProcsXml = {
let pp_procs_close fmt () => Io_infer.Xml.pp_close fmt "procedures";
};
let paths_to_filter =
Option.bind Config.filter_report_paths (fun f => Some (In_channel.read_lines f)) |>
Option.map f::(List.map f::SourceFile.create);
let report_filter source_file =>
switch paths_to_filter {
| Some paths => List.mem equal::SourceFile.equal paths source_file
| None => true
};
let should_report (issue_kind: Exceptions.err_kind) issue_type error_desc eclass =>
if (not Config.filtering || Exceptions.equal_err_class eclass Exceptions.Linters) {
true
@ -387,7 +397,7 @@ let module IssuesCsv = {
if (
in_footprint &&
error_filter source_file error_desc error_name &&
should_report ekind error_name error_desc eclass
should_report ekind error_name error_desc eclass && report_filter source_file
) {
let err_desc_string = error_desc_to_csv_string error_desc;
let err_advice_string = error_advice_to_csv_string error_desc;
@ -463,7 +473,8 @@ let module IssuesJson = {
if (
in_footprint &&
error_filter source_file error_desc error_name &&
should_report_source_file && should_report ekind error_name error_desc eclass
should_report_source_file &&
should_report ekind error_name error_desc eclass && report_filter source_file
) {
let kind = Exceptions.err_kind_string ekind;
let bug_type = Localise.to_string error_name;

@ -918,6 +918,12 @@ and filter_paths =
CLOpt.mk_bool ~long:"filter-paths" ~default:true
"Filters specified in .inferconfig"
and filter_report_paths =
CLOpt.mk_string_opt
~long:"filter-report-paths" ~parse_mode:CLOpt.(Infer [Print])
"Newline-separated list of files for which to emit a report. \
Source files should be specified relative to project root or be absolute."
and flavors =
CLOpt.mk_bool ~deprecated:["-use-flavors"] ~long:"flavors"
~parse_mode:CLOpt.(Infer [Driver])
@ -1606,6 +1612,7 @@ and fcp_apple_clang = !fcp_apple_clang
and fcp_syntax_only = !fcp_syntax_only
and file_renamings = !file_renamings
and filter_paths = !filter_paths
and filter_report_paths = !filter_report_paths
and filtering = !filtering
and final_parse_action = parse_action
and flavors = !flavors

@ -228,6 +228,7 @@ val fcp_apple_clang : string option
val fcp_syntax_only : bool
val file_renamings : string option
val filter_paths : bool
val filter_report_paths : string option
val filtering : bool
val final_parse_action : CommandLineOption.parse_action
val flavors : bool

@ -150,18 +150,19 @@ let of_header header_file =
| _ -> None in
Option.map ~f:from_abs_path file_opt
let create path =
if Filename.is_relative path then
(* sources in changed-files-index may be specified relative to project root *)
RelativeProjectRoot path
else
from_abs_path path
let changed_files_set =
let create_source_file path =
if Filename.is_relative path then
(* sources in changed-files-index may be specified relative to project root *)
RelativeProjectRoot path
else
from_abs_path path in
Option.bind Config.changed_files_index Utils.read_file |>
Option.map ~f:(
List.fold
~f:(fun changed_files line ->
let source_file = create_source_file line in
let source_file = create line in
let changed_files' = Set.add source_file changed_files in
(* Add source corresponding to changed header if it exists *)
match of_header source_file with

@ -27,6 +27,10 @@ val empty : t
(** create source file from absolute path *)
val from_abs_path : string -> t
(* Create a SourceFile from a given path. If relative, it assumes it is w.r.t.
project root *)
val create : string -> t
(** string encoding of a source file (including path) as a single filename *)
val encoding : t -> string

Loading…
Cancel
Save