From 4d98e29352f36c023e6b1297c87ceb2ece000c98 Mon Sep 17 00:00:00 2001 From: Igor Sugak Date: Tue, 3 Feb 2015 21:43:06 -0800 Subject: [PATCH] rocksdb: Enable scan-build static analysis Summary: Added new target ##make analyze## into Makefile. This command runs clang static analyzer and builds the sources as ##make all##. The result report is put into ##$(RocksDbSourceRoot)/can_build_report/## If the development environment is a Facebook devserver and ##ROCKSDB_NO_FBCODE## is not set, then scan-build is used from fbcode. If it is run not on a Facebook devserver, scan-build should be available in ##$PATH##. I'll add details to wiki how to install scan-build on a non Facebook devserver environment. Test Plan: Run the fallowing commands on a Facebook devserver and Mac OS, and ensure no build or test errors. ``` % make all check -j32 % make clean % USE_CLANG=1 make all -j32 % make analyze % USE_CLANG=1 make analyze ``` Reviewers: sdong, lgalanis, leveldb, igor Reviewed By: igor Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D32799 --- Makefile | 8 +++++++- build_tools/build_detect_platform | 10 ++++++++++ build_tools/fbcode_config.sh | 7 +++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1c0dea975..215ecb8a7 100644 --- a/Makefile +++ b/Makefile @@ -238,7 +238,7 @@ endif # PLATFORM_SHARED_EXT .PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests package \ release tags valgrind_check whitebox_crash_test format static_lib shared_lib all \ - dbg rocksdbjavastatic rocksdbjava install uninstall + dbg rocksdbjavastatic rocksdbjava install uninstall analyze all: $(LIBRARY) $(PROGRAMS) $(TESTS) @@ -303,6 +303,10 @@ valgrind_check: all $(PROGRAMS) $(TESTS) echo $$t $$((etime - stime)) >> $(VALGRIND_DIR)/valgrind_tests_times; \ done +analyze: + $(MAKE) clean + $(CLANG_SCAN_BUILD) --use-analyzer=$(CLANG_ANALYZER) -o $(CURDIR)/scan_build_report $(MAKE) all -j32 + unity.cc: $(shell (export ROCKSDB_ROOT="$(CURDIR)"; "$(CURDIR)/build_tools/unity" "$(CURDIR)/unity.cc")) @@ -733,9 +737,11 @@ ifneq ($(MAKECMDGOALS),format) ifneq ($(MAKECMDGOALS),jclean) ifneq ($(MAKECMDGOALS),jtest) ifneq ($(MAKECMDGOALS),package) +ifneq ($(MAKECMDGOALS),analyze) -include $(DEPFILES) endif endif endif endif endif +endif diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index b314b3acb..9c8bd7d2a 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -75,6 +75,14 @@ if test -z "$TARGET_OS"; then TARGET_OS=`uname -s` fi +if test -z "$CLANG_SCAN_BUILD"; then + CLANG_SCAN_BUILD=scan-build +fi + +if test -z "$CLANG_ANALYZER"; then + CLANG_ANALYZER=$(which clang++) +fi + COMMON_FLAGS="$COMMON_FLAGS ${CFLAGS}" CROSS_COMPILE= PLATFORM_CCFLAGS= @@ -348,3 +356,5 @@ echo "JEMALLOC_LIB=$JEMALLOC_LIB" >> "$OUTPUT" echo "ROCKSDB_MAJOR=$ROCKSDB_MAJOR" >> "$OUTPUT" echo "ROCKSDB_MINOR=$ROCKSDB_MINOR" >> "$OUTPUT" echo "ROCKSDB_PATCH=$ROCKSDB_PATCH" >> "$OUTPUT" +echo "CLANG_SCAN_BUILD=$CLANG_SCAN_BUILD" >> "$OUTPUT" +echo "CLANG_ANALYZER=$CLANG_ANALYZER" >> "$OUTPUT" diff --git a/build_tools/fbcode_config.sh b/build_tools/fbcode_config.sh index afc3de40b..2b40e3412 100644 --- a/build_tools/fbcode_config.sh +++ b/build_tools/fbcode_config.sh @@ -77,6 +77,10 @@ DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $GFLAGS_I GCC_BASE="/mnt/gvfs/third-party2/gcc/1c67a0b88f64d4d9ced0382d141c76aaa7d62fba/4.9.x/centos6-native/1317bc4" STDLIBS="-L $GCC_BASE/lib64" +CLANG_BASE="/mnt/gvfs/third-party2/clang/290704c112bf894bf4a30d7bbd1be81e34998473/dev" +CLANG_ANALYZER="$CLANG_BASE/centos6-native/af4b1a0/bin/clang++" +CLANG_SCAN_BUILD="$CLANG_BASE/src/clang/tools/scan-build/scan-build" + if [ -z "$USE_CLANG" ]; then # gcc CC="$GCC_BASE/bin/gcc" @@ -87,7 +91,6 @@ if [ -z "$USE_CLANG" ]; then CFLAGS+=" -isystem $LIBGCC_INCLUDE" else # clang - CLANG_BASE="/mnt/gvfs/third-party2/clang/290704c112bf894bf4a30d7bbd1be81e34998473/dev" CLANG_INCLUDE="$CLANG_BASE/gcc-4.9-glibc-2.20/74c386f/lib/clang/dev/include/" CC="$CLANG_BASE/centos6-native/af4b1a0/bin/clang" CXX="$CLANG_BASE/centos6-native/af4b1a0/bin/clang++" @@ -119,4 +122,4 @@ EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $GFLAGS_LIBS" VALGRIND_VER="/mnt/gvfs/third-party2/valgrind/6c45ef049cbf11c2df593addb712cd891049e737/3.10.0/gcc-4.9-glibc-2.20/4230243/bin/" -export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE +export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE CLANG_ANALYZER CLANG_SCAN_BUILD