Show a patch.

GET /api/1.1/patches/21526/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 21526,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21526/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21526/",
    "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": "<20241007095425.211158-4-stefan.klug@ideasonboard.com>",
    "date": "2024-10-07T09:54:07",
    "name": "[v2,3/7] utils: Add script to generate control_ids_debug.yaml",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7db98d12c87487e17c31ed212a87bd1ae1e03713",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21526/mbox/",
    "series": [
        {
            "id": 4661,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4661/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4661",
            "date": "2024-10-07T09:54:04",
            "name": "Add support for IPA debugging metadata",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4661/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21526/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21526/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 554B2C32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Oct 2024 09:54:45 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DAEAD63539;\n\tMon,  7 Oct 2024 11:54:44 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE63E63532\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Oct 2024 11:54:40 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:ba12:1296:516b:1122])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A77911111;\n\tMon,  7 Oct 2024 11:53:03 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BIjfnJiF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728294783;\n\tbh=n4SLJwD6XK6lTuOS7gyxMQ7vQzP/IusI2D3c6pPxqr0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BIjfnJiFJ1YdYVpq+6d6gmG/LH6sx2LFYBdamU3j3iIsyNMQzwdMjTFlrT0K8sgna\n\tbOX/8FojuL4S9aynQw0ZSRFS9oWGp1fWUhZHSIT5kxr6aUpsXl96ojy2hiS0ITGOPT\n\tQmGVAYLk8yddWcyTkammTgrQ4c+LfolAr+E+98O8=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v2 3/7] utils: Add script to generate control_ids_debug.yaml",
        "Date": "Mon,  7 Oct 2024 11:54:07 +0200",
        "Message-ID": "<20241007095425.211158-4-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241007095425.211158-1-stefan.klug@ideasonboard.com>",
        "References": "<20241007095425.211158-1-stefan.klug@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "For flexible debugging it is helpful to minimize the roundtrip time.\nThis script parses the sourcetree and looks for usages of\n\nset<type>(controls::debug::Something,\n\nand adds (or removes) the controls as necessary from the yaml\ndescription. It is meant to be used during development to ease the\ncreation of the correct yaml entries.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nChanges in v2:\n- Search only until the first comma of the set() call, to allow\n  linebreaks there.\n- Support ruamel.yaml as fallback\n- Rename output to ctrl_file\n- Add \"generated by\" comment in yaml file\n---\n utils/gen-debug-controls.py | 165 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 165 insertions(+)\n create mode 100755 utils/gen-debug-controls.py",
    "diff": "diff --git a/utils/gen-debug-controls.py b/utils/gen-debug-controls.py\nnew file mode 100755\nindex 000000000000..c5c4570ffd00\n--- /dev/null\n+++ b/utils/gen-debug-controls.py\n@@ -0,0 +1,165 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2024, Ideas on Board Inc.\n+#\n+# Author: Stefan Klug <stefan.klug@ideasonboard.com>\n+#\n+# This script looks for occurrences of the debug metadata controls in the source\n+# tree and updates src/libcamera/control_ids_debug.yaml accordingly. It is meant\n+# to be used during development to ease updating of the yaml file while\n+# debugging.\n+\n+import argparse\n+import logging\n+import os\n+import re\n+import sys\n+from dataclasses import dataclass\n+from pathlib import Path\n+\n+logger = logging.getLogger(__name__)\n+logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')\n+\n+try:\n+    import ruyaml\n+except:\n+    try:\n+        import ruamel.yaml as ruyaml\n+    except:\n+        logger.error(\n+            f'Failed to import ruyaml. Please install the ruyaml or the ruamel.yaml package.')\n+        sys.exit(1)\n+\n+@dataclass\n+class FoundMatch:\n+    file: os.PathLike\n+    whole_match: str\n+    line: int\n+    type: str\n+    name: str\n+    size: str = None\n+\n+\n+def get_control_name(control):\n+    k = list(control.keys())\n+    if len(k) != 1:\n+        raise Exception(f\"Can't handle control entry with {len(k)} keys\")\n+    return k[0]\n+\n+\n+def find_debug_controls(dir):\n+    extensions = ['.cpp', '.h']\n+    files = [p for p in dir.rglob('*') if p.suffix in extensions]\n+\n+    # The following regex was tested on\n+    # set<Span<type>>( controls::debug::something , static_cast<type>(var) )\n+    # set<>( controls::debug::something , static_cast<type>(var) )\n+    # set( controls::debug::something , static_cast<type> (var) )\n+    exp = re.compile(r'set'  # set function\n+                     # possibly followed by template param\n+                     r'(?:\\<((?:[^)(])*)\\>)?'\n+                     # referencing a debug control\n+                     r'\\(\\s*controls::debug::(\\w+)\\s*,'\n+                     )\n+    matches = []\n+    for p in files:\n+        with p.open('r') as f:\n+            for idx, line in enumerate(f):\n+                match = exp.search(line)\n+                if match:\n+                    m = FoundMatch(file=p, line=idx, type=match.group(1),\n+                                   name=match.group(2), whole_match=match.group(0))\n+                    if m.type is not None and m.type.startswith('Span'):\n+                        # simple span type detection treating the last word inside <> as type\n+                        r = re.match(r'Span<(?:.*\\s+)(.*)>', m.type)\n+                        m.type = r.group(1)\n+                        m.size = '[n]'\n+                    matches.append(m)\n+    return matches\n+\n+\n+def main(argv):\n+    parser = argparse.ArgumentParser(\n+        description='Automatically updates control_ids_debug.yaml',)\n+    args = parser.parse_args(argv[1:])\n+\n+    yaml = ruyaml.YAML()\n+    root_dir = Path(__file__).resolve().parent.parent\n+    ctrl_file = root_dir.joinpath('src/libcamera/control_ids_debug.yaml')\n+\n+    matches = find_debug_controls(root_dir.joinpath('src'))\n+\n+    doc = yaml.load(ctrl_file)\n+\n+    controls = doc['controls']\n+\n+    # create a map of names in the existing yaml for easier updating\n+    controls_map = {}\n+    for control in controls:\n+        for k, v in control.items():\n+            controls_map[k] = v\n+\n+    obsolete_names = list(controls_map.keys())\n+\n+    for m in matches:\n+        if not m.type:\n+            p = m.file.relative_to(Path.cwd(), walk_up=True)\n+            logger.warning(\n+                f'{p}:{m.line + 1}: Failed to deduce type from {m.whole_match} ... skipping')\n+            continue\n+\n+        p = m.file.relative_to(root_dir)\n+        desc = {'type': m.type,\n+                'description': f'Debug control {m.name} found in {p}:{m.line}'}\n+        if m.size is not None:\n+            desc['size'] = m.size\n+\n+        if m.name in controls_map:\n+            # Can't use == for modified check because of the special yaml dicts.\n+            update_needed = False\n+            if list(controls_map[m.name].keys()) != list(desc.keys()):\n+                update_needed = True\n+            else:\n+                for k, v in controls_map[m.name].items():\n+                    if v != desc[k]:\n+                        update_needed = True\n+                        break\n+\n+            if update_needed:\n+                logger.info(f\"Update control '{m.name}'\")\n+                controls_map[m.name].clear()\n+                controls_map[m.name].update(desc)\n+\n+            obsolete_names.remove(m.name)\n+        else:\n+            logger.info(f\"Add control '{m.name}'\")\n+            insert_before = len(controls)\n+            for idx, control in enumerate(controls):\n+                if get_control_name(control).lower() > m.name.lower():\n+                    insert_before = idx\n+                    break\n+            controls.insert(insert_before, {m.name: desc})\n+\n+    # Remove elements from controls without recreating the list (to keep comments etc.)\n+    idx = 0\n+    while idx < len(controls):\n+        name = get_control_name(controls[idx])\n+        if name in obsolete_names:\n+            logger.info(f\"Remove control '{name}'\")\n+            controls.pop(idx)\n+        else:\n+            idx += 1\n+\n+    with ctrl_file.open('w') as f:\n+        # ruyaml looses the copyright header\n+        f.write((\"# SPDX-License-Identifier: LGPL-2.1-or-later\\n\"\n+                 \"#\\n\"\n+                 \"# This file is generated by utils/gen-debug-controls.py\\n\"\n+                 \"#\\n\"))\n+        yaml.dump(doc, f)\n+\n+    return 0\n+\n+\n+if __name__ == '__main__':\n+    sys.exit(main(sys.argv))\n",
    "prefixes": [
        "v2",
        "3/7"
    ]
}