{"id":10745,"url":"https://patchwork.libcamera.org/api/1.1/patches/10745/?format=json","web_url":"https://patchwork.libcamera.org/patch/10745/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20201224123510.22453-1-laurent.pinchart@ideasonboard.com>","date":"2020-12-24T12:35:10","name":"[libcamera-devel] utils: checkstyle.py: Drop astyle support","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7ebf0a3ab1e0099a63fdfba37c6cd31cd8bb0a22","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/10745/mbox/","series":[{"id":1551,"url":"https://patchwork.libcamera.org/api/1.1/series/1551/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1551","date":"2020-12-24T12:35:10","name":"[libcamera-devel] utils: checkstyle.py: Drop astyle support","version":1,"mbox":"https://patchwork.libcamera.org/series/1551/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10745/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10745/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9EDFDC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Dec 2020 12:35:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 009B3615AF;\n\tThu, 24 Dec 2020 13:35:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 46A3E60528\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Dec 2020 13:35:22 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B843DA1D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Dec 2020 13:35:21 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gCua/640\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1608813321;\n\tbh=ttgh5yc0tTecK/sjI9hpizAYXA57nTWUIjH0smDqbSA=;\n\th=From:To:Subject:Date:From;\n\tb=gCua/640kMcIlPOdnSGn73yfS7aRVtW0VC2DO+hdwn7SKIedp6kGklzkDGyEyjTAR\n\tIDWaeN5CoPYC17pgI5PzcrZER5dCWGnI7vAXwTWZkfcsMfp3QDdbadyBudkgU9XjKy\n\tSJ/Vas+S7j5yOMmtgLSv/tvb6LCXYudf8cZ+9r94=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 24 Dec 2020 14:35:10 +0200","Message-Id":"<20201224123510.22453-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH] utils: checkstyle.py: Drop astyle support","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Formatting code using astyle doesn't lead to results as good as with\nclang-format, and doesn't receive much test coverage ass most developers\nuse clang-format. The code is thus bitrotting. Drop it.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n Documentation/coding-style.rst | 34 +++++----------------\n utils/checkstyle.py            | 54 ++--------------------------------\n 2 files changed, 9 insertions(+), 79 deletions(-)","diff":"diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst\nindex 71d5c0b2e842..dd1ac00113c8 100644\n--- a/Documentation/coding-style.rst\n+++ b/Documentation/coding-style.rst\n@@ -279,32 +279,16 @@ between the \\fn, \\brief, \\param and \\return directives.\n Tools\n -----\n \n-The 'clang-format' code formatting tool can be used to reformat source files\n+The 'clang-format' code formatting tool is be used to reformat source files\n with the libcamera coding style, defined in the .clang-format file at the root\n of the source tree.\n \n-Alternatively the 'astyle' tool can also be used, with the following arguments.\n-\n-::\n-\n-  --style=linux\n-  --indent=force-tab=8\n-  --attach-namespaces\n-  --attach-extern-c\n-  --pad-oper\n-  --align-pointer=name\n-  --align-reference=name\n-  --max-code-length=120\n-\n-Use of astyle is discouraged as clang-format better matches the libcamera coding\n-style.\n-\n-As both astyle and clang-format are code formatters, they operate on full files\n-and output reformatted source code. While they can be used to reformat code\n-before sending patches, it may generate unrelated changes. To avoid this,\n-libcamera provides a 'checkstyle.py' script wrapping the formatting tools to\n-only retain related changes. This should be used to validate modifications\n-before submitting them for review.\n+As clang-format is a code formatter, it operates on full files and outputs\n+reformatted source code. While it can be used to reformat code before sending\n+patches, it may generate unrelated changes. To avoid this, libcamera provides a\n+'checkstyle.py' script wrapping the formatting tools to only retain related\n+changes. This should be used to validate modifications before submitting them\n+for review.\n \n The script operates on one or multiple git commits specified on the command\n line. It does not modify the git tree, the index or the working directory and\n@@ -393,8 +377,4 @@ diff that fixes the issues, on top of the corresponding commit. As the script is\n in early development false positive are expected. The flagged issues should be\n reviewed, but the diff doesn't need to be applied blindly.\n \n-The checkstyle.py script uses clang-format by default if found, and otherwise\n-falls back to astyle. The formatter can be manually selected with the\n-'--formatter' argument.\n-\n Happy hacking, libcamera awaits your patches!\ndiff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex e618db937c2b..0e9659e98518 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -4,7 +4,7 @@\n #\n # Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n #\n-# checkstyle.py - A patch style checker script based on astyle or clang-format\n+# checkstyle.py - A patch style checker script based on clang-format\n #\n # TODO:\n #\n@@ -22,22 +22,8 @@ import shutil\n import subprocess\n import sys\n \n-astyle_options = (\n-    '-n',\n-    '--style=linux',\n-    '--indent=force-tab=8',\n-    '--attach-namespaces',\n-    '--attach-extern-c',\n-    '--pad-oper',\n-    '--align-pointer=name',\n-    '--align-reference=name',\n-    '--keep-one-line-blocks',\n-    '--max-code-length=120'\n-)\n-\n dependencies = {\n-    'astyle': False,\n-    'clang-format': False,\n+    'clang-format': True,\n     'git': True,\n }\n \n@@ -550,7 +536,6 @@ class ShellChecker(StyleChecker):\n #\n \n class Formatter(metaclass=ClassRegistry):\n-    enabled = True\n     subclasses = []\n \n     def __init__(self):\n@@ -562,15 +547,11 @@ class Formatter(metaclass=ClassRegistry):\n     @classmethod\n     def formatters(cls, filename):\n         for formatter in cls.subclasses:\n-            if not cls.enabled:\n-                continue\n             if formatter.supports(filename):\n                 yield formatter\n \n     @classmethod\n     def supports(cls, filename):\n-        if not cls.enabled:\n-            return False\n         for pattern in cls.patterns:\n             if fnmatch.fnmatch(os.path.basename(filename), pattern):\n                 return True\n@@ -580,26 +561,12 @@ class Formatter(metaclass=ClassRegistry):\n     def all_patterns(cls):\n         patterns = set()\n         for formatter in cls.subclasses:\n-            if not cls.enabled:\n-                continue\n             patterns.update(formatter.patterns)\n \n         return patterns\n \n \n-class AStyleFormatter(Formatter):\n-    enabled = False\n-    patterns = ('*.c', '*.cpp', '*.h')\n-\n-    @classmethod\n-    def format(cls, filename, data):\n-        ret = subprocess.run(['astyle', *astyle_options],\n-                             input=data.encode('utf-8'), stdout=subprocess.PIPE)\n-        return ret.stdout.decode('utf-8')\n-\n-\n class CLangFormatter(Formatter):\n-    enabled = False\n     patterns = ('*.c', '*.cpp', '*.h')\n \n     @classmethod\n@@ -854,8 +821,6 @@ def main(argv):\n \n     # Parse command line arguments\n     parser = argparse.ArgumentParser()\n-    parser.add_argument('--formatter', '-f', type=str, choices=['astyle', 'clang-format'],\n-                        help='Code formatter. Default to clang-format if not specified.')\n     parser.add_argument('--staged', '-s', action='store_true',\n                         help='Include the changes in the index. Defaults to False')\n     parser.add_argument('--amend', '-a', action='store_true',\n@@ -873,21 +838,6 @@ def main(argv):\n \n         dependencies[command] = found\n \n-    if args.formatter:\n-        if not args.formatter in dependencies or \\\n-           not dependencies[args.formatter]:\n-            print(\"Formatter %s not available\" % args.formatter)\n-            return 1\n-        formatter = args.formatter\n-    else:\n-        if dependencies['clang-format']:\n-            CLangFormatter.enabled = True\n-        elif dependencies['astyle']:\n-            AStyleFormatter.enabled = True\n-        else:\n-            print(\"No formatter found, please install clang-format or astyle\")\n-            return 1\n-\n     # Get the top level directory to pass absolute file names to git diff\n     # commands, in order to support execution from subdirectories of the git\n     # tree.\n","prefixes":["libcamera-devel"]}