diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-23 16:10:26 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-23 17:12:34 +0300 |
commit | bb5f8cf4951fc5813d60ab806c57c5b5d713f38c (patch) | |
tree | 6aec757b18fd5d15b8e060564c338bfc73772a37 /utils | |
parent | 73a11cbf78342ecc875709e92abacee165530823 (diff) |
utils: checkstyle.py: Add include checker
Add an include checker to verify usage of the C compatibility headers.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/checkstyle.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 42a96f6d..335e58f5 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',) |