From e695e14ee19bf2411a9b75485528f55378a83fbf Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 19 May 2016 08:42:00 -0700 Subject: [PATCH] add various filter options from inferconfig to the CLI Summary: Part of the migration of .inferconfig-specific options into options accepted both by .inferconfig and the CLI. Reviewed By: jberdine Differential Revision: D3304783 fbshipit-source-id: 4a7ee6f --- infer/src/backend/CommandLineOption.ml | 6 ++- infer/src/backend/config.ml | 53 +++++++++++++++++++++ infer/src/backend/config.mli | 4 ++ infer/src/backend/inferconfig.ml | 21 +++----- infer/tests/codetoanalyze/java/.inferconfig | 2 +- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/infer/src/backend/CommandLineOption.ml b/infer/src/backend/CommandLineOption.ml index 03d31a647..08e25520b 100644 --- a/infer/src/backend/CommandLineOption.ml +++ b/infer/src/backend/CommandLineOption.ml @@ -324,7 +324,11 @@ let decode_inferconfig_to_argv path = let json_config = YBU.to_assoc json in let one_config_item result (key, json_val) = try - let {decode_json} = IList.find (fun {long} -> string_equal key long) desc_list in + let {decode_json} = + IList.find + (fun {long; short} -> + string_equal key long || (* for deprecated options *) string_equal key short) + desc_list in decode_json json_val @ result with | Not_found -> diff --git a/infer/src/backend/config.ml b/infer/src/backend/config.ml index 0e0093d10..0cba6090e 100644 --- a/infer/src/backend/config.ml +++ b/infer/src/backend/config.ml @@ -269,6 +269,41 @@ and allow_specs_cleanup = CLOpt.mk_bool ~deprecated:["allow_specs_cleanup"] ~long:"allow-specs-cleanup" "Allow to remove existing specs before running analysis when it's not incremental" +and ( + analysis_path_regex_whitelist_options, + analysis_path_regex_blacklist_options, + analysis_blacklist_files_containing_options, + analysis_suppress_errors_options) = + let mk_filtering_options ~suffix ?(deprecated_suffix=[]) ~help ~meta = + let mk_option analyzer = + let long = Printf.sprintf "%s-%s" (string_of_analyzer analyzer) suffix in + let deprecated = + IList.map (Printf.sprintf "%s_%s" (string_of_analyzer analyzer)) deprecated_suffix in + let help_string = Printf.sprintf "%s (%s only)" help (string_of_analyzer analyzer) in + CLOpt.mk_string_list ~deprecated ~long ~exes:CLOpt.[A] ~meta help_string in + IList.map (fun analyzer -> (analyzer, mk_option analyzer)) analyzers in + ( + mk_filtering_options + ~suffix:"whitelist-path-regex" + ~deprecated_suffix:["whitelist"] + ~help:"whitelist the analysis of files whose relative path matches the specified OCaml-style regex" + ~meta:"path regex", + mk_filtering_options + ~suffix:"blacklist-path-regex" + ~deprecated_suffix:["blacklist"] + ~help:"blacklist the analysis of files whose relative path matches the specified OCaml-style regex" + ~meta:"path regex", + mk_filtering_options + ~suffix:"blacklist-files-containing" + ~deprecated_suffix:["blacklist_files_containing"] + ~help:"blacklist files containing the specified string" + ~meta:"string", + mk_filtering_options + ~suffix:"suppress-errors" + ~deprecated_suffix:["suppress_errors"] + ~help:"do not report a type of errors" + ~meta:"error name") + (** Check whether to report Analysis_stops message in user mode *) and analysis_stops = CLOpt.mk_bool ~deprecated:["analysis_stops"] ~long:"analysis-stops" @@ -969,6 +1004,14 @@ let print_usage_exit () = let anon_args = !anon_args and abs_struct = !abs_struct and allow_specs_cleanup = !allow_specs_cleanup +and analysis_path_regex_whitelist_options = + IList.map (fun (a, b) -> (a, !b)) analysis_path_regex_whitelist_options +and analysis_path_regex_blacklist_options = + IList.map (fun (a, b) -> (a, !b)) analysis_path_regex_blacklist_options +and analysis_blacklist_files_containing_options = + IList.map (fun (a, b) -> (a, !b)) analysis_blacklist_files_containing_options +and analysis_suppress_errors_options = + IList.map (fun (a, b) -> (a, !b)) analysis_suppress_errors_options and analysis_stops = !analysis_stops and analyzer = !analyzer and angelic_execution = !angelic_execution @@ -1055,6 +1098,16 @@ and write_html = !write_html and xml_specs = !xml_specs and zip_libraries = !zip_libraries + +let analysis_path_regex_whitelist analyzer = + IList.assoc (=) analyzer analysis_path_regex_whitelist_options +and analysis_path_regex_blacklist analyzer = + IList.assoc (=) analyzer analysis_path_regex_blacklist_options +and analysis_blacklist_files_containing analyzer = + IList.assoc (=) analyzer analysis_blacklist_files_containing_options +and analysis_suppress_errors analyzer = + IList.assoc (=) analyzer analysis_suppress_errors_options + let inferconfig_json = lazy !CLOpt.inferconfig_json and suppress_warnings_json = lazy ( diff --git a/infer/src/backend/config.mli b/infer/src/backend/config.mli index a9c9127bd..a0c1e798e 100644 --- a/infer/src/backend/config.mli +++ b/infer/src/backend/config.mli @@ -101,7 +101,11 @@ val sound_dynamic_dispatch : bool val anon_args : string list val abs_struct : int val allow_specs_cleanup : bool +val analysis_path_regex_whitelist : analyzer -> string list +val analysis_path_regex_blacklist : analyzer -> string list +val analysis_blacklist_files_containing : analyzer -> string list val analysis_stops : bool +val analysis_suppress_errors : analyzer -> string list val analyzer : analyzer option val angelic_execution : bool val array_level : int diff --git a/infer/src/backend/inferconfig.ml b/infer/src/backend/inferconfig.ml index 824b64752..215d09174 100644 --- a/infer/src/backend/inferconfig.ml +++ b/infer/src/backend/inferconfig.ml @@ -327,16 +327,12 @@ module ModeledExpensiveMatcher = OverridesMatcher(struct end) let load_filters analyzer = - let lazy json = Config.inferconfig_json in - let inferconfig = - { - whitelist = lookup_string_list (analyzer ^ "_whitelist") json; - blacklist = lookup_string_list (analyzer ^ "_blacklist") json; - blacklist_files_containing = - lookup_string_list (analyzer ^ "_blacklist_files_containing") json; - suppress_errors = lookup_string_list (analyzer ^ "_suppress_errors") json; - } in - Some inferconfig + { + whitelist = Config.analysis_path_regex_whitelist analyzer; + blacklist = Config.analysis_path_regex_blacklist analyzer; + blacklist_files_containing = Config.analysis_blacklist_files_containing analyzer; + suppress_errors = Config.analysis_suppress_errors analyzer; + } let filters_from_inferconfig inferconfig : filters = let path_filter = @@ -365,10 +361,7 @@ let filters_from_inferconfig inferconfig : filters = (* The environment varialble NO_PATH_FILTERING disables path filtering. *) let create_filters analyzer = if Config.from_env_variable "NO_PATH_FILTERING" then do_not_filter - else - match load_filters (Utils.string_of_analyzer analyzer) with - | None -> do_not_filter - | Some inferconfig -> filters_from_inferconfig inferconfig + else filters_from_inferconfig (load_filters analyzer) (* Decide whether a checker or error type is enabled or disabled based on*) (* white/black listing in .inferconfig and the default value *) diff --git a/infer/tests/codetoanalyze/java/.inferconfig b/infer/tests/codetoanalyze/java/.inferconfig index 3fbcbfd4d..a7ff591ed 100644 --- a/infer/tests/codetoanalyze/java/.inferconfig +++ b/infer/tests/codetoanalyze/java/.inferconfig @@ -10,7 +10,7 @@ "method": "get" } ], - "infer_blacklist_files_containing": [ + "infer-blacklist-files-containing": [ "@generated" ], "skip_translation": [