From 6131b1fd13f5392da34f544fda64f5160426c613 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Sat, 27 Oct 2018 02:19:43 -0700 Subject: [PATCH] Allow ints for int options in .inferconfig Reviewed By: jvillard Differential Revision: D10861323 fbshipit-source-id: 78453ff9f --- Makefile | 2 +- infer/src/base/CommandLineOption.ml | 15 ++++++++- .../inferconfig_not_strict/Makefile | 33 +++++++++++++++++++ .../inferconfig_not_strict/config/infer.conf | 4 +++ .../inferconfig_not_strict/issues.exp | 4 +++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 infer/tests/build_systems/inferconfig_not_strict/Makefile create mode 100644 infer/tests/build_systems/inferconfig_not_strict/config/infer.conf create mode 100644 infer/tests/build_systems/inferconfig_not_strict/issues.exp diff --git a/Makefile b/Makefile index 32d1ddc4c..c59fa699a 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += buck_blacklist buck-clang-db buck_flavors buck_flavors_run buck_flavors_deterministic endif ifneq ($(CMAKE),no) -BUILD_SYSTEMS_TESTS += clang_compilation_db cmake inferconfig +BUILD_SYSTEMS_TESTS += clang_compilation_db cmake inferconfig inferconfig_not_strict endif ifneq ($(NDKBUILD),no) BUILD_SYSTEMS_TESTS += ndk_build diff --git a/infer/src/base/CommandLineOption.ml b/infer/src/base/CommandLineOption.ml index 71f37b945..e27e7b850 100644 --- a/infer/src/base/CommandLineOption.ml +++ b/infer/src/base/CommandLineOption.ml @@ -337,6 +337,19 @@ type 'a t = -> Arg.doc -> 'a +let int_json_decoder ~flag ~inferconfig_dir json = + let int_as_string = + match json with + | `String s -> + warnf "WARNING: in %s/.inferconfig for option '%s', use an integer instead of a string.@." + inferconfig_dir flag ; + s + | json -> + string_of_int (YBU.to_int json) + in + [flag; int_as_string] + + let string_json_decoder ~flag ~inferconfig_dir:_ json = [flag; YBU.to_string json] let path_json_decoder ~flag ~inferconfig_dir json = @@ -463,7 +476,7 @@ let mk_int ~default ?(default_to_string = string_of_int) ?(f = Fn.id) ?(deprecat let flag = mk_flag ~deprecated ?short ~long in mk ~deprecated ~long ?short ~default ?parse_mode ?in_help ~meta doc ~default_to_string ~mk_setter:(fun var str -> var := f (int_of_string str)) - ~decode_json:(string_json_decoder ~flag) + ~decode_json:(int_json_decoder ~flag) ~mk_spec:(fun set -> String set) diff --git a/infer/tests/build_systems/inferconfig_not_strict/Makefile b/infer/tests/build_systems/inferconfig_not_strict/Makefile new file mode 100644 index 000000000..684745deb --- /dev/null +++ b/infer/tests/build_systems/inferconfig_not_strict/Makefile @@ -0,0 +1,33 @@ +# Copyright (c) 2017-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +TESTS_DIR = ../.. + +CMAKE_DIR = $(CURDIR)/../codetoanalyze/clang_compilation_database +CMAKE_BUILD_DIR = $(CURDIR)/_build_infer + +CLEAN_EXTRA = $(CMAKE_BUILD_DIR) +INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(CMAKE_DIR) +SOURCES = $(CMAKE_DIR)/hello.cpp +OBJECTS = $(CMAKE_BUILD_DIR)/compile_commands.json +INFERPRINT_OPTIONS = --issues-tests + +include $(TESTS_DIR)/infer.make +export INFER_STRICT_MODE=0 + +$(CMAKE_BUILD_DIR): + $(QUIET)$(MKDIR_P) $@ + +$(CMAKE_BUILD_DIR)/compile_commands.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CMAKE_BUILD_DIR) + $(QUIET)cd $(CMAKE_BUILD_DIR) && \ + $(call silent_on_success,Running cmake to generate Makefiles,\ + $(CMAKE) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $(CMAKE_DIR)) + +infer-out/report.json: $(CMAKE_BUILD_DIR)/compile_commands.json $(CLANG_DEPS) $(SOURCES) +# test that config/infer.conf is read and paths inside it are interpreted relative to its +# location + $(QUIET)$(call silent_on_success,Testing Clang compilation database with index integration,\ + INFERCONFIG=config/infer.conf $(INFER_BIN) $(INFER_OPTIONS) -o $(@D) \ + --compilation-database $<) diff --git a/infer/tests/build_systems/inferconfig_not_strict/config/infer.conf b/infer/tests/build_systems/inferconfig_not_strict/config/infer.conf new file mode 100644 index 000000000..9e0190b37 --- /dev/null +++ b/infer/tests/build_systems/inferconfig_not_strict/config/infer.conf @@ -0,0 +1,4 @@ +{ + "bo-debug": 0, + "bo-debug": "0" +} diff --git a/infer/tests/build_systems/inferconfig_not_strict/issues.exp b/infer/tests/build_systems/inferconfig_not_strict/issues.exp new file mode 100644 index 000000000..7a11cad39 --- /dev/null +++ b/infer/tests/build_systems/inferconfig_not_strict/issues.exp @@ -0,0 +1,4 @@ +hello.cpp, test0, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test0()] +hello.cpp, test1, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test1(),start of procedure deref1()] +hello.cpp, test2, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test2(),start of procedure deref2()] +lib3.h, test, 0, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test(),start of procedure deref3()]