All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Shargo <jshargo@chromium.org>
To: Development mailing list for IGT GPU Tools
	<igt-dev@lists.freedesktop.org>,
	Petri Latvala <petri.latvala@intel.com>,
	Arkadiusz Hiler <arek@hiler.eu>
Cc: Jim Shargo <jshargo@chromium.org>
Subject: [igt-dev] [PATCH i-g-t v3] tooling: Add linux's .clang-format
Date: Thu, 28 Jul 2022 13:57:36 -0400	[thread overview]
Message-ID: <20220728175736.1893691-1-jshargo@chromium.org> (raw)
In-Reply-To: <YuJA8zCW9wFQh5M6@platvala-desk.ger.corp.intel.com>

As I was authoring my first patchset for IGT, I found myself fighting
the tooling a bit to get everything right. I had to add a bunch of extra
command line args to use my linux checkout's formatting rules to get the
style right.

I grabbed this from a recent checkout of torvald's repo.

The commit I used was: e0dccc3b76fb35bb257b4118367a883073d7390e

To make this discoverable to new contributors, this change also
updates CONTRIBUTING.md with:

  - A link to git-clang-format, which is a useful tool for using
  clang-format from git just on a commit's changes
  - A link to .editorconfig to make it more discoverable

Changes made to the linux kernel style:

  - Reflowing comments, including multi-line comments (ReflowComments)
  - Support for magic code blocks (ForEachMacros, IfMacros)

Signed-off-by: Jim Shargo <jshargo@chromium.org>
---
V2 -> V3: Update CONTRIBUTING.md with a note about .editorconfig,
          remove reference to .clang-format from the .editorconfig
V1 -> V2: Better support for IGT style and addressing comments

 .clang-format   | 176 ++++++++++++++++++++++++++++++++++++++++++++++++
 CONTRIBUTING.md |   9 ++-
 2 files changed, 182 insertions(+), 3 deletions(-)
 create mode 100644 .clang-format

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..da42bead
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,176 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+#   Documentation/process/clang-format.rst
+#   https://clang.llvm.org/docs/ClangFormat.html
+#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+# This file was pulled from the linux kernel at revision
+# e0dccc3b76fb35bb257b4118367a883073d7390e.
+#
+# Changes made for IGT-specific styles should include a comment noting
+# the previous value with "kernel-value". This makes it clear what we
+# want to keep when updating this file.
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: false
+  AfterControlStatement: false
+  AfterEnum: false
+  AfterFunction: true
+  AfterNamespace: true
+  AfterObjCDeclaration: false
+  AfterStruct: false
+  AfterUnion: false
+  AfterExternBlock: false
+  BeforeCatch: false
+  BeforeElse: false
+  IndentBraces: false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+#   git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
+#   | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$,  - '\1'," \
+#   | LC_ALL=C sort -u
+ForEachMacros: # kernel-value: (long list removed)
+  # IGT rules, found via:
+  # git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ lib/ |
+  #     sed "s,^#define \([^(]\+\).*,'\1'," |
+  #     grep -v "__" |
+  #     sort -u    
+  - 'for_each_collection_data'
+  - 'for_each_combination'
+  - 'for_each_connected_output'
+  - 'for_each_connector_mode'
+  - 'for_each_ctx_cfg_engine'
+  - 'for_each_ctx_engine'
+  - 'for_each_format'
+  - 'for_each_if'
+  - 'for_each_memory_region'
+  - 'for_each_mmap_offset_type'
+  - 'for_each_physical_engine'
+  - 'for_each_physical_ring'
+  - 'for_each_pipe'
+  - 'for_each_pipe_static'
+  - 'for_each_pipe_with_single_output'
+  - 'for_each_pipe_with_valid_output'
+  - 'for_each_plane_on_pipe'
+  - 'for_each_prime_number'
+  - 'for_each_ring'
+  - 'for_each_subset'
+  - 'for_each_sysfs_gt_dirfd'
+  - 'for_each_sysfs_gt_path'
+  - 'for_each_valid_output_on_pipe'
+  - 'for_each_variation_nr'
+  - 'for_each_variation_r'
+  - 'igt_list_for_each_entry'
+  - 'igt_list_for_each_entry_reverse'
+  - 'igt_list_for_each_entry_safe'
+  - 'igt_list_for_each_entry_safe_reverse'
+
+IfMacros: # kernel-value: none
+  - 'igt_dynamic'
+  - 'igt_fixture'
+  - 'igt_fork'
+  - 'igt_subtest'
+  - 'igt_subtest_f'
+  - 'igt_subtest_group'
+  - 'igt_subtest_with_dynamic'
+  - 'igt_subtest_with_dynamic_f'
+  - 'igt_until_timeout'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+  - Regex: '.*'
+    Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: true # kernel-value: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6d1294ad..f2af5a18 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,8 +10,10 @@ improvements for documentation and new tools and testcases.
 The Code
 --------
 
-- The code should follow kernel coding style:
-  https://www.kernel.org/doc/html/latest/process/coding-style.html
+- The code should follow [kernel coding style](coding-style). Before
+  sending out a patch, changes can be formatted with
+  [git-clang-format](git-clang-format). Editors can be configured
+  using .editorconfig for additional style support.
 
 - Testcases (subtests) have to use minus signs (-) as a word separator.
   The generated documentation contains glossary of commonly used terms.
@@ -30,9 +32,10 @@ The Code
   provided by the igt library. The semantic patch lib/igt.cocci can help with
   more automatic conversions.
 
+[coding-style]: https://www.kernel.org/doc/html/latest/process/coding-style.html
+[git-clang-format]: https://github.com/llvm-mirror/clang/blob/master/tools/clang-format/git-clang-format
 [igt-describe]: https://drm.pages.freedesktop.org/igt-gpu-tools/igt-gpu-tools-Core.html#igt-describe
 
-
 Sending Patches
 ---------------
 
-- 
2.37.1.455.g008518b4e5-goog

  parent reply	other threads:[~2022-07-28 17:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 19:01 [igt-dev] [PATCH i-g-t] tooling: Add linux's .clang-format Jim Shargo
2022-07-27 10:52 ` Petri Latvala
2022-07-27 20:10   ` Jim Shargo
2022-07-27 20:21   ` [igt-dev] [PATCH i-g-t v2] " Jim Shargo
2022-07-28  7:55     ` Petri Latvala
2022-07-28 17:55       ` Jim Shargo
2022-07-28 17:57       ` Jim Shargo [this message]
2022-08-12 12:53         ` [igt-dev] [PATCH i-g-t v3] " Petri Latvala
2022-08-12 16:00           ` Jim Shargo
2022-08-19 14:23             ` Jim Shargo
2022-08-23 11:01         ` Petri Latvala
2023-08-31 17:03         ` Mauro Carvalho Chehab
2022-07-29  9:21   ` [igt-dev] ✓ Fi.CI.BAT: success for tooling: Add linux's .clang-format (rev3) Patchwork
2022-07-29 10:38   ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2022-08-02 22:25     ` Jim Shargo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728175736.1893691-1-jshargo@chromium.org \
    --to=jshargo@chromium.org \
    --cc=arek@hiler.eu \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.