Skip to content

Commit 07d6bdc

Browse files
committed
feat: format the code with clang-format
The code currently mixes tab and space indenting. Having the code style defined into a file is usually good practice, as we can use tools to do it automatically. This change proposes use clang-format to do it. It provides predefined rules following LLVM/Google/Mozilla/GNU code style that can be tweaked. I try to create a .clang-format configuration that just fix the tab/space mix and keep the rest as-is as much I can. Currently all cpp/hpp/h are formatted except those in src/ext. The code formatting will be checked Jenkins. It also can be run with: `cmake .. && make clang-format` cmake also install automatically a pre-commit hook to format the code. It can be disabled with `INSTALL_GIT_HOOKS=OFF` llvm provide some basic integration for editor: https://clang.llvm.org/docs/ClangFormat.html#vim-integration https://clang.llvm.org/docs/ClangFormat.html#emacs-integration But you can also use other tools like: https://github.com/SavchenkoValeriy/emacs-clang-format-plus
1 parent c72327d commit 07d6bdc

File tree

162 files changed

+41264
-32493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+41264
-32493
lines changed

.clang-format

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveMacros: false
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Right
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllArgumentsOnNextLine: true
12+
AllowAllConstructorInitializersOnNextLine: true
13+
AllowAllParametersOfDeclarationOnNextLine: true
14+
AllowShortBlocksOnASingleLine: Never
15+
AllowShortCaseLabelsOnASingleLine: false
16+
AllowShortFunctionsOnASingleLine: None
17+
AllowShortLambdasOnASingleLine: All
18+
AllowShortIfStatementsOnASingleLine: Never
19+
AllowShortLoopsOnASingleLine: false
20+
AlwaysBreakAfterDefinitionReturnType: None
21+
AlwaysBreakAfterReturnType: None
22+
AlwaysBreakBeforeMultilineStrings: false
23+
AlwaysBreakTemplateDeclarations: MultiLine
24+
BinPackArguments: true
25+
BinPackParameters: true
26+
BraceWrapping:
27+
AfterCaseLabel: true
28+
AfterClass: true
29+
AfterControlStatement: true
30+
AfterEnum: true
31+
AfterFunction: true
32+
AfterNamespace: true
33+
AfterObjCDeclaration: true
34+
AfterStruct: true
35+
AfterUnion: true
36+
AfterExternBlock: true
37+
BeforeCatch: true
38+
BeforeElse: true
39+
IndentBraces: true
40+
SplitEmptyFunction: true
41+
SplitEmptyRecord: true
42+
SplitEmptyNamespace: true
43+
BreakBeforeBinaryOperators: All
44+
BreakBeforeBraces: GNU
45+
BreakBeforeInheritanceComma: false
46+
BreakInheritanceList: BeforeColon
47+
BreakBeforeTernaryOperators: true
48+
BreakConstructorInitializersBeforeComma: false
49+
BreakConstructorInitializers: BeforeColon
50+
BreakAfterJavaFieldAnnotations: false
51+
BreakStringLiterals: true
52+
ColumnLimit: 79
53+
CommentPragmas: '^ IWYU pragma:'
54+
CompactNamespaces: false
55+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
56+
ConstructorInitializerIndentWidth: 4
57+
ContinuationIndentWidth: 4
58+
Cpp11BracedListStyle: false
59+
DeriveLineEnding: true
60+
DerivePointerAlignment: false
61+
DisableFormat: false
62+
ExperimentalAutoDetectBinPacking: false
63+
FixNamespaceComments: false
64+
ForEachMacros:
65+
- foreach
66+
- Q_FOREACH
67+
- BOOST_FOREACH
68+
IncludeBlocks: Preserve
69+
IncludeCategories:
70+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
71+
Priority: 2
72+
SortPriority: 0
73+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
74+
Priority: 3
75+
SortPriority: 0
76+
- Regex: '.*'
77+
Priority: 1
78+
SortPriority: 0
79+
IncludeIsMainRegex: '(Test)?$'
80+
IncludeIsMainSourceRegex: ''
81+
IndentCaseLabels: false
82+
IndentGotoLabels: true
83+
IndentPPDirectives: None
84+
IndentWidth: 2
85+
IndentWrappedFunctionNames: false
86+
JavaScriptQuotes: Leave
87+
JavaScriptWrapImports: true
88+
KeepEmptyLinesAtTheStartOfBlocks: true
89+
MacroBlockBegin: ''
90+
MacroBlockEnd: ''
91+
MaxEmptyLinesToKeep: 1
92+
NamespaceIndentation: All
93+
ObjCBinPackProtocolList: Auto
94+
ObjCBlockIndentWidth: 2
95+
ObjCSpaceAfterProperty: false
96+
ObjCSpaceBeforeProtocolList: true
97+
PenaltyBreakAssignment: 2
98+
PenaltyBreakBeforeFirstCallParameter: 19
99+
PenaltyBreakComment: 300
100+
PenaltyBreakFirstLessLess: 120
101+
PenaltyBreakString: 1000
102+
PenaltyBreakTemplateDeclaration: 10
103+
PenaltyExcessCharacter: 1000000
104+
PenaltyReturnTypeOnItsOwnLine: 60
105+
PointerAlignment: Right
106+
ReflowComments: true
107+
SortIncludes: false
108+
SortUsingDeclarations: true
109+
SpaceAfterCStyleCast: false
110+
SpaceAfterLogicalNot: false
111+
SpaceAfterTemplateKeyword: true
112+
SpaceBeforeAssignmentOperators: true
113+
SpaceBeforeCpp11BracedList: false
114+
SpaceBeforeCtorInitializerColon: true
115+
SpaceBeforeInheritanceColon: true
116+
SpaceBeforeParens: ControlStatements
117+
SpaceBeforeRangeBasedForLoopColon: true
118+
SpaceInEmptyBlock: false
119+
SpaceInEmptyParentheses: false
120+
SpacesBeforeTrailingComments: 1
121+
SpacesInAngles: false
122+
SpacesInConditionalStatement: false
123+
SpacesInContainerLiterals: true
124+
SpacesInCStyleCastParentheses: false
125+
SpacesInParentheses: false
126+
SpacesInSquareBrackets: false
127+
SpaceBeforeSquareBrackets: false
128+
Standard: c++11
129+
StatementMacros:
130+
- Q_UNUSED
131+
- QT_REQUIRE_VERSION
132+
TabWidth: 8
133+
UseCRLF: false
134+
UseTab: Never
135+
...

