generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: format, include-guards, copyrights, git-hooks (#222)
* refactor: change copyright comments * refactor: replace include-guards by pragma-once * update: clang-format config * feature: git-hook for format * fix: target `clang-format` * refactor: reapply updated clang-format config * update: bump version to 0.1.17 * fix: clang-format version selector Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
- Loading branch information
Showing
718 changed files
with
4,827 additions
and
4,018 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
# | ||
# Copyright Quadrivium LLC | ||
# All Rights Reserved | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
BasedOnStyle: Google | ||
NamespaceIndentation: All | ||
BreakBeforeBinaryOperators: NonAssignment | ||
AlignOperands: false | ||
AlignOperands: AlignAfterOperator | ||
DerivePointerAlignment: false | ||
PointerAlignment: Right | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
AllowShortFunctionsOnASingleLine: Empty | ||
AllowShortIfStatementsOnASingleLine: false | ||
IncludeBlocks: Preserve | ||
#InsertBraces: true | ||
InsertBraces: true | ||
InsertTrailingCommas: Wrapped | ||
SortIncludes: CaseSensitive | ||
QualifierAlignment: Custom | ||
QualifierOrder: ['inline', 'static', 'constexpr', 'const', 'volatile', 'type', 'restrict'] | ||
ReferenceAlignment: Right | ||
# uncomment in clang-format-16 | ||
#RemoveSemicolon: true | ||
#InsertNewlineAtEOF: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[//]: # ( | ||
Copyright Quadrivium LLC | ||
All Rights Reserved | ||
SPDX-License-Identifier: Apache-2.0 | ||
) | ||
|
||
# Git Hooks | ||
|
||
This folder _might_ contain some git-hooks to execute various checkup in Kagome. | ||
|
||
To activate presented (_and all future_) hooks just execute **once** shell-script [activate_hooks.sh](./activate_hooks.sh) from Kagome project root path. | ||
|
||
## pre-commit | ||
|
||
This hook check existing `clang-format` and `cmake-format` and their versions. | ||
If they have recommended version, specific checkup is enabled. | ||
|
||
Each changed C++ file (`.hpp` and `.cpp` extensions) gets processed by `clang-format`. | ||
|
||
Each changed CMake file (`CMakeLists.txt` and `.cmake` extension) gets processed by `cmake-format` | ||
|
||
Commit will be blocked while there are any differences between original files and `clang-format/cmake-format` output files. | ||
|
||
## etc. | ||
|
||
_Other hooks might be provided by maintainers in the future._ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright Quadrivium LLC | ||
# All Rights Reserved | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
GIT=$(which git) | ||
|
||
if [ -z "${GIT}" ]; then | ||
echo "Command ``git'' command not found" | ||
exit 1 | ||
fi | ||
|
||
cd "$(dirname "$0")/.." || (echo "Run script from file" | exit 1) | ||
|
||
chmod +x .githooks/* | ||
|
||
${GIT} config --local core.hooksPath .githooks || (echo "Hooks activation has failed" | exit 1) | ||
|
||
echo "Hooks activated successfully" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright Quadrivium LLC | ||
# All Rights Reserved | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1; then | ||
BASE=HEAD | ||
else | ||
# Initial commit: diff BASE an empty tree object | ||
BASE=$(git hash-object -t tree /dev/null) | ||
fi | ||
|
||
# check clang-format binary | ||
CLANG_FORMAT_ENABLED=1 | ||
CLANG_FORMAT=$(which clang-format-15) | ||
if [ -z "${CLANG_FORMAT}" ]; then | ||
CLANG_FORMAT=$(which clang-format) | ||
if [ -z "${CLANG_FORMAT}" ]; then | ||
echo "Command clang-format is not found" >&2 | ||
echo "Please, install clang-format version 15 to enable checkup C++-files formatting over git pre-commit hook" >&2 | ||
CLANG_FORMAT_ENABLED=0 | ||
fi | ||
fi | ||
|
||
# check clang-format version | ||
if [ $CLANG_FORMAT_ENABLED ]; then | ||
CLANG_FORMAT_VERSION=$($CLANG_FORMAT --version | sed -r "s/.*version ([[:digit:]]+).*/\1/") | ||
|
||
if [ "$CLANG_FORMAT_VERSION" != "15" ]; then | ||
echo "Please, install clang-format version 15 to enable checkup C++-files formatting over git pre-commit hook" >&2 | ||
CLANG_FORMAT_ENABLED=0 | ||
fi | ||
fi | ||
|
||
FILES=$(git diff --staged --diff-filter=ACMR --name-only) | ||
|
||
# check c++ files' format with clang-format | ||
CXX_RES=0 | ||
if [ $CLANG_FORMAT_ENABLED ]; then | ||
# for FILE in $(git diff-index --name-only "${BASE}" --diff-filter=ACMR | grep -e "\\.[ch]pp$"); do | ||
for FILE in $(echo "$FILES" | grep -e "\\.[ch]pp$"); do | ||
O_HASH=$(shasum <"${FILE}") | ||
F_HASH=$(${CLANG_FORMAT} --style=file "$FILE" | shasum) | ||
if [ "${O_HASH}" != "${F_HASH}" ]; then | ||
echo "File looks nonformatted: $FILE" | ||
CXX_RES=1 | ||
fi | ||
done | ||
|
||
if [ $CXX_RES = 1 ]; then | ||
CLANG_FORMAT_VERSION_FULL=$($CLANG_FORMAT --version | sed -r "s/.*version ([[:digit:]\.]+).*/\1/") | ||
echo "Used clang-format version $CLANG_FORMAT_VERSION_FULL" >&2 | ||
fi | ||
fi | ||
|
||
## check cmake-format binary | ||
#CMAKE_FORMAT_ENABLED=1 | ||
#CMAKE_FORMAT=$(which cmake-format) | ||
#if [ -z "${CMAKE_FORMAT}" ]; then | ||
# echo "Command cmake-format is not found" >&2 | ||
# echo "Please, install cmake-format version 15 to enable checkup cmake-files formatting over git pre-commit hook" >&2 | ||
# CMAKE_FORMAT_ENABLED=0 | ||
#fi | ||
# | ||
## check cmake-files' format with cmake-format | ||
#CMAKE_RES=0 | ||
#if [ $CMAKE_FORMAT_ENABLED ]; then | ||
# for FILE in $(echo "$FILES" | grep -e "\(\(CMakeLists\\.txt\)\|\(\\.cmake\)\)$"); do | ||
# O_HASH=$(shasum <"${FILE}") | ||
# F_HASH=$(${CMAKE_FORMAT} "$FILE" | shasum) | ||
# if [ "${O_HASH}" != "${F_HASH}" ]; then | ||
# echo "File looks nonformatted: $FILE" | ||
# CMAKE_RES=1 | ||
# fi | ||
# done | ||
# | ||
# if [ $CMAKE_RES = 1 ]; then | ||
# CMAKE_FORMAT_VERSION_FULL=$($CMAKE_FORMAT --version) | ||
# echo "Used cmake-format version $CMAKE_FORMAT_VERSION_FULL" >&2 | ||
# fi | ||
#fi | ||
|
||
# result of checks | ||
if [ "$CXX_RES" = "1" ] || [ "$CMAKE_RES" = "1" ]; then | ||
echo "Formatter required" >&2 | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.