From eafe1158a66ae128d24926f35b5b6f79f84d4617 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 15 Dec 2016 09:00:32 -0800 Subject: [PATCH] [tests] convert cmake test to a Makefile Reviewed By: jberdine Differential Revision: D4329214 fbshipit-source-id: 4d4ced5 --- .gitignore | 5 ++- Makefile | 2 +- .../build_systems/build_integration_tests.py | 6 +-- .../clang_compilation_db/Makefile | 4 +- infer/tests/build_systems/cmake/Makefile | 42 +++++++++++++++++++ infer/tests/build_systems/cmake/issues.exp | 1 + .../expected_outputs/cmake_report.json | 7 ---- 7 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 infer/tests/build_systems/cmake/Makefile create mode 100644 infer/tests/build_systems/cmake/issues.exp delete mode 100644 infer/tests/build_systems/expected_outputs/cmake_report.json diff --git a/.gitignore b/.gitignore index 1a02c41a5..ff848830b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,10 @@ *.rej *.start -# generated by tests -_build +# generated by build and tests +/infer/_build /infer/tests/codetoanalyze/java/*/codetoanalyze +_build_infer *.exp.test *.exp.test.* *.test.dot diff --git a/Makefile b/Makefile index e24165df6..cd3063ddb 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += buck endif ifneq ($(CMAKE),no) -BUILD_SYSTEMS_TESTS += clang_compilation_db +BUILD_SYSTEMS_TESTS += clang_compilation_db cmake endif DIRECT_TESTS= diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index 64074c424..8ee15d344 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 = [ - 'cmake', 'componentkit_analytics', 'componentkit_imports', 'delete', @@ -400,7 +399,7 @@ class BuildIntegrationTest(unittest.TestCase): [{'compile': ['./waf', 'build']}], clean_commands=[['make', 'clean']]) - def test_cmake_integration( + def _test_cmake_integration( self, enabled=None, root=os.path.join(CODETOANALYZE_DIR, 'cmake'), @@ -412,6 +411,7 @@ class BuildIntegrationTest(unittest.TestCase): {'compile': ['make', 'clean', 'all']}], available=lambda: is_tool_available(['cmake', '--version']), enabled=enabled, + report_fname=report_fname, # remove build/ directory just in case preprocess=lambda: shutil.rmtree(build_root, True), # cmake produces absolute paths using the real path @@ -434,7 +434,7 @@ class BuildIntegrationTest(unittest.TestCase): shutil.copytree(os.path.join(CODETOANALYZE_DIR, 'utf8_in_pwd'), utf8_in_pwd_path) - self.test_cmake_integration( + self._test_cmake_integration( enabled=True, root=os.path.join(utf8_in_pwd_path, 'cmake'), report_fname='utf8_in_pwd_cmake_report.json') diff --git a/infer/tests/build_systems/clang_compilation_db/Makefile b/infer/tests/build_systems/clang_compilation_db/Makefile index c81f128ae..2f8b7ad7d 100644 --- a/infer/tests/build_systems/clang_compilation_db/Makefile +++ b/infer/tests/build_systems/clang_compilation_db/Makefile @@ -8,7 +8,7 @@ TESTS_DIR = ../.. CMAKE_DIR = ../codetoanalyze/clang_compilation_database -CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build +CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build_infer ANALYZER = infer CLEAN_EXTRA = $(CMAKE_BUILD_DIR) @@ -27,7 +27,7 @@ $(CMAKE_BUILD_DIR)/compile_commands.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CMAKE) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. infer-out/report.json: - # make this target empty - since this test defines issues.exp.test directly +# make this target empty - since this test defines issues.exp.test directly infer-out-with-index/report.json: $(CMAKE_BUILD_DIR)/compile_commands.json $(CLANG_DEPS) $(SOURCES) $(call silent_on_success,\ diff --git a/infer/tests/build_systems/cmake/Makefile b/infer/tests/build_systems/cmake/Makefile new file mode 100644 index 000000000..bc9c18ae9 --- /dev/null +++ b/infer/tests/build_systems/cmake/Makefile @@ -0,0 +1,42 @@ +# 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/cmake +CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build +CMAKE_ANALYZE_DIR = $(CMAKE_DIR)/_build_infer + +ANALYZER = infer +CLEAN_EXTRA = $(CMAKE_BUILD_DIR) $(CMAKE_ANALYZE_DIR) +INFER_OPTIONS = --project-root $(CMAKE_DIR) +SOURCES = $(CMAKE_DIR)/hello.c +OBJECTS = $(CMAKE_BUILD_DIR)/CMakeFiles/Hello.dir/hello.c.o +INFERPRINT_OPTIONS = --issues-tests + +include $(TESTS_DIR)/base.make + +$(CMAKE_BUILD_DIR)/Makefile: $(CMAKE_DIR)/CMakeLists.txt + @$(MKDIR_P) $(CMAKE_BUILD_DIR) + @cd $(CMAKE_BUILD_DIR) && \ + $(CMAKE) .. + +$(OBJECTS): $(SOURCES) $(CMAKE_BUILD_DIR)/Makefile + cd $(CMAKE_BUILD_DIR) && \ + $(MAKE) + +infer-out/report.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CLANG_DEPS) +# nuke the build dir and recreate everything to avoid stale compilation/analysis results + @$(REMOVE_DIR) $(CMAKE_ANALYZE_DIR) && \ + $(MKDIR_P) $(CMAKE_ANALYZE_DIR) && \ + cd $(CMAKE_ANALYZE_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a compile $(INFER_OPTIONS) -- cmake ..) + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) -- $(MAKE) -C $(CMAKE_ANALYZE_DIR)) +# cmake makes all paths absolute + @sed -i -e 's#$(abspath $(CMAKE_DIR))/##g' $@ diff --git a/infer/tests/build_systems/cmake/issues.exp b/infer/tests/build_systems/cmake/issues.exp new file mode 100644 index 000000000..d03e4fd25 --- /dev/null +++ b/infer/tests/build_systems/cmake/issues.exp @@ -0,0 +1 @@ +hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()] diff --git a/infer/tests/build_systems/expected_outputs/cmake_report.json b/infer/tests/build_systems/expected_outputs/cmake_report.json deleted file mode 100644 index a6ed10eff..000000000 --- a/infer/tests/build_systems/expected_outputs/cmake_report.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "hello.c", - "procedure": "test" - } -] \ No newline at end of file