[tests] convert cmake test to a Makefile

Reviewed By: jberdine

Differential Revision: D4329214

fbshipit-source-id: 4d4ced5
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent b7bf84e757
commit eafe1158a6

5
.gitignore vendored

@ -13,9 +13,10 @@
*.rej *.rej
*.start *.start
# generated by tests # generated by build and tests
_build /infer/_build
/infer/tests/codetoanalyze/java/*/codetoanalyze /infer/tests/codetoanalyze/java/*/codetoanalyze
_build_infer
*.exp.test *.exp.test
*.exp.test.* *.exp.test.*
*.test.dot *.test.dot

@ -21,7 +21,7 @@ ifneq ($(BUCK),no)
BUILD_SYSTEMS_TESTS += buck BUILD_SYSTEMS_TESTS += buck
endif endif
ifneq ($(CMAKE),no) ifneq ($(CMAKE),no)
BUILD_SYSTEMS_TESTS += clang_compilation_db BUILD_SYSTEMS_TESTS += clang_compilation_db cmake
endif endif
DIRECT_TESTS= DIRECT_TESTS=

@ -61,7 +61,6 @@ CODETOANALYZE_DIR = os.path.join(SCRIPT_DIR, 'codetoanalyze')
EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs') EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs')
ALL_TESTS = [ ALL_TESTS = [
'cmake',
'componentkit_analytics', 'componentkit_analytics',
'componentkit_imports', 'componentkit_imports',
'delete', 'delete',
@ -400,7 +399,7 @@ class BuildIntegrationTest(unittest.TestCase):
[{'compile': ['./waf', 'build']}], [{'compile': ['./waf', 'build']}],
clean_commands=[['make', 'clean']]) clean_commands=[['make', 'clean']])
def test_cmake_integration( def _test_cmake_integration(
self, self,
enabled=None, enabled=None,
root=os.path.join(CODETOANALYZE_DIR, 'cmake'), root=os.path.join(CODETOANALYZE_DIR, 'cmake'),
@ -412,6 +411,7 @@ class BuildIntegrationTest(unittest.TestCase):
{'compile': ['make', 'clean', 'all']}], {'compile': ['make', 'clean', 'all']}],
available=lambda: is_tool_available(['cmake', '--version']), available=lambda: is_tool_available(['cmake', '--version']),
enabled=enabled, enabled=enabled,
report_fname=report_fname,
# remove build/ directory just in case # remove build/ directory just in case
preprocess=lambda: shutil.rmtree(build_root, True), preprocess=lambda: shutil.rmtree(build_root, True),
# cmake produces absolute paths using the real path # 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'), shutil.copytree(os.path.join(CODETOANALYZE_DIR, 'utf8_in_pwd'),
utf8_in_pwd_path) utf8_in_pwd_path)
self.test_cmake_integration( self._test_cmake_integration(
enabled=True, enabled=True,
root=os.path.join(utf8_in_pwd_path, 'cmake'), root=os.path.join(utf8_in_pwd_path, 'cmake'),
report_fname='utf8_in_pwd_cmake_report.json') report_fname='utf8_in_pwd_cmake_report.json')

@ -8,7 +8,7 @@
TESTS_DIR = ../.. TESTS_DIR = ../..
CMAKE_DIR = ../codetoanalyze/clang_compilation_database CMAKE_DIR = ../codetoanalyze/clang_compilation_database
CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build_infer
ANALYZER = infer ANALYZER = infer
CLEAN_EXTRA = $(CMAKE_BUILD_DIR) 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 .. $(CMAKE) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
infer-out/report.json: 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) infer-out-with-index/report.json: $(CMAKE_BUILD_DIR)/compile_commands.json $(CLANG_DEPS) $(SOURCES)
$(call silent_on_success,\ $(call silent_on_success,\

@ -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' $@

@ -0,0 +1 @@
hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()]

@ -1,7 +0,0 @@
[
{
"bug_type": "NULL_DEREFERENCE",
"file": "hello.c",
"procedure": "test"
}
]
Loading…
Cancel
Save