From patchwork Thu Dec 24 12:28:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10744 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 540C3C0F1A for ; Thu, 24 Dec 2020 12:29:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C220615AF; Thu, 24 Dec 2020 13:29:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YqrcMpaE"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A86C7615AF for ; Thu, 24 Dec 2020 13:29:10 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 47E92FE0 for ; Thu, 24 Dec 2020 13:29:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608812950; bh=yD71QmB73qmX72gSMLoN0LKZWfl2nUJ+FCw9LcubTDw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YqrcMpaEHiBabiUDKcqM2kPMM+NlCqVTDNDGOv6RjvsAEyYHPb7KX3KmTB97oA4Fe CCoBpgD9q1/RWeHingsFsimTNhkp6ECCk5m+MHZutf6mB/70YhNdWq9adOMIQqT+Hq ho89Uqmb0tdvjVR1NYtpjYFlPjCcK/y2E/0Yiiqo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Dec 2020 14:28:55 +0200 Message-Id: <20201224122855.22200-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201224122855.22200-1-laurent.pinchart@ideasonboard.com> References: <20201224122855.22200-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] utils: checkstyle.py: Add header add 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a commit checker that ensures that all header files added to the libcamera includes (public or internal) are accompanied by a corresponding update of the meson.build file in the same directory. Here's the output of the new checker when run against a commit that forgot to update meson.build. $ ./utils/checkstyle.py b3383da79f1d --------------------------------------------------------------------------------- b3383da79f1d513b0d76db220a7104e1c1035e30 libcamera: buffer: Create a MappedBuffer --------------------------------------------------------------------------------- Header include/libcamera/internal/buffer.h added without corresponding update to include/libcamera/internal/meson.build --- 1 potential issue detected, please review In theory we could extend the checker to cover .cpp files too, but the issue will be quite noticeable as meson won't build the file if meson.build isn't updated. Header files are more tricky as problems would only occur at when installing the headers (for public headers), or would result in race conditions in the build. Both of those issues are harder to catch. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- utils/checkstyle.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index c0a6b7ab06cd..e618db937c2b 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -320,6 +320,50 @@ class CommitIssue(object): self.msg = msg +class HeaderAddChecker(CommitChecker): + @classmethod + def check(cls, commit, top_level): + issues = [] + + meson_files = [f for f in commit.files('M') + if os.path.basename(f) == 'meson.build'] + + for filename in commit.files('A'): + if not filename.startswith('include/libcamera/') or \ + not filename.endswith('.h'): + continue + + meson = os.path.dirname(filename) + '/meson.build' + header = os.path.basename(filename) + + issue = CommitIssue('Header %s added without corresponding update to %s' % + (filename, meson)) + + if meson not in meson_files: + issues.append(issue) + continue + + diff = commit.get_diff(top_level, meson) + found = False + + for hunk in diff: + for line in hunk.lines: + if line[0] != '+': + continue + + if line.find("'%s'" % header) != -1: + found = True + break + + if found: + break + + if not found: + issues.append(issue) + + return issues + + # ------------------------------------------------------------------------------ # Style Checkers #