[libcamera-devel] [RFC PATCH] clang-format: Regroup sort orders

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Jul 16 17:16:42 CEST 2021


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 at 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(-)

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
-- 
2.30.2



More information about the libcamera-devel mailing list