{"id":559,"url":"https://patchwork.libcamera.org/api/patches/559/?format=json","web_url":"https://patchwork.libcamera.org/patch/559/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190212222557.8898-2-laurent.pinchart@ideasonboard.com>","date":"2019-02-12T22:25:57","name":"[libcamera-devel,2/2] utils: checkstyle: Catch LOG() usage without an explicit category","commit_ref":"5fb0ea016ce7d1347698b67e7e8f90b507495b65","pull_url":null,"state":"accepted","archived":false,"hash":"2bcff7ec6306130fc92aeb368d7edb267fd3b244","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/559/mbox/","series":[{"id":176,"url":"https://patchwork.libcamera.org/api/series/176/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=176","date":"2019-02-12T22:25:56","name":"[libcamera-devel,1/2] clang-format: Remove space after template","version":1,"mbox":"https://patchwork.libcamera.org/series/176/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/559/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/559/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 76C0D610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 23:26:04 +0100 (CET)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 074412CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 23:26:03 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550010364;\n\tbh=s5RcWrbP6c/JBJcuZKr46kbXrpc7Ng+YEfBig0CGDPo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=cvkxfDA4H4bSe/9cAkjplUN1VFQm5bJLhqXdTuhKTieU1/lpZJKFTLJV4M46GFkjF\n\tPGExiPeerhh5oykiZCca64KE8Rt3ZzxvNyAOEpK1ImOx+KTJM1lYtJ+GcnVSk34m6B\n\tUtA91XebWuykEWbi9rVDltIB3EupWz3eNI3Gfn7s=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 13 Feb 2019 00:25:57 +0200","Message-Id":"<20190212222557.8898-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.19.2","In-Reply-To":"<20190212222557.8898-1-laurent.pinchart@ideasonboard.com>","References":"<20190212222557.8898-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/2] utils: checkstyle: Catch LOG() usage\n\twithout an explicit category","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 12 Feb 2019 22:26:04 -0000"},"content":"Add support for checkers not related to code formatting to the\ncheckstyle.py script, and create a first checker that catches usage of\nthe LOG() macro without an explicit category.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 55 ++++++++++++++++++++++++++++++++++++++-------\n 1 file changed, 47 insertions(+), 8 deletions(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex f3005d1fbb52..9abd2687b1f9 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -146,7 +146,7 @@ class DiffHunk(object):\n             s += Colours.reset()\n             s += '\\n'\n \n-        return s\n+        return s[:-1]\n \n     def append(self, line):\n         if line[0] == ' ':\n@@ -229,6 +229,29 @@ available_formatters = {\n # Style checking\n #\n \n+class LogCategoryChecker(object):\n+    log_regex = re.compile('\\\\bLOG\\((Debug|Info|Warning|Error|Fatal)\\)')\n+\n+    def __init__(self, content):\n+        self.__content = content\n+\n+    def check(self, line_numbers):\n+        issues = []\n+        for line_number in line_numbers:\n+            line = self.__content[line_number-1]\n+            if not LogCategoryChecker.log_regex.search(line):\n+                continue\n+\n+            issues.append([line_number, line, 'LOG() should use categories'])\n+\n+        return issues\n+\n+\n+available_checkers = {\n+    'log_category': LogCategoryChecker,\n+}\n+\n+\n def check_file(top_level, commit, filename, formatters):\n     # Extract the line numbers touched by the commit.\n     diff = subprocess.run(['git', 'diff', '%s~..%s' % (commit, commit), '--',\n@@ -260,20 +283,36 @@ def check_file(top_level, commit, filename, formatters):\n     formatted = formatted.splitlines(True)\n     diff = difflib.unified_diff(after, formatted)\n \n-    # Split the diff in hunks, recording line number ranges for each hunk.\n+    # Split the diff in hunks, recording line number ranges for each hunk, and\n+    # filter out hunks that are not touched by the commit.\n     formatted_diff = parse_diff(diff)\n-\n-    # Filter out hunks that are not touched by the commit.\n     formatted_diff = [hunk for hunk in formatted_diff if hunk.intersects(lines)]\n-    if len(formatted_diff) == 0:\n+\n+    # Check for code issues not related to formatting.\n+    issues = []\n+    for checker in available_checkers:\n+        checker = available_checkers[checker](after)\n+        for hunk in commit_diff:\n+            issues += checker.check(hunk.side('to').touched)\n+\n+    # Print the detected issues.\n+    if len(issues) == 0 and len(formatted_diff) == 0:\n         return 0\n \n     print('%s---' % Colours.fg(Colours.Red), filename)\n     print('%s+++' % Colours.fg(Colours.Green), filename)\n-    for hunk in formatted_diff:\n-        print(hunk)\n \n-    return len(formatted_diff)\n+    if len(formatted_diff):\n+        for hunk in formatted_diff:\n+            print(hunk)\n+\n+    if len(issues):\n+        issues.sort()\n+        for issue in issues:\n+            print('%s#%u: %s' % (Colours.fg(Colours.Yellow), issue[0], issue[2]))\n+            print('+%s%s' % (issue[1].rstrip(), Colours.reset()))\n+\n+    return len(formatted_diff) + len(issues)\n \n \n def check_style(top_level, commit, formatters):\n","prefixes":["libcamera-devel","2/2"]}