Skip to content

Commit

Permalink
support cpplint code style checker (vesoft-inc#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet authored and dangleptr committed Jan 14, 2019
1 parent 015a731 commit 1d1172d
Show file tree
Hide file tree
Showing 3 changed files with 6,287 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,17 @@ add_custom_target(
DEPENDS clean-all
)

set(PRE_COMMIT_HOOK ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
if(EXISTS ${PRE_COMMIT_HOOK})
MESSAGE(STATUS "Remove pre commit hook")
FILE(REMOVE ${PRE_COMMIT_HOOK})
endif()

MESSAGE(STATUS "Create pre commit hook")
execute_process(COMMAND "ln" "-s" ${CMAKE_CURRENT_SOURCE_DIR}/cpplint/style_checker.sh ${PRE_COMMIT_HOOK}
RESULT_VARIABLE result)
IF(NOT ${result})
MESSAGE(STATUS "pre-commit hook create successed")
ELSE()
MESSAGE(STATUS "pre-commit hook create failed")
ENDIF()
29 changes: 29 additions & 0 deletions cpplint/bin/style_checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Copyright (c) 2018 - present, VE Software Inc. All rights reserved
#
# This source code is licensed under Apache 2.0 License
# (found in the LICENSE.Apache file in the root directory)

PROJECT_PATH=$(cd `dirname $0`; pwd)
PROJECT_NAME="${PROJECT_PATH##*/}"
CPPLINT_FILE=$PROJECT_PATH"/../../cpplint/cpplint.py"

if [ $# -eq 0 ];then
CHECK_FILES=$(git diff --name-only HEAD)
else
CHECK_FILES=$(find $1 -not \( -path src/CMakeFiles -prune \) -not \( -path src/interface/gen-cpp2 -prune \) -name "*.[h]" -o -name "*.cpp" | grep -v 'GraphScanner.*' | grep -v 'GraphParser.*')
fi

CPPLINT_EXTENS=cpp,h
CPPLINT_FITER=-whitespace/indent,-build/include_what_you_use,-readability/todo,-build/include,-build/header_guard
python $CPPLINT_FILE --extensions=$CPPLINT_EXTENS --filter=$CPPLINT_FITER --linelength=100 $CHECK_FILES 2>&1

result=$?
if [ $result -eq 0 ]
then
exit 0
else
echo "cpplint code style check failed, please fix and recommit."
exit 1
fi
Loading

0 comments on commit 1d1172d

Please sign in to comment.