Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cpplint style check automatically before commit #81

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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