From 61eddca39dca58777f941a4c401904f98c7f6070 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 12 Aug 2016 20:20:03 +0200 Subject: [PATCH] clang format: preliminary support Add a .clang-format example file. Might need minor tuning. If people doesn't like the syntax Add a basic script to validate current change is compliant with clang-format * on master it will test last 20 commits * on branch it will test all commits of the branch Idea is to plug it into travis (might require clang 3.8). Everything is blacklisted. Use "ALL" parameters to test all standard directories. --- .clang-format | 77 +++++++++++++++++++++++++++++++++++ linux_various/check_format.sh | 66 ++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .clang-format create mode 100755 linux_various/check_format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..ca1fc84be3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,77 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: true +ColumnLimit: 0 +CommentPragmas: '^ (IWYU pragma:|NOLINT)' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ForEachMacros: [] +IncludeCategories: + - Regex: '^"(stdafx|PrecompiledHeader)' + Priority: -2 + - Regex: '^".*Common' + Priority: -1 + - Regex: '^<' + Priority: 1 + - Regex: '^"' + Priority: 2 +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 3 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/linux_various/check_format.sh b/linux_various/check_format.sh new file mode 100755 index 0000000000..4ba79deb68 --- /dev/null +++ b/linux_various/check_format.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +ret=0 + +branch=`git rev-parse --abbrev-ref HEAD` +if [ x$branch = "xmaster" ] +then + # check the last 20 commits. It ought to be enough even for big push + diff_range=HEAD~20 +else + # check filed updated in the branch + diff_range="master...HEAD" +fi + +# get updates and blacklist directories that don't use yet the clang-format syntax +files=`git diff $diff_range --name-only --diff-filter=ACMRT | \ + grep "\.\(c\|h\|inl\|cpp\|hpp\)$" | \ + grep -v "${1}common/" | \ + grep -v "${1}pcsx2/" | \ + grep -v "${1}plugins/cdvdGigaherz/" | \ + grep -v "${1}plugins/CDVDiso/" | \ + grep -v "${1}plugins/CDVDisoEFP/" | \ + grep -v "${1}plugins/CDVDlinuz/" | \ + grep -v "${1}plugins/CDVDnull/" | \ + grep -v "${1}plugins/CDVDolio/" | \ + grep -v "${1}plugins/CDVDpeops/" | \ + grep -v "${1}plugins/dev9ghzdrk/" | \ + grep -v "${1}plugins/dev9null/" | \ + grep -v "${1}plugins/FWnull/" | \ + grep -v "${1}plugins/GSdx/" | \ + grep -v "${1}plugins/GSdx_legacy/" | \ + grep -v "${1}plugins/GSnull/" | \ + grep -v "${1}plugins/LilyPad/" | \ + grep -v "${1}plugins/onepad/" | \ + grep -v "${1}plugins/PadNull/" | \ + grep -v "${1}plugins/PeopsSPU2/" | \ + grep -v "${1}plugins/SPU2null/" | \ + grep -v "${1}plugins/spu2-x/" | \ + grep -v "${1}plugins/SSSPSXPAD/" | \ + grep -v "${1}plugins/USBnull/" | \ + grep -v "${1}plugins/USBqemu/" | \ + grep -v "${1}plugins/xpad/" | \ + grep -v "${1}plugins/zerogs/" | \ + grep -v "${1}plugins/zerospu2/" | \ + grep -v "${1}plugins/zzogl-pg/" | \ + \ + grep -v "3rdpary/" | \ + grep -v "bin/" | \ + grep -v "cmake/" | \ + grep -v "tools/" | \ + grep -v "tests/" | \ + grep -v "unfree/" +` + +# Check remaining files are clang-format compliant +for f in $files +do + clang-format -style=file -output-replacements-xml $f | grep "/dev/null + if [ $? -ne 1 ] + then + echo "file $f did not match clang-format" + ret=1; + fi +done + +exit $ret;