From be77dbbda692792335a8e9e7c02e0c281f003c40 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Wed, 22 Aug 2018 12:31:48 +0530 Subject: clang-format: add the config file Also update the required documents and scripts to enable clang-format Change-Id: I73aae6db06c2f732a1779d59a73bc05e28beafba updates: bz#1564149 Signed-off-by: Amar Tumballi --- .clang-format | 107 +++++++++++++++++++++++++++++++++ .gitignore | 1 + .testignore | 1 + doc/developer-guide/coding-standard.md | 24 ++++++++ rfc.sh | 19 +++++- 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000000..84c2efe3fad --- /dev/null +++ b/.clang-format @@ -0,0 +1,107 @@ +--- +Language: Cpp +# BasedOnStyle: Chromium +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: All +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 200 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 8 +UseTab: Never +... diff --git a/.gitignore b/.gitignore index 899758efe68..4b369515d3e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ test-driver # Softlinks to test and log log *.vol +.clang-format # cmocka unit tests *.log diff --git a/.testignore b/.testignore index 9e75d56a94a..cde29545b48 100644 --- a/.testignore +++ b/.testignore @@ -2,6 +2,7 @@ .gitignore .mailmap .testignore +.clang-format rfc.sh submit-for-review.sh AUTHORS diff --git a/doc/developer-guide/coding-standard.md b/doc/developer-guide/coding-standard.md index 9bc15a5cc15..7c1beddc2d5 100644 --- a/doc/developer-guide/coding-standard.md +++ b/doc/developer-guide/coding-standard.md @@ -1,6 +1,30 @@ GlusterFS Coding Standards ========================== +Before you get started +---------------------- +Before starting with other part of coding standard, install `clang-format` + +On Fedora: + +$ dnf install clang + +On debian/Ubuntu: + +$ apt-get install clang + +Once you are done with all the local changes, you need to run below set of commands, +before submitting the patch for review. + + $ git add $file # if any + $ git commit -a -s -m "commit message" + $ git show --pretty="format:" --name-only | grep -v "contrib/" | egrep "*\.[ch]$" | xargs clang-format -i + $ git diff # see if there are any changes + $ git commit -a --amend # get the format changes done + $ ./submit-for-review.sh + + + Structure definitions should have a comment per member ------------------------------------------------------ diff --git a/rfc.sh b/rfc.sh index 6947aa24231..607fd7528fb 100755 --- a/rfc.sh +++ b/rfc.sh @@ -303,7 +303,7 @@ main() return; fi - check_patches_for_coding_style; + # check_patches_for_coding_style rebase_changes; @@ -320,6 +320,23 @@ main() warn_reference_missing; fi + # TODO: add clang-format command here. It will after the changes are done everywhere else + clang_format=$(clang-format --version) + if [ ! -z "${clang_format}" ]; then + # Considering git show may not give any files as output matching the + # criteria, good to tell script not to fail on error + set +e + list_of_files=$(git show --pretty="format:" --name-only | + grep -v "contrib/" | egrep --color=never "*\.[ch]$"); + if [ ! -z "${list_of_files}" ]; then + echo "${list_of_files}" | xargs clang-format -i + fi + set -e + else + echo "High probability of your patch not passing smoke due to coding standard check" + echo "Please install 'clang-format' to format the patch before submitting" + fi + if [ "$DRY_RUN" = 1 ]; then drier='echo -e Please use the following command to send your commits to review:\n\n' else -- cgit