Skip to content
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
34 changes: 34 additions & 0 deletions .ci/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
LINUX_PACKAGES="make \
autoconf \
automake \
build-essential \
cargo \
curl \
git \
libtool \
ninja-build \
pkg-config \
python3.12 \
python3.12-dev \
python3.12-venv \
python3-pip \
unzip \
zip \
nano"

MACOS_PACKAGES="make \
autoconf \
automake \
rust \
curl \
git \
libtool \
ninja \
pkg-config \
[email protected] \
unzip \
zip"

CMAKE_VERSION=3.31.1
DEBIAN_FRONTEND=noninteractive
#VCPKG_FORCE_SYSTEM_BINARIES=1
23 changes: 23 additions & 0 deletions .ci/scripts/detect_os.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt >/dev/null 2>&1; then
echo "linux_deb"
else
echo "linux_other"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
else
echo "unknown"
fi
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: detect_os"
exit 1
fi
48 changes: 48 additions & 0 deletions .ci/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x
trap 'echo "=== Error on line $LINENO"; exit 1' ERR

SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
OS_SELECT=$(source ${SCRIPT_DIR}/detect_os.sh && detect_os)

set -o allexport && . ${SCRIPT_DIR}/../.env && set +o allexport

main() {
case "$OS_SELECT" in
linux_deb)
echo "=== Detected Linux system with apt"
apt update && apt install -y $LINUX_PACKAGES
if [ -f "$HOME/.cargo/env" ]; then
source "$HOME/.cargo/env"
fi
export PATH="$HOME/.cargo/bin:$PATH"
;;
linux_other)
echo "=== Detected Linux system without apt"
echo "=== Support for other package managers is not added"
;;
macos)
echo "=== Detected macOS system"
if command -v brew >/dev/null 2>&1; then
echo "=== Homebrew found. Installing packages..."
brew update && brew install $MACOS_PACKAGES
else
echo "=== Homebrew is not installed. Install it before proceeding: https://brew.sh"
fi
;;
*)
echo "=== Unknown system"
;;
esac

if command -v cargo >/dev/null 2>&1; then
echo "=== Cargo is available: $(cargo --version)"
else
echo "=== Warning: Cargo is not available in PATH"
fi
}

main

exit 0
17 changes: 17 additions & 0 deletions .ci/scripts/init_py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

init_py() {
echo "$VENV"
python3 -m venv "$VENV"
source $VENV/bin/activate
pip3 install cmake==${CMAKE_VERSION}
pip3 install --no-cache-dir asn1tools
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: init_py"
exit 1
fi
23 changes: 23 additions & 0 deletions .ci/scripts/init_vcpkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

init_vcpkg() {
if [[ ! -d $VCPKG || -z "$(ls -A $VCPKG 2>/dev/null)" ]]; then
echo "Directory $VCPKG does not exist or is empty. Cloning vcpkg..."
git clone https://github.com/microsoft/vcpkg.git $VCPKG
fi

if [[ ! -e $VCPKG/vcpkg ]]; then
echo "vcpkg executable not found. Bootstrapping vcpkg..."
$VCPKG/bootstrap-vcpkg.sh -disableMetrics
fi

echo "vcpkg is initialized at $VCPKG."
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: init_vcpkg"
exit 1
fi
91 changes: 91 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
# Copyright Quadrivium LLC
# All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#

Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ContinuationIndentWidth: 4
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^["<]MAIN_INCLUDE_FILE[">]$'
Priority: 1
- Regex: '^((<gtest/gtest\.h>)|(<gmock/gmock\.h>))$'
Priority: 2
- Regex: '^<[^/]*>$'
Priority: 3
- Regex: '^<.*>$'
Priority: 4
- Regex: '^".*"$'
Priority: 5
- Regex: '.*'
Priority: 6
IndentWidth: 2
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: Wrapped
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PointerAlignment: Right
QualifierAlignment: Custom
QualifierOrder:
- inline
- static
- constexpr
- const
- volatile
- type
- restrict
ReferenceAlignment: Right
ReflowComments: true
ShortNamespaceLines: 2
SortIncludes: CaseSensitive
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 2
...
27 changes: 27 additions & 0 deletions .githooks/README.md
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._

22 changes: 22 additions & 0 deletions .githooks/activate_hooks.sh
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
90 changes: 90 additions & 0 deletions .githooks/pre-commit_
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/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-16 2>/dev/null)
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 16 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" != "16" ]; then
echo "clang-format version 16 is recommended" >&2
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
Loading
Loading