Skip to content

Commit c352fba

Browse files
committed
Add a .clang_format file for Open MPI
This file works with clang-format --style=file to reformat code to match the style used in Open MPI. This type includes: - No tabs. They are not recommended for Open MPI and can often screw up the formatting. - Tab depth: 4. This is what is used throughout the Open MPI code base. - Max column width: 100. There currently is no standard for Open MPI but we should aim to use something reasonable. - Braces following function definitions occur un-indented on the following line. - Braces following other control statements occur on the same line as the control statement. - Spaces before open parentheses for control statements. No spaces otherwise. This is common accross the code base but not consistent. - Sort headers. Put _config headers before any other header. Followed by internal ("" headers), then system headers (<> headers). - Align consecutive macro definitions. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent c40537c commit c352fba

File tree

2 files changed

+203
-0
lines changed

2 files changed

+203
-0
lines changed

.clang-format

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# This file represents the coding style enforced by Open MPI. This file
2+
# is based on the long-held, but not enforced, guidelines from the
3+
# beginning of the project. We will be requiring that all code going
4+
# forward uses this style. To check your code before attempting to open
5+
# a PR install clang-format and run your commits through clang-format.
6+
#
7+
# To install clang-format:
8+
#
9+
# macOS:
10+
# Homebrew: brew install clang-format
11+
# Mac Ports: port install clang
12+
#
13+
# Linux:
14+
# debian/ubuntu/rasbian: apt-get install clang-format
15+
# redhat/fedora: yum install clang-format
16+
#
17+
# To run against your code changes:
18+
#
19+
# unstaged changes: git clang-format --style file -f
20+
# staged changes: git clang-format --style file
21+
#
22+
# For interactive add the -p option.
23+
#
24+
# To run against all of Open MPI:
25+
#
26+
# ./contrib/clang-format-ompi.sh
27+
#
28+
# This command is intended to be run only once.
29+
---
30+
Language: Cpp
31+
# BasedOnStyle: LLVM
32+
AccessModifierOffset: -2
33+
AlignAfterOpenBracket: Align
34+
AlignConsecutiveMacros: true
35+
AlignConsecutiveAssignments: false
36+
AlignConsecutiveBitFields: false
37+
AlignConsecutiveDeclarations: false
38+
AlignEscapedNewlines: Left
39+
AlignOperands: Align
40+
AlignTrailingComments: true
41+
AllowAllArgumentsOnNextLine: true
42+
AllowAllConstructorInitializersOnNextLine: true
43+
AllowAllParametersOfDeclarationOnNextLine: true
44+
AllowShortEnumsOnASingleLine: true
45+
AllowShortBlocksOnASingleLine: Never
46+
AllowShortCaseLabelsOnASingleLine: false
47+
AllowShortFunctionsOnASingleLine: All
48+
AllowShortLambdasOnASingleLine: All
49+
AllowShortIfStatementsOnASingleLine: Never
50+
AllowShortLoopsOnASingleLine: false
51+
AlwaysBreakAfterDefinitionReturnType: None
52+
AlwaysBreakAfterReturnType: None
53+
AlwaysBreakBeforeMultilineStrings: false
54+
AlwaysBreakTemplateDeclarations: MultiLine
55+
BinPackArguments: true
56+
BinPackParameters: true
57+
BraceWrapping:
58+
AfterCaseLabel: false
59+
AfterClass: false
60+
AfterControlStatement: Never
61+
AfterEnum: false
62+
AfterFunction: true
63+
AfterNamespace: false
64+
AfterObjCDeclaration: false
65+
AfterStruct: false
66+
AfterUnion: false
67+
AfterExternBlock: false
68+
BeforeCatch: false
69+
BeforeElse: false
70+
BeforeLambdaBody: false
71+
BeforeWhile: false
72+
IndentBraces: false
73+
SplitEmptyFunction: true
74+
SplitEmptyRecord: true
75+
SplitEmptyNamespace: true
76+
BreakBeforeBinaryOperators: None
77+
BreakBeforeBraces: Custom
78+
BreakBeforeInheritanceComma: false
79+
BreakInheritanceList: BeforeColon
80+
BreakBeforeTernaryOperators: true
81+
BreakConstructorInitializersBeforeComma: false
82+
BreakConstructorInitializers: BeforeColon
83+
BreakAfterJavaFieldAnnotations: false
84+
BreakStringLiterals: true
85+
ColumnLimit: 100
86+
CommentPragmas: '^ IWYU pragma:'
87+
CompactNamespaces: false
88+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
89+
ConstructorInitializerIndentWidth: 4
90+
ContinuationIndentWidth: 4
91+
Cpp11BracedListStyle: true
92+
DeriveLineEnding: true
93+
DerivePointerAlignment: false
94+
DisableFormat: false
95+
ExperimentalAutoDetectBinPacking: false
96+
FixNamespaceComments: true
97+
ForEachMacros:
98+
- foreach
99+
- Q_FOREACH
100+
- BOOST_FOREACH
101+
- BOOST_FOREACH
102+
- OPAL_LIST_FOREACH
103+
- OPAL_LIST_FOREACH_DECL
104+
- OPAL_LIST_FOREACH_SAFE
105+
- OPAL_LIST_FOREACH_REV
106+
- OPAL_LIST_FOREACH_SAFE_REV
107+
- OPAL_HASH_TABLE_FOREACH
108+
- OPAL_HASH_TABLE_FOREACH_PTR
109+
IncludeBlocks: Preserve
110+
IncludeCategories:
111+
# Ensure config includes always come first (opal_config.h, ompi_config.h, etc)
112+
- Regex: '^".*_config\.h"'
113+
Priority: -1
114+
# In-tree includes come next (after main include)
115+
- Regex: '^".*"'
116+
Priority: 2
117+
# System includes come last
118+
- Regex: '^<.*>'
119+
Priority: 3
120+
IncludeIsMainRegex: '(Test)?$'
121+
IncludeIsMainSourceRegex: ''
122+
IndentCaseLabels: false
123+
IndentCaseBlocks: false
124+
IndentGotoLabels: true
125+
IndentPPDirectives: AfterHash
126+
IndentExternBlock: AfterExternBlock
127+
IndentWidth: 4
128+
IndentWrappedFunctionNames: false
129+
InsertTrailingCommas: None
130+
JavaScriptQuotes: Leave
131+
JavaScriptWrapImports: true
132+
KeepEmptyLinesAtTheStartOfBlocks: true
133+
MacroBlockBegin: ''
134+
MacroBlockEnd: ''
135+
MaxEmptyLinesToKeep: 1
136+
NamespaceIndentation: None
137+
ObjCBinPackProtocolList: Auto
138+
ObjCBlockIndentWidth: 4
139+
ObjCBreakBeforeNestedBlockParam: true
140+
ObjCSpaceAfterProperty: false
141+
ObjCSpaceBeforeProtocolList: true
142+
PenaltyBreakAssignment: 300
143+
PenaltyBreakBeforeFirstCallParameter: 300
144+
PenaltyBreakComment: 300
145+
PenaltyBreakFirstLessLess: 120
146+
PenaltyBreakString: 1000
147+
PenaltyBreakTemplateDeclaration: 10
148+
PenaltyExcessCharacter: 1000000
149+
PenaltyReturnTypeOnItsOwnLine: 60
150+
PointerAlignment: Right
151+
ReflowComments: true
152+
SortIncludes: true
153+
SortUsingDeclarations: true
154+
SpaceAfterCStyleCast: true
155+
SpaceAfterLogicalNot: false
156+
SpaceAfterTemplateKeyword: true
157+
SpaceBeforeAssignmentOperators: true
158+
SpaceBeforeCpp11BracedList: false
159+
SpaceBeforeCtorInitializerColon: true
160+
SpaceBeforeInheritanceColon: true
161+
SpaceBeforeParens: ControlStatements
162+
SpaceBeforeRangeBasedForLoopColon: true
163+
SpaceInEmptyBlock: false
164+
SpaceInEmptyParentheses: false
165+
SpacesBeforeTrailingComments: 1
166+
SpacesInAngles: false
167+
SpacesInConditionalStatement: false
168+
SpacesInContainerLiterals: true
169+
SpacesInCStyleCastParentheses: false
170+
SpacesInParentheses: false
171+
SpacesInSquareBrackets: false
172+
SpaceBeforeSquareBrackets: false
173+
Standard: Latest
174+
StatementMacros:
175+
- Q_UNUSED
176+
- QT_REQUIRE_VERSION
177+
- BEGIN_C_DECLS
178+
- END_C_DECLS
179+
TabWidth: 8
180+
UseCRLF: false
181+
UseTab: Never
182+
WhitespaceSensitiveMacros:
183+
- _STRINGIZE
184+
- STRINGIZE
185+
- PP_STRINGIZE
186+
- BOOST_PP_STRINGIZE
187+
...
188+

contrib/clang-format-ompi.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running clang-format on code base..."
4+
5+
files=($(git ls-tree -r master --name-only | grep -v '3rd-party/' | grep -v 'contrib' | grep -e '.*\.[ch]$'))
6+
7+
for file in "${files[@]}" ; do
8+
if test "$1" = "-d" ; then
9+
echo "Would have formatted: ${file}"
10+
else
11+
clang-format --style=file --verbose -i "${file}"
12+
fi
13+
done
14+
15+
echo "Done"

0 commit comments

Comments
 (0)