Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
162 changes: 162 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
# BeforeLambdaBody: true
# BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true

BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^\s*(\*)?\s*\\.+'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
# EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(gtest|gmock)/.*'
Priority: 1

- Regex: '^<sc-memory/*.*'
Priority: 11

- Regex: '^"sc_*.*'
Priority: 21

- Regex: '.*'
Priority: 100
# IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Middle
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
# SpaceAroundPointerQualifiers: After/Both
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 2
UseTab: Never
...
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
# Expression flags change how the expression is interpreted.
flags: # optional, default is gm
# A error message which will be returned in case of an error.
error: "One of commit messages or PR title have incorrect formatting. Please read the documentation: https://github.com/ostis-dev/sc-machine/blob/master/docs/dev/pr.md"
error: "One of commit messages or PR title have incorrect formatting. Please read the documentation: https://github.com/ostis-ai/sc-machine/blob/main/docs/dev/pr.md"
# Setting this input to true will exclude the Pull Request title from the check.
excludeTitle: true # optional, default is false
# Setting this input to true will exclude the Pull Request description from the check.
Expand Down Expand Up @@ -67,6 +67,10 @@ jobs:
id: install_deps
run: scripts/install_deps_ubuntu.sh

- name: Checking the code with clang
run: |
./scripts/ci/check-formatting.sh

- name: Build
id: run_cmake
env:
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: clang-format-check
name: clang-format-check
exclude: (generated/|thidrparty/|scs/|/json)
entry: scripts/ci/check-formatting.sh
language: script
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ option (SC_KPM_SCP "Flag to build SCP module" OFF)
option (SC_BUILD_SCTP "Flag to turn on/off sctp protocol support" ON)
option (SC_BUILD_TESTS "Flag to build unit tests" OFF)
option (SC_COVERAGE "Flag to generate coverage report" OFF)
option (SC_CLANG_FORMAT_CODE "flag to add clangformat and clangformat_check targets" OFF)

