From patchwork Wed Oct 23 13:52:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2213 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6AAF06138F for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 11169A24 for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1571838841; bh=DxRBXOFYmDhQwqHU0Iuu5vpN/Q10ulADw5PZNF8qoR8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YSHoydqyje2yDzp5wH6YDFSf/BtFqj62g7pkcBYfuCdahMnzpgwPZdROjPtxW4Flu oo5eNDn35K5J9p2Vk6Qub0R0thTZQ7ypzPhExEgVWRXftCFSDSI00yuQDlZU4RqUNV 1Fx5shRa+he/GsO11IeB2z4FPstWob7tgmt84rVM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Oct 2019 16:52:57 +0300 Message-Id: <20191023135258.32256-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> References: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] utils: checkstyle.py: Add include checker X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Oct 2019 13:54:01 -0000 --- utils/checkstyle.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) Signed-off-by: Laurent Pinchart Reviewed-by: <...insert tag here...> 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 ') + + 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',)