diff --git a/.gitignore b/.gitignore index 77ae0baea..51e04bd0b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,17 @@ *.orig *.rej *.start + +# generated by tests +_build +/infer/tests/codetoanalyze/java/*/codetoanalyze *.exp.test *.exp.test.* +*.test.dot duplicates.txt -infer/tests/codetoanalyze/java/*/codetoanalyze +*.capture.sh +*.capture.bdump +*.capture.biniou # Directories generated by Ocamlbuild _build diff --git a/Makefile b/Makefile index f522c8314..e89f879c9 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ endif ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += buck endif +ifneq ($(CMAKE),no) +BUILD_SYSTEMS_TESTS += clang_compilation_db +endif DIRECT_TESTS= ifeq ($(BUILD_C_ANALYZERS),yes) diff --git a/Makefile.config.in b/Makefile.config.in index 6ac62ac11..5cc4d1ec5 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -20,6 +20,7 @@ CC = @CC@ CFLAGS = @CFLAGS@ CLANG_INCLUDES = @CLANG_INCLUDES@ CLANG_PREFIX = @CLANG_PREFIX@ +CMAKE = @CMAKE@ CPP = @CPP@ CXX = @CXX@ CXXFLAGS = @CXXFLAGS@ diff --git a/configure.ac b/configure.ac index a9bd4d797..1648e70d3 100644 --- a/configure.ac +++ b/configure.ac @@ -98,8 +98,8 @@ AS_IF([test "x$enable_c_analyzers" = "xyes"], [ AC_CHECK_TOOL([SHASUM], [shasum], [no]) AC_ASSERT_PROG([shasum], [$SHASUM]) # cmake is required to build llvm+clang + AC_CHECK_TOOL([CMAKE], [cmake], [no]) AS_IF([test "x$is_release_tree" = "xno"], [ - AC_CHECK_TOOL([CMAKE], [cmake], [no]) AC_ASSERT_PROG([cmake], [$CMAKE]) ]) AC_ARG_ENABLE(ocamlopt-custom-cc, @@ -116,7 +116,6 @@ AC_CHECK_TOOL([PYTHON27], [python2.7], [no]) AC_ASSERT_PROG([python2.7], [$PYTHON27]) AC_CHECK_TOOL([XCODE_SELECT], [xcode-select], [no]) -AC_SUBST([XCODE_SELECT]) # prefer clang over gcc because the plugins makes use of @@ -232,7 +231,6 @@ fi AC_CHECK_TOOL([ATDGEN], [atdgen], [no]) AC_ASSERT_PROG([atdgen], [$ATDGEN]) -AC_SUBST([ATDGEN]) AC_ARG_ENABLE(ocaml-annot, AS_HELP_STRING([--disable-ocaml-annot], [do not build ocaml .annot files]), diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index ee62f5b3c..c1fb9ef67 100755 --- a/infer/tests/build_systems/build_integration_tests.py +++ b/infer/tests/build_systems/build_integration_tests.py @@ -61,7 +61,6 @@ CODETOANALYZE_DIR = os.path.join(SCRIPT_DIR, 'codetoanalyze') EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs') ALL_TESTS = [ - 'clang_compilation_database', 'cmake', 'componentkit', 'delete', @@ -421,27 +420,6 @@ class BuildIntegrationTest(unittest.TestCase): # remove build/ directory shutil.rmtree(build_root) - def test_clang_compilation_database_integration( - self, - enabled=None, - root=os.path.join(CODETOANALYZE_DIR, 'clang_compilation_database'), - report_fname='clang_compilation_database_report.json'): - build_root = os.path.join(root, 'build') - if test('clang_compilation_database', 'clang compilation database test', - build_root, - [{'compile': ['cmake', '-DCMAKE_EXPORT_COMPILE_COMMANDS=1', '..']}, - {'compile': ['clang-compilation-database', 'compile_commands.json']}], - available=lambda: is_tool_available(['cmake', '--version']), - enabled=enabled, - # remove build/ directory just in case - preprocess=lambda: shutil.rmtree(build_root, True), - # cmake produces absolute paths using the real path - postprocess=(lambda errors: - make_paths_relative_in_report( - os.path.realpath(root), errors))): - # remove build/ directory - shutil.rmtree(build_root) - def test_utf8_in_pwd_integration(self): if not 'utf8_in_pwd' in to_test: print('\nSkipping utf8_in_pwd integration test') diff --git a/infer/tests/build_systems/clang_compilation_db/Makefile b/infer/tests/build_systems/clang_compilation_db/Makefile new file mode 100644 index 000000000..f456c4afe --- /dev/null +++ b/infer/tests/build_systems/clang_compilation_db/Makefile @@ -0,0 +1,31 @@ +# Copyright (c) 2016 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +TESTS_DIR = ../.. + +CMAKE_DIR = ../codetoanalyze/clang_compilation_database +CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build + +ANALYZER = 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)/base.make + +$(CMAKE_BUILD_DIR): + $(MKDIR_P) $@ + +$(CMAKE_BUILD_DIR)/compile_commands.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CMAKE_BUILD_DIR) + cd $(CMAKE_BUILD_DIR) && \ + $(CMAKE) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. + +infer-out/report.json: $(CMAKE_BUILD_DIR)/compile_commands.json $(INFER_BIN) $(SOURCES) + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) -- clang-compilation-database $<) diff --git a/infer/tests/build_systems/clang_compilation_db/issues.exp b/infer/tests/build_systems/clang_compilation_db/issues.exp new file mode 100644 index 000000000..0781f943a --- /dev/null +++ b/infer/tests/build_systems/clang_compilation_db/issues.exp @@ -0,0 +1 @@ +hello.cpp, test, 2, NULL_DEREFERENCE, [start of procedure test()] diff --git a/infer/tests/build_systems/expected_outputs/clang_compilation_database_report.json b/infer/tests/build_systems/expected_outputs/clang_compilation_database_report.json deleted file mode 100644 index 670aacd63..000000000 --- a/infer/tests/build_systems/expected_outputs/clang_compilation_database_report.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "hello.cpp", - "procedure": "test" - } -] \ No newline at end of file