diff --git a/Makefile b/Makefile index f5b0e649a..1f3dabcfb 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ DIRECT_TESTS += \ cpp_racerd cpp_siof cpp_uninit cpp_nullable cpp_conflicts cpp_linters-for-test-only \ ifneq ($(BUCK),no) -BUILD_SYSTEMS_TESTS += buck-clang-db buck_flavors buck_flavors_run buck_flavors_deterministic +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 diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 16de0892b..587f3149b 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -834,7 +834,7 @@ and bootclasspath = and buck = CLOpt.mk_bool ~long:"buck" "" and buck_blacklist = - CLOpt.mk_string_opt + CLOpt.mk_string_list ~deprecated:["-blacklist-regex"; "-blacklist"] ~long:"buck-blacklist" ~in_help:InferCommand.[(Run, manual_buck_flavors); (Capture, manual_buck_flavors)] diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index e3a876ac9..564eb93bf 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -249,7 +249,7 @@ val bo_relational_domain : [`Bo_relational_domain_oct | `Bo_relational_domain_po val buck : bool -val buck_blacklist : string option +val buck_blacklist : string list val buck_build_args : string list diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 53bbe2778..3e81efc48 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -219,11 +219,9 @@ let capture ~changed_files = function let infer_py = Config.lib_dir ^/ "python" ^/ "infer.py" in let args = List.rev_append Config.anon_args - ( ( match Config.buck_blacklist with - | Some s when in_buck_mode -> - ["--blacklist-regex"; s] - | _ -> - [] ) + ( ( if not (List.is_empty Config.buck_blacklist) then + ["--blacklist-regex"; "(" ^ String.concat ~sep:")|(" Config.buck_blacklist ^ ")"] + else [] ) @ (if not Config.continue_capture then [] else ["--continue"]) @ ( match Config.force_integration with | None -> diff --git a/infer/tests/build_systems/buck_blacklist/.buckconfig b/infer/tests/build_systems/buck_blacklist/.buckconfig new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/buck_blacklist/Makefile b/infer/tests/build_systems/buck_blacklist/Makefile new file mode 100644 index 000000000..81f09a70b --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/Makefile @@ -0,0 +1,29 @@ +# 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 = ../.. +ROOT_DIR = $(TESTS_DIR)/../.. + +ANALYZER = checkers +BUCK_TARGET = //src:hello @buck_target.txt +SOURCES = $(wildcard src/*.c) $(wildcard src/subtarget1/*.c) $(wildcard src/subtarget2/*.c) +OBJECTS = buck-out/gen/src/hello\#compile-hello.c.o1f717d69,default/hello.c.o +INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(TESTS_DIR) --no-linters +INFERPRINT_OPTIONS = --project-root $(TESTS_DIR) --issues-tests +CLEAN_EXTRA = buck-out + +include $(TESTS_DIR)/infer.make + +$(OBJECTS): $(JAVA_SOURCE_FILES) + $(QUIET)$(call silent_on_success,Compiling Buck flavors tests,\ + $(BUCK) build --no-cache $(BUCK_TARGET)) + +infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(MAKEFILE_LIST) + $(QUIET)$(REMOVE_DIR) buck-out && \ + $(call silent_on_success,Testing Buck flavors integration,\ + $(INFER_BIN) $(INFER_OPTIONS) capture --flavors --results-dir $(CURDIR)/infer-out \ + @blacklist.txt --buck-blacklist '.*src/hello2\.c' \ + -- $(BUCK) build --no-cache $(BUCK_TARGET) &&\ + $(INFER_BIN) $(INFER_OPTIONS) --merge analyze) diff --git a/infer/tests/build_systems/buck_blacklist/blacklist.txt b/infer/tests/build_systems/buck_blacklist/blacklist.txt new file mode 100644 index 000000000..797f340b0 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/blacklist.txt @@ -0,0 +1,2 @@ +--buck-blacklist +(.*subhello2.*)|(.*subhello2.*) diff --git a/infer/tests/build_systems/buck_blacklist/buck_target.txt b/infer/tests/build_systems/buck_blacklist/buck_target.txt new file mode 100644 index 000000000..ce6b87f8e --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/buck_target.txt @@ -0,0 +1 @@ +//src:hello3 diff --git a/infer/tests/build_systems/buck_blacklist/issues.exp b/infer/tests/build_systems/buck_blacklist/issues.exp new file mode 100644 index 000000000..4c0b8723f --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/issues.exp @@ -0,0 +1,3 @@ +src/hello.c, test, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test()] +src/hello3.c, test3, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure test3()] +src/subtarget1/z_filename_greater_than_subhello1.c, foo_defined_in_subtarget1, 2, NULL_DEREFERENCE, no_bucket, ERROR, [start of procedure foo_defined_in_subtarget1()] diff --git a/infer/tests/build_systems/buck_blacklist/src/BUCK b/infer/tests/build_systems/buck_blacklist/src/BUCK new file mode 100644 index 000000000..8e7b8a860 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/BUCK @@ -0,0 +1,17 @@ +cxx_library( + name = 'hello', + srcs = [ + 'hello.c', 'hello2.c', + ], + deps = [ + "//src/subtarget1:subtarget1", + "//src/subtarget2:subtarget2", + ] +) + +cxx_library( + name = 'hello3', + srcs = [ + 'hello3.c', + ], +) diff --git a/infer/tests/build_systems/buck_blacklist/src/hello.c b/infer/tests/build_systems/buck_blacklist/src/hello.c new file mode 100644 index 000000000..d1dd780a4 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/hello.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015-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. + */ + +#include + +void test() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_blacklist/src/hello2.c b/infer/tests/build_systems/buck_blacklist/src/hello2.c new file mode 100644 index 000000000..f8a4a290d --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/hello2.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015-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. + */ + +#include + +void test2() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_blacklist/src/hello3.c b/infer/tests/build_systems/buck_blacklist/src/hello3.c new file mode 100644 index 000000000..8c615dffc --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/hello3.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015-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. + */ + +#include + +void test3() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_blacklist/src/subtarget1/BUCK b/infer/tests/build_systems/buck_blacklist/src/subtarget1/BUCK new file mode 100644 index 000000000..e9368c055 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/subtarget1/BUCK @@ -0,0 +1,10 @@ +cxx_library( + name = 'subtarget1', + visibility = [ + 'PUBLIC', + ], + srcs = [ + 'z_filename_greater_than_subhello1.c', + 'subhello1.c', + ], +) diff --git a/infer/tests/build_systems/buck_blacklist/src/subtarget1/subhello1.c b/infer/tests/build_systems/buck_blacklist/src/subtarget1/subhello1.c new file mode 100644 index 000000000..272941b07 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/subtarget1/subhello1.c @@ -0,0 +1,13 @@ +/* + * 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. + */ + +#include + +void foo_defined_in_subtarget1() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_blacklist/src/subtarget1/z_filename_greater_than_subhello1.c b/infer/tests/build_systems/buck_blacklist/src/subtarget1/z_filename_greater_than_subhello1.c new file mode 100644 index 000000000..b830c7fc3 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/subtarget1/z_filename_greater_than_subhello1.c @@ -0,0 +1,13 @@ +/* + * 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. + */ + +#include + +void foo_defined_in_subtarget1() { + int* t = NULL; + *t = 42; +} diff --git a/infer/tests/build_systems/buck_blacklist/src/subtarget2/BUCK b/infer/tests/build_systems/buck_blacklist/src/subtarget2/BUCK new file mode 100644 index 000000000..6df812b6d --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/subtarget2/BUCK @@ -0,0 +1,9 @@ +cxx_library( + name = 'subtarget2', + visibility = [ + 'PUBLIC', + ], + srcs = [ + 'subhello2.c', + ], +) diff --git a/infer/tests/build_systems/buck_blacklist/src/subtarget2/subhello2.c b/infer/tests/build_systems/buck_blacklist/src/subtarget2/subhello2.c new file mode 100644 index 000000000..c6e368027 --- /dev/null +++ b/infer/tests/build_systems/buck_blacklist/src/subtarget2/subhello2.c @@ -0,0 +1,16 @@ +/* + * 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. + */ + +#include + +void foo_defined_in_subtarget1(); + +void goo() { + foo_defined_in_subtarget1(); + int* s = NULL; + *s = 42; +}