Fix pre-commit exec from different places

This commit is contained in:
Ivan-lis 2024-10-09 21:05:21 +00:00
parent f649af6ec2
commit 033bceb06d
3 changed files with 15 additions and 5 deletions

View file

@ -5,6 +5,7 @@ NC='\033[0m' # No Color
SCRIPTS_FOLDER=$( dirname "$(realpath "$0")" ) SCRIPTS_FOLDER=$( dirname "$(realpath "$0")" )
PROJECT_FOLDER=$( dirname "$SCRIPTS_FOLDER" ) PROJECT_FOLDER=$( dirname "$SCRIPTS_FOLDER" )
cd $PROJECT_FOLDER || exit 1
GIT_STAGED_FILES=$(git diff --cached --name-only --diff-filter=d | grep -E -i "\.(h|hpp|c|cpp)$") GIT_STAGED_FILES=$(git diff --cached --name-only --diff-filter=d | grep -E -i "\.(h|hpp|c|cpp)$")
GIT_SCRIPT_FILES="$(git diff --cached --name-only --diff-filter=d | grep -E -i "\.(sh)$") .githooks/pre-commit" GIT_SCRIPT_FILES="$(git diff --cached --name-only --diff-filter=d | grep -E -i "\.(sh)$") .githooks/pre-commit"
@ -49,14 +50,16 @@ fi
# #
# Description: Temporal solution before CI # Description: Temporal solution before CI
# Test tools: default compiler, gtest execution # Test tools: default compiler, gtest execution
# Manual cmd command: cd /workspaces/larra ; mkdir temp_pre_commit_check ; cd temp_pre_commit_check ; cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON .. ; cmake --build . --target larra_xmpp_tests --parallel `nproc` ; ./larra_xmpp_tests --gtest_brief=1 # Manual cmd command: cd /workspaces/larra ; mkdir temp_pre_commit_check ; cd temp_pre_commit_check ; cmake -Wno-dev -S .. -B . -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DCMAKE_CXX_FLAGS="-Wno-non-template-friend" ; cmake --build . --target larra_xmpp_tests --parallel `nproc` ; ./larra_xmpp_tests --gtest_brief=1
# #
GTEST_FOLDER=${PROJECT_FOLDER?}/temp_pre_commit_check GTEST_FOLDER=${PROJECT_FOLDER?}/temp_pre_commit_check
rm -rf ${GTEST_FOLDER} || exit 1
printf "\n\tPrepare GTests to check (takes up to 10 seconds)" printf "\n\tPrepare GTests to check (takes up to 10 seconds)"
mkdir -p ${GTEST_FOLDER}; cd ${GTEST_FOLDER} || exit 1; cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON .. > /dev/null 2>&1 mkdir -p ${GTEST_FOLDER}; cd ${GTEST_FOLDER} || exit 1; cmake -Wno-dev -S ${PROJECT_FOLDER} -B ${GTEST_FOLDER} -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DCMAKE_CXX_FLAGS="-Wno-non-template-friend" > /dev/null 2>&1
printf "\n\tBuild GTests to check (takes up to 30 seconds)" printf "\n\tBuild GTests to check (takes up to 30 seconds)"
cmake --build . --target larra_xmpp_tests --parallel "`nproc`" > /dev/null 2>&1 cmake --build ${GTEST_FOLDER} --target larra_xmpp_tests --parallel "$(nproc)"
printf "\n\tLaunch GTests to check\n" printf "\n\tLaunch GTests to check\n"
./larra_xmpp_tests --gtest_brief=1 ./larra_xmpp_tests --gtest_brief=1

4
.vscode/tasks.json vendored
View file

@ -23,7 +23,7 @@
"command": [ "command": [
"cd ${workspaceFolder} &&", "cd ${workspaceFolder} &&",
"mkdir -p build && cd build &&", "mkdir -p build && cd build &&",
"cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&", "cmake -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&",
"cmake --build . --parallel `nproc`", "cmake --build . --parallel `nproc`",
"|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )"
], ],
@ -45,7 +45,7 @@
"command": [ "command": [
"cd ${workspaceFolder} &&", "cd ${workspaceFolder} &&",
"mkdir -p build_clang && cd build_clang &&", "mkdir -p build_clang && cd build_clang &&",
"cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&", "cmake -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DENABLE_TESTS=ON .. &&",
"cmake --build . --parallel `nproc`", "cmake --build . --parallel `nproc`",
"|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )"
], ],

View file

@ -1,5 +1,12 @@
cmake_minimum_required(VERSION 3.28) cmake_minimum_required(VERSION 3.28)
# Configure local githooks
execute_process(
COMMAND git config core.hooksPath .githooks
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_COMMAND_RESULT
)
project(larra project(larra
VERSION 0.1 VERSION 0.1
LANGUAGES CXX) LANGUAGES CXX)