CMakeLists.txt

+28
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,34 @@ if (BUILD_TOOLS)
10111011
add_subdirectory(tools)
10121012
endif()
10131013

1014+
# Get all project files
1015+
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.cpp src/*.hpp src/*.h src/*.c tests/*.cc src/*.cc)
1016+
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "^${CMAKE_SOURCE_DIR}/src/ext/.*$")
1017+
1018+
add_custom_target(
1019+
clang-format
1020+
COMMAND clang-format
1021+
-style=file
1022+
-i
1023+
${ALL_SOURCE_FILES}
1024+
)
1025+
add_custom_target(
1026+
clang-format-check
1027+
COMMAND clang-format
1028+
--dry-run
1029+
--Werror
1030+
--ferror-limit=10
1031+
-style=file
1032+
-i
1033+
${ALL_SOURCE_FILES}
1034+
)
1035+
1036+
option(INSTALL_GIT_HOOKS "install client side git hook" ON)
1037+
if (INSTALL_GIT_HOOKS)
1038+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/git-pre-commit-hook
1039+
${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit @ONLY)
1040+
endif()
1041+
10141042
# status
10151043
message(STATUS "Build Tests : ${BUILD_TESTS}")
10161044
message(STATUS "Caffe DEBUG : ${USE_CAFFE_DEBUG}")

Jenkinsfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export PATH="/usr/lib/ccache/:$PATH"
88
mkdir -p build
99
cd build
1010
cmake .. -DBUILD_TESTS=ON -DUSE_CUDNN=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_XGBOOST=ON -DUSE_TORCH=ON -DUSE_NCNN=ON -DUSE_TENSORRT=ON -DCUDA_ARCH="-gencode arch=compute_61,code=sm_61"
11+
make clang-format-check
1112
make -j24
1213
ccache -s
1314
'''

README.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ http://www.deepdetect.com/overview/examples/
200200
| | Caffe | Tensorflow | Source | Top-1 Accuracy (ImageNet) |
201201
|--------------------------|-------|------------|---------------|---------------------------|
202202
| AlexNet | Y | N | BVLC | 57.1% |
203-
| SqueezeNet | [Y](https://deepdetect.com/models/squeezenet/squeezenet_v1.1.caffemodel) | N | DeepScale | 59.5% |
203+
| SqueezeNet | [Y](https://deepdetect.com/models/squeezenet/squeezenet_v1.1.caffemodel) | N | DeepScale | 59.5% |
204204
| Inception v1 / GoogleNet | [Y](https://deepdetect.com/models/ggnet/bvlc_googlenet.caffemodel) | [Y](https://deepdetect.com/models/tf/inception_v1.pb) | BVLC / Google | 67.9% |
205205
| Inception v2 | N | [Y](https://deepdetect.com/models/tf/inception_v2.pb) | Google | 72.2% |
206206
| Inception v3 | N | [Y](https://deepdetect.com/models/tf/inception_v3.pb) | Google | 76.9% |
@@ -263,7 +263,7 @@ Beware of dependencies, typically on Debian/Ubuntu Linux, do:
263263
sudo apt-get install build-essential libgoogle-glog-dev libgflags-dev libeigen3-dev libopencv-dev libcppnetlib-dev libboost-dev libboost-iostreams-dev libcurlpp-dev libcurl4-openssl-dev protobuf-compiler libopenblas-dev libhdf5-dev libprotobuf-dev libleveldb-dev libsnappy-dev liblmdb-dev libutfcpp-dev cmake libgoogle-perftools-dev unzip python-setuptools python-dev libspdlog-dev python-six python-enum34 libarchive-dev
264264
```
265265

266-
#### Choosing interfaces :
266+
#### Choosing interfaces :
267267

268268
DeepDetect can be used:
269269
- directly from command line for caffe models. To build the executable use:
@@ -274,7 +274,7 @@ cmake .. -DUSE_COMMAND_LINE=ON
274274
```
275275
cmake .. -DUSE_COMMAND_LINE=ON -DUSE_JSON_API=ON
276276
```
277-
- as a REST server (using JSON API). To build the server executable use (`USE_JSON_API` is auto-selected):
277+
- as a REST server (using JSON API). To build the server executable use (`USE_JSON_API` is auto-selected):
278278
```
279279
cmake .. -DUSE_HTTP_SERVER=ON
280280
```
@@ -383,7 +383,7 @@ Specify the following option via cmake:
383383
```$xslt
384384
cmake .. -DUSE_TENSORRT=ON
385385
```
386-
TensorRT requires GPU and CUDNN, they are automatically switched on.
386+
TensorRT requires GPU and CUDNN, they are automatically switched on.
387387

388388
#### Build with TensorRT support + TRT oss parts
389389
Specify the following option via cmake:
@@ -442,6 +442,19 @@ Run tests with:
442442
ctest
443443
```
444444

445+
### Code Style Rules
446+
447+
`clang-format` is used to enforce code style.
448+
449+
You can automatically format it with:
450+
451+
```
452+
cmake ..
453+
make clang-format
454+
```
455+
456+
Or use your favorite editor with a clang-format plugin.
457+
445458
### Start the server
446459

447460
```
@@ -481,7 +494,7 @@ where `sname` is the service name and the JSON is a string without external quot
481494
- service prediction
482495
```
483496
service_predict;JSON string
484-
```
497+
```
485498

486499
### Pure command line JSON API
487500

@@ -502,7 +515,7 @@ where `<other options>` stands for the command line parameters from the command
502515
-service_train (/train POST call JSON string) type: string default: ""
503516
-service_train_delete (/train DELETE call JSON string) type: string default: ""
504517
-service_train_status (/train GET call JSON string) type: string default: ""
505-
518+
506519
```
507520

508521
The options above can be obtained from running

0 commit comments

Comments
 (0)