Skip to content

Commit

Permalink
add precommit in cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jan 11, 2025
1 parent ad2acc8 commit 41f7621
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ ENDIF()
SET(LIB ${LIB} CACHE INTERNAL "libs which should be linked for executable target")

INCLUDE(ExternalProject)
INCLUDE(cmake/precommit.cmake)
INCLUDE(cmake/findTools.cmake)
INCLUDE(cmake/openssl.cmake)
INCLUDE(cmake/gflags.cmake)
Expand Down Expand Up @@ -223,6 +224,15 @@ FOREACH(IGNORE_FILE ${CLANG_FORMAT_IGNORE_FILES})
FILE(APPEND ${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt "${IGNORE_FILE}\n")
ENDFOREACH()

# install git hooks when configure
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${HOOKS_SOURCE_DIR}/precommit.sh
${GIT_HOOKS_DIR}/pre-commit
COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
)

STRING(CONCAT FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src,")
ADD_CUSTOM_TARGET(format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
Expand All @@ -239,17 +249,6 @@ ADD_CUSTOM_TARGET(check-format
--source_dirs ${FORMAT_DIRS}
)

# FIND_PROGRAM(CLANG_FORMAT "clang-format")
# IF(CLANG_FORMAT)
# ADD_CUSTOM_TARGET(
# format-check
# COMMAND ${CMAKE_SOURCE_DIR}/etc/script/check-format.sh
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# COMMENT "Checking code format..."
# VERBATIM
# )
# ENDIF()

ADD_CUSTOM_TARGET(clang-tidy
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_tidy.py
-clang-tidy-binary ${CLANG_TIDY_BIN}
Expand Down
19 changes: 19 additions & 0 deletions cmake/precommit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2025-present, Arana/Kiwi Community. 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.


# define hooks source and target path
SET(HOOKS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/etc/script")
set(GIT_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")

# ensure pre-commit hook is installed
ADD_CUSTOM_TARGET(install_git_hooks
COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${HOOKS_SOURCE_DIR}/precommit.sh
${GIT_HOOKS_DIR}/pre-commit
COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
COMMENT "Installing git hooks..."
)
11 changes: 0 additions & 11 deletions etc/script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@ PWD=`pwd`
PROJECT_HOME="${PWD}/"
CONF="${PROJECT_HOME}/etc/conf/kiwi.conf"

function precommit() {
# Copy pre-commit hook to the .git/hooks directory

if [ ! -f "./git/hooks/pre-commit" ];then
cp etc/script/pre_commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "Git hooks installed."
fi
}

function build() {
precommit
if [ ! -f "/proc/cpuinfo" ];then
CPU_CORE=$(sysctl -n hw.ncpu)
else
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 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.

AUX_SOURCE_DIRECTORY(. kiwi_SRC)
AUX_SOURCE_DIRECTORY(. KIWI_SRC)

ADD_EXECUTABLE(kiwi ${kiwi_SRC})
ADD_EXECUTABLE(kiwi ${KIWI_SRC})

IF (CMAKE_BUILD_TYPE STREQUAL "Release")
# get current date and time and git commit id
Expand Down

0 comments on commit 41f7621

Please sign in to comment.