[libcamera-devel] [PATCH 3/4] utils: checkstyle.py: Add include checker

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Oct 23 15:52:57 CEST 2019


---
 utils/checkstyle.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 42a96f6d6102..335e58f5fddf 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -240,6 +240,38 @@ class StyleIssue(object):
         self.msg = msg
 
 
+class IncludeChecker(StyleChecker):
+    patterns = ('*.cpp', '*.h')
+
+    headers = ('assert', 'ctype', 'errno', 'fenv', 'float', 'inttypes',
+               'limits', 'locale', 'math', 'setjmp', 'signal', 'stdarg',
+               'stddef', 'stdint', 'stdio', 'stdlib', 'string', 'time', 'uchar',
+               'wchar', 'wctype')
+    include_regex = re.compile('^#include <c([a-z]*)>')
+
+    def __init__(self, content):
+        super().__init__()
+        self.__content = content
+
+    def check(self, line_numbers):
+        issues = []
+
+        for line_number in line_numbers:
+            line = self.__content[line_number - 1]
+            match = IncludeChecker.include_regex.match(line)
+            if not match:
+                continue
+
+            header = match.group(1)
+            if header not in IncludeChecker.headers:
+                continue
+
+            issues.append(StyleIssue(line_number, line,
+                                     'C compatibility header <%s.h> is preferred' % header))
+
+        return issues
+
+
 class LogCategoryChecker(StyleChecker):
     log_regex = re.compile('\\bLOG\((Debug|Info|Warning|Error|Fatal)\)')
     patterns = ('*.cpp',)
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list