[libcamera-devel,v2,1/2] libcamera: Add clang-format style

Message ID 20190121180128.1261-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,v2,1/2] libcamera: Add clang-format style
Related show

Commit Message

Laurent Pinchart Jan. 21, 2019, 6:01 p.m. UTC
The initial clang-format options are copied from the Linux kernel style,
with the following differences:

- Use C++11
- Remove the line length limit (to keep the original line breaks)
- Don't indent access modifiers
- Allow short inline functions on a single line
- Move braces to next line after class definition
- Keep braces on the line of the namespace definition
- Replace for-each macros

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .clang-format | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 .clang-format

Comments

Kieran Bingham Jan. 22, 2019, 10:27 a.m. UTC | #1
Hi Laurent,

On 21/01/2019 18:01, Laurent Pinchart wrote:
> The initial clang-format options are copied from the Linux kernel style,
> with the following differences:
> 
> - Use C++11
> - Remove the line length limit (to keep the original line breaks)
> - Don't indent access modifiers
> - Allow short inline functions on a single line
> - Move braces to next line after class definition
> - Keep braces on the line of the namespace definition
> - Replace for-each macros
> 

I approve of this - it gives us so much more control than astyle...

I've done some initial testing, putting this through my branches - and
it gives good results. Some things are picked up which aren't picked up
by astyle, which is to be expected.

for example, spaces are now added between while and (), which I actually
think is reasonable:

                timeout.start(5000);
