[libcamera-devel,RFC] clang-format: Regroup sort orders
diff mbox series

Message ID 20210716151642.500178-1-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • [libcamera-devel,RFC] clang-format: Regroup sort orders
Related show

Commit Message

Kieran Bingham July 16, 2021, 3:16 p.m. UTC
Utilise the clang-format header sort to provide a regex based pattern
match for our header inclusion coding style.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
I used this mostly during the libcamera-base split, but it's worth
considering and perhaps adapting to see if it helps in general.

May still need some tweaking and adjustments - but here's the initial
version for anyone who wants to try it or even for us to integrate and
update as we identify any more cases or corners...

 .clang-format | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/.clang-format b/.clang-format
index 3a8a896e373d..5ecba901db15 100644
--- a/.clang-format
+++ b/.clang-format
@@ -66,10 +66,41 @@  ExperimentalAutoDetectBinPacking: false
 FixNamespaceComments: true
 ForEachMacros:
   - 'udev_list_entry_foreach'
-IncludeBlocks: Preserve
+SortIncludes: true
+IncludeBlocks: Regroup
 IncludeCategories:
-  - Regex: '.*'
-    Priority: 1
+  # Headers in <> with or without extension. (system libraries)
+  - Regex:           '<([A-Za-z0-9\-_])+.h>'
+    Priority:        1 
+  - Regex:           '<sys/.*>'
+    Priority:        1
+  # Linux headers, as a second group/subset of system headers
+  - Regex:           '<linux/.*>'
+    Priority:        2
+  # C++ library includes (no .h)
+  - Regex:           '<([A-Za-z0-9\-_])+>'
+    Priority:        3
+  # Headers for Base support
+  - Regex:           '<libcamera/base/private.h>'
+    Priority:        4
+  - Regex:           '<libcamera/base/([A-Za-z0-9])+.*>'
+    Priority:        5
+  # Headers for libcamera, which are not in a subdir (i.e. ipa/,internal/)
+  - Regex:           '<libcamera/([A-Za-z0-9\-_])+.h>'
+    Priority:        6
+  # IPA Interfaces
+  - Regex:           '<libcamera/ipa/([A-Za-z0-9])+.*>'
+    Priority:        7
+  # libcamera Internal headers in ""  
+  - Regex:           '"libcamera/internal/.*\.h"'
+    Priority:        8
+  # local modular includes
+  - Regex:           '".*/.*\.h"'
+    Priority:        9
+  # Other local headers "" with extension.
+  - Regex:           '"([A-Za-z0-9.\/-_])+"'
+    Priority:        10
+
 IncludeIsMainRegex: '(_test)?$'
 IndentCaseLabels: false
 IndentPPDirectives: None