From ca784cdb41d0fd8ac5d431df722ee085b2f39f06 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 19 Jan 2017 03:53:43 -0800 Subject: [PATCH] [cli] warn about deprecated options, clean up infer repo Summary: Also make sure we don't introduce deprecated options in our repo, eg when calling infer from infer. Reviewed By: jeremydubreil Differential Revision: D4430379 fbshipit-source-id: 77ea7fd --- .inferconfig | 2 +- Makefile.config | 4 +++ infer/lib/python/inferlib/bucklib.py | 2 +- infer/lib/python/inferlib/utils.py | 4 +-- infer/src/backend/cluster.ml | 2 +- infer/src/backend/clusterMakefile.ml | 2 +- infer/src/backend/inferconfig.ml | 2 +- infer/src/base/CommandLineOption.ml | 27 ++++++++++++++++--- infer/src/checkers/sql_examples/Makefile | 2 +- infer/tests/build_systems/ant/.inferconfig | 2 +- infer/tests/build_systems/linters/Makefile | 2 +- infer/tests/codetoanalyze/java/.inferconfig | 8 +++--- .../codetoanalyze/java/checkers/.inferconfig | 2 +- .../codetoanalyze/java/infer/.inferconfig | 4 +-- .../codetoanalyze/java/tracing/.inferconfig | 4 +-- 15 files changed, 47 insertions(+), 22 deletions(-) diff --git a/.inferconfig b/.inferconfig index 72a3f0d9f..90264e7cb 100644 --- a/.inferconfig +++ b/.inferconfig @@ -1,5 +1,5 @@ { - "skip_translation": [ + "skip-translation": [ { "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_" diff --git a/Makefile.config b/Makefile.config index 1e1427831..7b12237fd 100644 --- a/Makefile.config +++ b/Makefile.config @@ -7,6 +7,10 @@ SHELL = bash +# Make infer crash a bit more often to detect issues in the way we call infer within this repo, eg, +# using deprecated options. +export INFER_STRICT_MODE=1 + include $(ROOT_DIR)/Makefile.autoconf PLATFORM = $(shell uname) diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index a48f7b9af..92d2d8c33 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -62,7 +62,7 @@ def prepare_build(args): infer_cache_dir = os.path.join(args.infer_out, 'cache') if not os.path.isdir(infer_cache_dir): os.mkdir(infer_cache_dir) - infer_options += ['--infer_cache', infer_cache_dir] + infer_options += ['--infer-cache', infer_cache_dir] temp_files = [infer_cache_dir] try: diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index fc09714c5..d8b8fa9c3 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -111,7 +111,7 @@ def dump_json_to_path( def infer_version(): version = json.loads(subprocess.check_output([ get_cmd_in_bin_dir('InferAnalyze'), - '-version_json', + '--version-json', ]).decode()) return version['commit'] @@ -119,7 +119,7 @@ def infer_version(): def infer_branch(): version = json.loads(subprocess.check_output([ get_cmd_in_bin_dir('InferAnalyze'), - '-version_json', + '--version-json', ]).decode()) return version['branch'] diff --git a/infer/src/backend/cluster.ml b/infer/src/backend/cluster.ml index 6e44965c0..fd702e68a 100644 --- a/infer/src/backend/cluster.ml +++ b/infer/src/backend/cluster.ml @@ -41,7 +41,7 @@ let pp_cluster fmt (nr, cluster) = let pp_cl fmt n = Format.fprintf fmt "%s" (cl_name n) in store_to_file (DB.filename_from_string fname) (nr, cluster); F.fprintf fmt "%a: @\n" pp_cl nr; - F.fprintf fmt "\t$(INFERANALYZE) -cluster '%s'@\n" fname; + F.fprintf fmt "\t$(INFERANALYZE) --cluster '%s'@\n" fname; (* touch the target of the rule to let `make` know that the job has been done *) F.fprintf fmt "\t@@touch $@@@\n"; F.fprintf fmt "@\n" diff --git a/infer/src/backend/clusterMakefile.ml b/infer/src/backend/clusterMakefile.ml index 83c0b7dfb..31974161f 100644 --- a/infer/src/backend/clusterMakefile.ml +++ b/infer/src/backend/clusterMakefile.ml @@ -42,7 +42,7 @@ let pp_prolog fmt clusters = let compilation_dbs_cmd = IList.map (F.sprintf "--clang-compilation-db-files '%s'") !Config.clang_compilation_db_files |> String.concat ~sep:" " |> escape in - F.fprintf fmt "INFERANALYZE= %s -results_dir '%s' %s \n@." + F.fprintf fmt "INFERANALYZE= %s --results-dir '%s' %s \n@." (Config.bin_dir ^/ (CLOpt.exe_name Analyze)) (escape Config.results_dir) compilation_dbs_cmd; diff --git a/infer/src/backend/inferconfig.ml b/infer/src/backend/inferconfig.ml index 49dd968ac..f0271913d 100644 --- a/infer/src/backend/inferconfig.ml +++ b/infer/src/backend/inferconfig.ml @@ -280,7 +280,7 @@ let patterns_of_json_with_key (json_key, json) = error in let warn_user msg = - F.eprintf "WARNING: in file %s: error parsing option %s@\n%s" + F.eprintf "WARNING: in file %s: error parsing option %s@\n%s@." Config.inferconfig_file json_key msg in (* Translate all the JSON entries into matching patterns *) diff --git a/infer/src/base/CommandLineOption.ml b/infer/src/base/CommandLineOption.ml index d006021f2..5b5138ce8 100644 --- a/infer/src/base/CommandLineOption.ml +++ b/infer/src/base/CommandLineOption.ml @@ -29,6 +29,11 @@ let to_arg_spec = function | Symbol (symbols, f) -> Arg.Symbol (symbols, f) | Rest f -> Arg.Rest f +let is_env_var_set v = + Option.value (Option.map (Sys.getenv v) ~f:((=) "1")) ~default:false + +let warnf = if is_env_var_set "INFER_STRICT_MODE" then failwithf else F.eprintf + (** Each command line option may appear in the --help list of any executable, these tags are used to specify which executables for which an option will be documented. *) type exe = Analyze | Clang | Driver | Interactive | Print @@ -210,6 +215,22 @@ let add exes desc = desc_list := desc :: !desc_list ) exe_desc_lists +let deprecate_desc ~long ~short ~deprecated desc = + let warn () = + warnf "WARNING: '-%s' is deprecated. Use '--%s'%s instead.@." + deprecated long (if short = "" then "" else Printf.sprintf " or '-%s'" short) in + let warn_then_f f x = warn (); f x in + let deprecated_spec = match desc.spec with + | Unit f -> Unit (warn_then_f f) + | String f -> String (warn_then_f f) + | Symbol (symbols, f) -> Symbol (symbols, warn_then_f f) + | Rest _ as spec -> spec in + let deprecated_decode_json j = + F.eprintf "WARNING: in .inferconfig: '%s' is deprecated. Use '%s' instead.@." deprecated long; + desc.decode_json j in + { long = ""; short = deprecated; meta = ""; doc = ""; + spec = deprecated_spec; decode_json = deprecated_decode_json } + let mk ?(deprecated=[]) ?(exes=[]) ~long ?(short="") ~default ~meta doc ~default_to_string ~decode_json ~mk_setter ~mk_spec = let variable = ref default in @@ -231,9 +252,9 @@ let mk ?(deprecated=[]) ?(exes=[]) if short <> "" then add [] {desc with long = ""; meta = ""; doc = ""} ; (* add desc for deprecated options only for parsing, without documentation *) - IList.iter (fun deprecated -> - add [] {desc with long = ""; short = deprecated; meta = ""; doc = ""} - ) deprecated ; + List.iter deprecated ~f:(fun deprecated -> + deprecate_desc ~long ~short ~deprecated desc + |> add []) ; variable (* arguments passed to Arg.parse_argv_dynamic, susceptible to be modified on the fly when parsing *) diff --git a/infer/src/checkers/sql_examples/Makefile b/infer/src/checkers/sql_examples/Makefile index fccd9bdf0..bcf35537c 100644 --- a/infer/src/checkers/sql_examples/Makefile +++ b/infer/src/checkers/sql_examples/Makefile @@ -1,5 +1,5 @@ all: - InferAnalyze -results_dir out -checkers + InferAnalyze --results-dir out -checkers .PHONY: capture capture: diff --git a/infer/tests/build_systems/ant/.inferconfig b/infer/tests/build_systems/ant/.inferconfig index 72a3f0d9f..90264e7cb 100644 --- a/infer/tests/build_systems/ant/.inferconfig +++ b/infer/tests/build_systems/ant/.inferconfig @@ -1,5 +1,5 @@ { - "skip_translation": [ + "skip-translation": [ { "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_" diff --git a/infer/tests/build_systems/linters/Makefile b/infer/tests/build_systems/linters/Makefile index cee362017..2b7eccffa 100644 --- a/infer/tests/build_systems/linters/Makefile +++ b/infer/tests/build_systems/linters/Makefile @@ -10,7 +10,7 @@ SYM_ROOT = ../codetoanalyze/linters/tsrc_symlink TESTS_DIR = ../.. ANALYZER = linters CLANG_OPTIONS = -x objective-c++ -std=c++11 -fblocks -c -INFER_OPTIONS = --no-filtering --debug-exceptions --project_root $(SYM_ROOT) +INFER_OPTIONS = --no-filtering --debug-exceptions --project-root $(SYM_ROOT) INFERPRINT_OPTIONS = --issues-tests SOURCES = $(SYM_ROOT)/main.mm diff --git a/infer/tests/codetoanalyze/java/.inferconfig b/infer/tests/codetoanalyze/java/.inferconfig index 46bad5db6..5bd033efa 100644 --- a/infer/tests/codetoanalyze/java/.inferconfig +++ b/infer/tests/codetoanalyze/java/.inferconfig @@ -1,5 +1,5 @@ { - "never_returning_null": [ + "never-returning-null": [ { "language": "Java", "source_contains": "_AUTOMATICALLY_GENERATED_" @@ -13,16 +13,16 @@ "infer-blacklist-files-containing": [ "@generated" ], - "enable_checks": [ + "enable-checks": [ "GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL" ], - "skip_translation": [ + "skip-translation": [ { "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_" } ], - "modeled_expensive": [ + "modeled-expensive": [ { "language": "Java", "class": "android.app.Activity", diff --git a/infer/tests/codetoanalyze/java/checkers/.inferconfig b/infer/tests/codetoanalyze/java/checkers/.inferconfig index a92a25acc..4a9e2d394 100644 --- a/infer/tests/codetoanalyze/java/checkers/.inferconfig +++ b/infer/tests/codetoanalyze/java/checkers/.inferconfig @@ -1,5 +1,5 @@ { - "modeled_expensive": [ + "modeled-expensive": [ { "language": "Java", "class": "android.app.Activity", diff --git a/infer/tests/codetoanalyze/java/infer/.inferconfig b/infer/tests/codetoanalyze/java/infer/.inferconfig index 4584297ee..07907b1fb 100644 --- a/infer/tests/codetoanalyze/java/infer/.inferconfig +++ b/infer/tests/codetoanalyze/java/infer/.inferconfig @@ -1,5 +1,5 @@ { - "never_returning_null": [ + "never-returning-null": [ { "language": "Java", "source_contains": "_AUTOMATICALLY_GENERATED_" @@ -13,7 +13,7 @@ "infer-blacklist-files-containing": [ "@generated" ], - "skip_translation": [ + "skip-translation": [ { "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_" diff --git a/infer/tests/codetoanalyze/java/tracing/.inferconfig b/infer/tests/codetoanalyze/java/tracing/.inferconfig index 4584297ee..07907b1fb 100644 --- a/infer/tests/codetoanalyze/java/tracing/.inferconfig +++ b/infer/tests/codetoanalyze/java/tracing/.inferconfig @@ -1,5 +1,5 @@ { - "never_returning_null": [ + "never-returning-null": [ { "language": "Java", "source_contains": "_AUTOMATICALLY_GENERATED_" @@ -13,7 +13,7 @@ "infer-blacklist-files-containing": [ "@generated" ], - "skip_translation": [ + "skip-translation": [ { "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_"