# Coverage
if(${SC_COVERAGE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
endif()

if(${SC_CLANG_FORMAT_CODE})
include(${CMAKE_CURRENT_LIST_DIR}/cmake/ClangFormat.cmake)
endif()

if (${SC_BUILD_ARM64})
check_c_compiler_flag("-arch arm64" IS_ARM64_SUPPORTED)
if (${IS_ARM64_SUPPORTED})
Expand Down
70 changes: 70 additions & 0 deletions cmake/ClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright Tomas Zeman 2019-2020.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

function(prefix_clangformat_setup prefix)
if(NOT CLANGFORMAT_EXECUTABLE)
set(CLANGFORMAT_EXECUTABLE clang-format)
endif()

if(NOT EXISTS ${CLANGFORMAT_EXECUTABLE})
find_program(clangformat_executable_tmp ${CLANGFORMAT_EXECUTABLE})
if(clangformat_executable_tmp)
set(CLANGFORMAT_EXECUTABLE ${clangformat_executable_tmp})
unset(clangformat_executable_tmp)
else()
message(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborting")
endif()
endif()

foreach(clangformat_source ${ARGN})
get_filename_component(clangformat_source ${clangformat_source} ABSOLUTE)
list(APPEND clangformat_sources ${clangformat_source})
endforeach()

add_custom_target(${prefix}_clangformat
COMMAND
${CLANGFORMAT_EXECUTABLE}
-style=file
-fallback-style=none
-i
${clangformat_sources}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
)

add_custom_target(${prefix}_clangformat_check
COMMAND
${CLANGFORMAT_EXECUTABLE}
-style=file
-fallback-style=none
--Werror
--dry-run
${clangformat_sources}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Check formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
)

if(TARGET clangformat)
add_dependencies(clangformat ${prefix}_clangformat)
add_dependencies(clangformat_check ${prefix}_clangformat_check)
else()
add_custom_target(clangformat DEPENDS ${prefix}_clangformat)
add_custom_target(clangformat_check DEPENDS ${prefix}_clangformat_check)
endif()
endfunction()

function(clangformat_setup)
prefix_clangformat_setup(${PROJECT_NAME} ${ARGN})
endfunction()

function(target_clangformat_setup target)
get_target_property(target_sources ${target} SOURCES)
list(FILTER target_sources EXCLUDE REGEX \(.*/generated/.*|.*/scs/*.|.*/json/.*\))
prefix_clangformat_setup(${target} ${target_sources})
endfunction()
43 changes: 42 additions & 1 deletion docs/build/linux-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This instruction made for Ubuntu.
## Clone

```sh
git clone https://github.com/ostis-dev/sc-machine.git
git clone https://github.com/ostis-ai/sc-machine.git
cd sc-machine
```

Expand All @@ -25,3 +25,44 @@ cd build
cmake .. -DCMAKE_BUILD_TYPE=Release # use Debug for debug build
make
```

To build tests run:
```shell
cd sc-machine
mkdir build
cd build
cmake .. -DSC_BUILD_TESTS=ON -DSC_AUTO_TEST=ON -DSC_KPM_SCP=OFF
make
```

or:
```shell
cd sc-machine
./scripts/ci/make-tests.sh
```

## Code formatting with CLangFormat

To check code with CLangFormat run:
```shell
cd sc-machine
mkdir build
cd build
cmake .. -DSC_CLANG_FORMAT_CODE=ON
make clangformat_check
```

or
```shell
cd sc-machine
./scripts/ci/check-formatting.sh
```

To format code with CLangFormat run:
```shell
cd sc-machine
mkdir build
cd build
cmake .. -DSC_CLANG_FORMAT_CODE=ON
make clangformat
```
2 changes: 1 addition & 1 deletion docs/build/osx-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Clone

```sh
git clone https://github.com/ostis-dev/sc-machine.git
git clone https://github.com/ostis-ai/sc-machine.git
cd sc-machine
```

Expand Down
2 changes: 1 addition & 1 deletion docs/build/windows-build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Build with Visual Studio 2013:

* install [jre](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html)
* downlaod source code of [sc-machine](https://github.com/deniskoronchik/sc-machine).
* downlaod source code of [sc-machine](https://github.com/ostis-ai/sc-machine).
* Run cmake for Visual Studio 2013 with param `CMAKE_PREFIX_PATH=<path to QT>`. For example: `CMAKE_PREFIX_PATH=D:\Qt\5.5\msvc2013_64\)`
* Setup redis for Windows: [https://github.com/MSOpenTech/redis/releases](https://github.com/MSOpenTech/redis/releases)
12 changes: 10 additions & 2 deletions docs/dev/git-workflow.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
### Initialize
To initialize your repo do:
* make fork from `https://github.com/ostis-dev/sc-machine`
* make fork from `https://github.com/ostis-ai/sc-machine`
* clone your fork to your machine and prepare
```sh
git clone [email protected]:yourlogin/sc-machine.git
cd sc-machine
git config --global user.name "Your Name"
git config --global user.email [email protected]
git remote add upstream [email protected]:ostis-dev/sc-machine.git
git remote add upstream [email protected]:ostis-ai/sc-machine.git
```
### Update
To update your master from `upstream` use:
Expand Down Expand Up @@ -35,3 +35,11 @@ git rebase --abort

### Common rules
* use `git rebase` instead of `merge`. [More documentation about this command](https://git-scm.com/docs/git-rebase) This command just try to apply your commits (from current branch to commits in specified branch)

### Git hooks

To setup `pre-commit` hook run:
```shell
cd sc-machine
pre-commit install
```
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
termcolor
tornado
tornado
pre-commit
3 changes: 3 additions & 0 deletions sc-kpm/sc-agents-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ target_link_libraries(sc-agents-common sc-memory)
sc_codegen_ex(sc-agents-common ${SC_AGENTS_COMMON_SRC} "${SC_AGENTS_COMMON_SRC}/generated")
target_compile_definitions(sc-agents-common PRIVATE "-DSC_AGENTS_COMMON_SELF_BUILD")

if (${SC_CLANG_FORMAT_CODE})
target_clangformat_setup(sc-agents-common)
endif ()
Loading