-               while(timeout.isRunning()) {
+               while (timeout.isRunning()) {
                        dispatcher->processEvents();

Especially as it picked up this:

-       while( ioctl(fd_, VIDIOC_ENUM_FMT, &fmt) == 0 ) {
+       while (ioctl(fd_, VIDIOC_ENUM_FMT, &fmt) == 0) {

which looks nicer.


Initialiser lists are forced to a new line, which might be ok, but also
note that hugging of the empty function ... I might have left that space
in there at least...


-       CaptureAsync() : frames(0) {};
+       CaptureAsync()
+               : frames(0){};


Hugging of casts (I like this one too),

I think we can adapt things as we go along though rather than stall this.

Ship it! The sooner this goes in the easier it will be to migrate.

Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  .clang-format | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 119 insertions(+)
>  create mode 100644 .clang-format
> 
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 000000000000..17eb095bde71
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,119 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# clang-format configuration file. Intended for clang-format >= 4.
> +#
> +# For more information, see:
> +#
> +#   Documentation/process/clang-format.rst
> +#   https://clang.llvm.org/docs/ClangFormat.html
> +#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> +#
> +---
> +AccessModifierOffset: -8
> +AlignAfterOpenBracket: Align
> +AlignConsecutiveAssignments: false
> +AlignConsecutiveDeclarations: false
> +#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
> +AlignOperands: true
> +AlignTrailingComments: false
> +AllowAllParametersOfDeclarationOnNextLine: false
> +AllowShortBlocksOnASingleLine: false
> +AllowShortCaseLabelsOnASingleLine: false
> +AllowShortFunctionsOnASingleLine: Inline
> +AllowShortIfStatementsOnASingleLine: false
> +AllowShortLoopsOnASingleLine: false
> +AlwaysBreakAfterDefinitionReturnType: None
> +AlwaysBreakAfterReturnType: None
> +AlwaysBreakBeforeMultilineStrings: false
> +AlwaysBreakTemplateDeclarations: false
> +BinPackArguments: true
> +BinPackParameters: true
> +BraceWrapping:
> +  AfterClass: true
> +  AfterControlStatement: false
> +  AfterEnum: false
> +  AfterFunction: true
> +  AfterNamespace: false
> +  AfterObjCDeclaration: false
> +  AfterStruct: false
> +  AfterUnion: false
> +  #AfterExternBlock: false # Unknown to clang-format-5.0
> +  BeforeCatch: false
> +  BeforeElse: false
> +  IndentBraces: false
> +  #SplitEmptyFunction: true # Unknown to clang-format-4.0
> +  #SplitEmptyRecord: true # Unknown to clang-format-4.0
> +  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
> +BreakBeforeBinaryOperators: None
> +BreakBeforeBraces: Custom
> +#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
> +BreakBeforeTernaryOperators: false
> +BreakConstructorInitializersBeforeComma: false
> +#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
> +BreakAfterJavaFieldAnnotations: false
> +BreakStringLiterals: false
> +ColumnLimit: 0
> +CommentPragmas: '^ IWYU pragma:'
> +#CompactNamespaces: false # Unknown to clang-format-4.0
> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> +ConstructorInitializerIndentWidth: 8
> +ContinuationIndentWidth: 8
> +Cpp11BracedListStyle: false
> +DerivePointerAlignment: false
> +DisableFormat: false
> +ExperimentalAutoDetectBinPacking: false
> +#FixNamespaceComments: false # Unknown to clang-format-4.0
> +ForEachMacros:
> +  - 'udev_list_entry_foreach'
> +#IncludeBlocks: Preserve # Unknown to clang-format-5.0
> +IncludeCategories:
> +  - Regex: '.*'
> +    Priority: 1
> +IncludeIsMainRegex: '(_test)?$'
> +IndentCaseLabels: false
> +#IndentPPDirectives: None # Unknown to clang-format-5.0
> +IndentWidth: 8
> +IndentWrappedFunctionNames: false
> +JavaScriptQuotes: Leave
> +JavaScriptWrapImports: true
> +KeepEmptyLinesAtTheStartOfBlocks: false
> +MacroBlockBegin: ''
> +MacroBlockEnd: ''
> +MaxEmptyLinesToKeep: 1
> +NamespaceIndentation: Inner
> +#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
> +ObjCBlockIndentWidth: 8
> +ObjCSpaceAfterProperty: true
> +ObjCSpaceBeforeProtocolList: true
> +
> +# Taken from git's rules
> +#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
> +PenaltyBreakBeforeFirstCallParameter: 30
> +PenaltyBreakComment: 10
> +PenaltyBreakFirstLessLess: 0
> +PenaltyBreakString: 10
> +PenaltyExcessCharacter: 100
> +PenaltyReturnTypeOnItsOwnLine: 60
> +
> +PointerAlignment: Right
> +ReflowComments: false
> +SortIncludes: false
> +#SortUsingDeclarations: false # Unknown to clang-format-4.0
> +SpaceAfterCStyleCast: false
> +SpaceAfterTemplateKeyword: true
> +SpaceBeforeAssignmentOperators: true
> +#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
> +#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
> +SpaceBeforeParens: ControlStatements
> +#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
> +SpaceInEmptyParentheses: false
> +SpacesBeforeTrailingComments: 1
> +SpacesInAngles: false
> +SpacesInContainerLiterals: false
> +SpacesInCStyleCastParentheses: false
> +SpacesInParentheses: false
> +SpacesInSquareBrackets: false
> +Standard: Cpp11
> +TabWidth: 8
> +UseTab: Always
> +...
>
Niklas Söderlund Jan. 22, 2019, 11:24 a.m. UTC | #2
Hi Laurent,

On 2019-01-21 20:01:27 +0200, Laurent Pinchart wrote:
> The initial clang-format options are copied from the Linux kernel style,
> with the following differences:
> 
> - Use C++11
> - Remove the line length limit (to keep the original line breaks)
> - Don't indent access modifiers
> - Allow short inline functions on a single line
> - Move braces to next line after class definition
> - Keep braces on the line of the namespace definition
> - Replace for-each macros
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  .clang-format | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 119 insertions(+)
>  create mode 100644 .clang-format
> 
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 000000000000..17eb095bde71
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,119 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# clang-format configuration file. Intended for clang-format >= 4.
> +#
> +# For more information, see:
> +#
> +#   Documentation/process/clang-format.rst
> +#   https://clang.llvm.org/docs/ClangFormat.html
> +#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> +#
> +---
> +AccessModifierOffset: -8
> +AlignAfterOpenBracket: Align
> +AlignConsecutiveAssignments: false
> +AlignConsecutiveDeclarations: false
> +#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
> +AlignOperands: true
> +AlignTrailingComments: false
> +AllowAllParametersOfDeclarationOnNextLine: false
> +AllowShortBlocksOnASingleLine: false
> +AllowShortCaseLabelsOnASingleLine: false
> +AllowShortFunctionsOnASingleLine: Inline
> +AllowShortIfStatementsOnASingleLine: false
> +AllowShortLoopsOnASingleLine: false
> +AlwaysBreakAfterDefinitionReturnType: None
> +AlwaysBreakAfterReturnType: None
> +AlwaysBreakBeforeMultilineStrings: false
> +AlwaysBreakTemplateDeclarations: false
> +BinPackArguments: true
> +BinPackParameters: true
> +BraceWrapping:
> +  AfterClass: true
> +  AfterControlStatement: false
> +  AfterEnum: false
> +  AfterFunction: true
> +  AfterNamespace: false
> +  AfterObjCDeclaration: false
> +  AfterStruct: false
> +  AfterUnion: false
> +  #AfterExternBlock: false # Unknown to clang-format-5.0
> +  BeforeCatch: false
> +  BeforeElse: false
> +  IndentBraces: false
> +  #SplitEmptyFunction: true # Unknown to clang-format-4.0
> +  #SplitEmptyRecord: true # Unknown to clang-format-4.0
> +  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
> +BreakBeforeBinaryOperators: None
> +BreakBeforeBraces: Custom
> +#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
> +BreakBeforeTernaryOperators: false
> +BreakConstructorInitializersBeforeComma: false
> +#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
> +BreakAfterJavaFieldAnnotations: false
> +BreakStringLiterals: false
> +ColumnLimit: 0
> +CommentPragmas: '^ IWYU pragma:'
> +#CompactNamespaces: false # Unknown to clang-format-4.0
> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> +ConstructorInitializerIndentWidth: 8
> +ContinuationIndentWidth: 8
> +Cpp11BracedListStyle: false
> +DerivePointerAlignment: false
> +DisableFormat: false
> +ExperimentalAutoDetectBinPacking: false
> +#FixNamespaceComments: false # Unknown to clang-format-4.0
> +ForEachMacros:
> +  - 'udev_list_entry_foreach'
> +#IncludeBlocks: Preserve # Unknown to clang-format-5.0
> +IncludeCategories:
> +  - Regex: '.*'
> +    Priority: 1
> +IncludeIsMainRegex: '(_test)?$'
> +IndentCaseLabels: false
> +#IndentPPDirectives: None # Unknown to clang-format-5.0
> +IndentWidth: 8
> +IndentWrappedFunctionNames: false
> +JavaScriptQuotes: Leave
> +JavaScriptWrapImports: true
> +KeepEmptyLinesAtTheStartOfBlocks: false
> +MacroBlockBegin: ''
> +MacroBlockEnd: ''
> +MaxEmptyLinesToKeep: 1
> +NamespaceIndentation: Inner
> +#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
> +ObjCBlockIndentWidth: 8
> +ObjCSpaceAfterProperty: true
> +ObjCSpaceBeforeProtocolList: true
> +
> +# Taken from git's rules
> +#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
> +PenaltyBreakBeforeFirstCallParameter: 30
> +PenaltyBreakComment: 10
> +PenaltyBreakFirstLessLess: 0
> +PenaltyBreakString: 10
> +PenaltyExcessCharacter: 100
> +PenaltyReturnTypeOnItsOwnLine: 60
> +
> +PointerAlignment: Right
> +ReflowComments: false
> +SortIncludes: false
> +#SortUsingDeclarations: false # Unknown to clang-format-4.0
> +SpaceAfterCStyleCast: false
> +SpaceAfterTemplateKeyword: true
> +SpaceBeforeAssignmentOperators: true
> +#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
> +#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
> +SpaceBeforeParens: ControlStatements
> +#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
> +SpaceInEmptyParentheses: false
> +SpacesBeforeTrailingComments: 1
> +SpacesInAngles: false
> +SpacesInContainerLiterals: false
> +SpacesInCStyleCastParentheses: false
> +SpacesInParentheses: false
> +SpacesInSquareBrackets: false
> +Standard: Cpp11
> +TabWidth: 8
> +UseTab: Always
> +...
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000000..17eb095bde71
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,119 @@ 
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 4.
+#
+# For more information, see:
+#
+#   Documentation/process/clang-format.rst
+#   https://clang.llvm.org/docs/ClangFormat.html
+#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -8
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: true
+  AfterControlStatement: false
+  AfterEnum: false
+  AfterFunction: true
+  AfterNamespace: false
+  AfterObjCDeclaration: false
+  AfterStruct: false
+  AfterUnion: false
+  #AfterExternBlock: false # Unknown to clang-format-5.0
+  BeforeCatch: false
+  BeforeElse: false
+  IndentBraces: false
+  #SplitEmptyFunction: true # Unknown to clang-format-4.0
+  #SplitEmptyRecord: true # Unknown to clang-format-4.0
+  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 0
+CommentPragmas: '^ IWYU pragma:'
+#CompactNamespaces: false # Unknown to clang-format-4.0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+#FixNamespaceComments: false # Unknown to clang-format-4.0
+ForEachMacros:
+  - 'udev_list_entry_foreach'
+#IncludeBlocks: Preserve # Unknown to clang-format-5.0
+IncludeCategories:
+  - Regex: '.*'
+    Priority: 1
+IncludeIsMainRegex: '(_test)?$'
+IndentCaseLabels: false
+#IndentPPDirectives: None # Unknown to clang-format-5.0
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: Inner
+#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+#SortUsingDeclarations: false # Unknown to clang-format-4.0
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
+#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
+SpaceBeforeParens: ControlStatements
+#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Always
+...