Patch Detail
Show a patch.
GET /api/1.1/patches/39/?format=api
{ "id": 39, "url": "https://patchwork.libcamera.org/api/1.1/patches/39/?format=api", "web_url": "https://patchwork.libcamera.org/patch/39/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<1544612976-27101-3-git-send-email-jacopo@jmondi.org>", "date": "2018-12-12T11:09:36", "name": "[libcamera-devel,v4,2/2] Documentation: Add style checker tool", "commit_ref": null, "pull_url": null, "state": "rejected", "archived": false, "hash": "905da63916995dab62583269e21375afdfff9ab3", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/39/mbox/", "series": [ { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/series/17/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=17", "date": "2018-12-12T11:09:34", "name": "Documentation: coding style and style checker tool", "version": 4, "mbox": "https://patchwork.libcamera.org/series/17/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/39/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/39/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FD9260B13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Dec 2018 12:09:55 +0100 (CET)", "from w540.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id DB09124001D;\n\tWed, 12 Dec 2018 11:09:54 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 12 Dec 2018 12:09:36 +0100", "Message-Id": "<1544612976-27101-3-git-send-email-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.7.4", "In-Reply-To": "<1544612976-27101-1-git-send-email-jacopo@jmondi.org>", "References": "<1544612976-27101-1-git-send-email-jacopo@jmondi.org>", "Subject": "[libcamera-devel] [PATCH v4 2/2] Documentation: Add style checker\n\ttool", "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": "Wed, 12 Dec 2018 11:09:55 -0000" }, "content": "Add the style checker tool 'checkstyle.sh' and add tool documentation section\nto 'coding-style.rst'.\n\nThe script is in a very early development stage, and it has been tested\nlocally only. Use this a starting point, as we might later consider\nre-implementing it in something that is not shell scripting (as Python, in\nexample).\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n Documentation/coding-style.rst | 45 +++++++++++++\n utils/checkstyle.sh | 141 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 186 insertions(+)\n create mode 100755 utils/checkstyle.sh", "diff": "diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst\nindex 4747927..c2f95c7 100644\n--- a/Documentation/coding-style.rst\n+++ b/Documentation/coding-style.rst\n@@ -78,3 +78,48 @@ C++-11-specific features:\n * General-purpose smart pointers (std::unique_ptr), deprecating std::auto_ptr\n Smart pointers, as well as shared pointers and weak pointers, shall not be\n overused.\n+\n+\n+Tools\n+-----\n+\n+Libcamera provides a style checker scripts that uses 'astyle', to ease\n+identification of style errors before patches gets submitted for review.\n+\n+Right now, these are the basic astyle options used by the project's code base:\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+Astyle works on full files, and modifies files in place unless instructed to\n+do differently. It can't serve directly as a style validator by operating\n+directly on patches. The libcamera project thus provides a 'checkstyle.sh'\n+script that wraps around git and astyle to get the changes recorded in the\n+top-most commit in the working tree and detect style errors.\n+\n+Here is a simple usage example:\n+\n+ * Do your file editing, then \"git add\" and \"git commit\" as usual.\n+ * Run 'checkstyle.sh' on your latest commit: be aware that 'checkstyle.sh'\n+ works on commits, so make sure your index is clean.\n+\n+To use the script simply run:\n+\n+.. code-block:: bash\n+\n+ $ ./utils/checkstyle.sh\n+\n+The tool outputs the differences between the code added by the last commit\n+and its astyled version, for all source files modified by the commit.\n+\n+Once the script doesn't report any difference, or when the reported\n+differences are false positives according to your best judgment, the patches\n+are ready to be submitted for review.\n+\n+Happy hacking, libcamera awaits your patches!\ndiff --git a/utils/checkstyle.sh b/utils/checkstyle.sh\nnew file mode 100755\nindex 0000000..7f52975\n--- /dev/null\n+++ b/utils/checkstyle.sh\n@@ -0,0 +1,141 @@\n+#!/bin/bash\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2018, Google Inc.\n+#\n+# Author: Jacopo Mondi <jacopo@jmondi.org>\n+#\n+# checkstyle.sh - A style checker script using astyle for the libcamera project\n+#\n+# The scripts makes use of the following tools, which are expected to be\n+# found in $PATH:\n+# - astyle\n+# - git\n+# - diff\n+# - colordiff\n+\n+ASTYLE=astyle\n+ASTYLE_OPT='-n --style=linux --indent=force-tab=8 --attach-namespaces\n+--attach-extern-c --pad-oper --align-pointer=name --align-reference=name\n+--max-code-length=120'\n+EXTDIFF=colordiff\n+INTDIFF=diff\n+GIT=git\n+TMP=/tmp/\n+\n+# Check for tools to be installed and available in $PATH\n+TOOL_LIST=\"$ASTYLE $EXTDIFF $INTDIFF $GIT\"\n+for T in $TOOL_LIST; do\n+\tif [ _$(which $T) = '_' ]; then\n+\t\techo $T \"missing or not in \\$PATH; please install it\"\n+\t\texit 1\n+\tfi\n+done\n+\n+COMMIT_MSG=$($GIT log --format=%s -n1)\n+FLIST=$($GIT diff-index --name-only HEAD^)\n+\n+echo \"Running $0 on commit: \\\"$COMMIT_MSG\\\"\"\n+echo\n+echo \"The commit modifies the following files:\"\n+for F in $FLIST; do echo $F; done\n+echo\n+\n+# Loop on every file modified by the last commit\n+for F in $FLIST; do\n+\trm $TMP/chstyle.* &> /dev/null\n+\tBASENAME=$(basename $F)\n+\tDIRNAME=$(dirname $F)\n+\n+\techo\n+\t# Skip style check on meson files\n+\tif [[ $BASENAME == \"meson.build\" ]]; then\n+\t\techo \"=================================================================\"\n+\t\techo \"skip checks on:\" $F\n+\t\techo \"it's a meson build file\"\n+\t\techo \"=================================================================\"\n+\t\tcontinue;\n+\tfi\n+\n+\t# Skip style check on hidden files\n+\tif [[ $BASENAME == '.'* ]]; then\n+\t\techo \"=================================================================\"\n+\t\techo \"skip checks on:\" $F\n+\t\techo \"it's an hidden file\"\n+\t\techo \"=================================================================\"\n+\t\tcontinue;\n+\tfi\n+\n+\t# Skip Documentation patches\n+\tif [[ $DIRNAME == 'Documentation' ]]; then\n+\t\techo \"=================================================================\"\n+\t\techo \"skip checks on:\" $F\n+\t\techo \"it's a Documentation file\"\n+\t\techo \"=================================================================\"\n+\t\tcontinue;\n+\tfi\n+\n+\t# Skip patches on utils/\n+\tif [[ $DIRNAME == 'utils' ]]; then\n+\t\techo \"=================================================================\"\n+\t\techo \"skip checks on:\" $F\n+\t\techo \"it's a utils/ script\"\n+\t\techo \"=================================================================\"\n+\t\tcontinue;\n+\tfi\n+\n+\techo \"=================================================================\"\n+\techo \"Checking style on file: \" $F\n+\n+\t$GIT show $F > $TMP/chstyle.patch\n+\tpatch -p1 -R < $TMP/chstyle.patch > /dev/null\n+\tif [[ ! -f \"$F\" ]]; then\n+\t\t# If the file has been added by the last commit, run astyle\n+\t\t# on it and report the differences\n+\t\techo\n+\t\techo \"Is $BASENAME introduced by this commit? It seems so...\"\n+\t\techo \"Now running astyle on the whole file: $BASENAME\"\n+\t\techo\n+\t\tpatch -p1 < $TMP/chstyle.patch > /dev/null\n+\t\t$ASTYLE $ASTYLE_OPT < $F > $TMP/chstyle.astylepre\n+\t\techo \"-----------------------------------------------------------------\"\n+\t\t$EXTDIFF $F $TMP/chstyle.astylepre\n+\t\techo \"-----------------------------------------------------------------\"\n+\t\techo\n+\t\techo \"If you see nothing here, it means the patch on this file is good!\"\n+\t\techo \"Otherwise, you may want to check what's wrong with this change\"\n+\t\techo \"=================================================================\"\n+\t\tcontinue\n+\tfi\n+\n+\t# Run astyle on the file -before- this commit, and then -after-\n+\t# Record the differences between the two to have the astyled version\n+\t# of the latest changes\n+\t$ASTYLE $ASTYLE_OPT < $F > $TMP/chstyle.astylepre\n+\tpatch -p1 < $TMP/chstyle.patch > /dev/null\n+\t$ASTYLE $ASTYLE_OPT < $F > $TMP/chstyle.astylepost\n+\t$INTDIFF $TMP/chstyle.astylepre $TMP/chstyle.astylepost \\\n+\t\t| grep -e '^[\\>\\<]' \\\n+\t\t| sed s/^[\\>\\<]\\ // > $TMP/chstyle.astylediff\n+\n+\t# Sanitize the content of the patch as recorded in the commit\n+\tgrep ^[+-] $TMP/chstyle.patch \\\n+\t\t| sed s/^[+-]// | sed /^[+-]\\.*/d > $TMP/chstyle.patchpost\n+\n+\t# Now compare the two: raw commit and its astyled version\n+\techo \"-----------------------------------------------------------------\"\n+\t$EXTDIFF -u $TMP/chstyle.patchpost /tmp/chstyle.astylediff\n+\techo \"-----------------------------------------------------------------\"\n+\techo\n+\techo \"If you see nothing here, it means the patch on this file is good!\"\n+\techo \"Otherwise, you may want to check what's wrong with this change\"\n+\techo \"=================================================================\"\n+done\n+\n+cat << _END_MSG\n+\n+-----------------------------------------------------------------\n+If checkstyle reports any difference you may want to check what's\n+wrong in your patch before submitting it, otherwise the patch\n+is ready to be sent out!\n+-----------------------------------------------------------------\n+_END_MSG\n", "prefixes": [ "libcamera-devel", "v4", "2/2" ] }