Show a patch.

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

{
    "id": 2862,
    "url": "https://patchwork.libcamera.org/api/patches/2862/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2862/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20200220165704.23600-4-kieran.bingham@ideasonboard.com>",
    "date": "2020-02-20T16:57:01",
    "name": "[libcamera-devel,v3,3/6] libcamera: ipa_manager: Allow recursive parsing",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "bea2ec2488d494ed15dbf597c341e767d3ffe32c",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2862/mbox/",
    "series": [
        {
            "id": 688,
            "url": "https://patchwork.libcamera.org/api/series/688/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=688",
            "date": "2020-02-20T16:56:58",
            "name": "Support loading IPAs from the build tree",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/688/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2862/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2862/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<kieran.bingham@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 A29F9625C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 Feb 2020 17:57:08 +0100 (CET)",
            "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1BAFC13C7;\n\tThu, 20 Feb 2020 17:57:08 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582217828;\n\tbh=eCzZCVbPvJRe29BE5V9Smwp7Xg7gFtgIKdPaBqmAaBk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=F5tZplKQTnEWtk9tOZufbdmuQGP6ilxnateEKbahBUIp5OrIgowdx8fbfXL19lCn+\n\tzda1H+upNNTAhtK3HwjudolaUFHLfcdLU/5IzQQcFCZnla7sOmA3AjnTbq7Jwz0JUS\n\tM7bkSaqoMofDzR+PTHBv1o5PGWCD1ZhKUpf/Wq6E=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu, 20 Feb 2020 16:57:01 +0000",
        "Message-Id": "<20200220165704.23600-4-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20200220165704.23600-1-kieran.bingham@ideasonboard.com>",
        "References": "<20200220165704.23600-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 3/6] libcamera: ipa_manager: Allow\n\trecursive parsing",
        "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>",
        "X-List-Received-Date": "Thu, 20 Feb 2020 16:57:08 -0000"
    },
    "content": "Provide an optional means to recurse into subdirectories to search for IPA\nlibraries. This allows IPAs contained within their own build directory\nto be resolved when loading from a non-installed build.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/ipa_manager.h |  6 ++-\n src/libcamera/ipa_manager.cpp       | 69 ++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 17 deletions(-)",
    "diff": "diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h\nindex 94d35d9062e4..5dca2c2a7d8d 100644\n--- a/src/libcamera/include/ipa_manager.h\n+++ b/src/libcamera/include/ipa_manager.h\n@@ -32,8 +32,10 @@ private:\n \tIPAManager();\n \t~IPAManager();\n \n-\tint addDir(const char *libDir);\n-\tint addPath(const char *path);\n+\tint parseDir(const char *libDir, std::vector<std::string> &files,\n+\t\t     unsigned int maxDepth);\n+\tint addDir(const char *libDir, unsigned int maxDepth = 0);\n+\tint addPath(const char *path, unsigned int maxDepth = 0);\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nindex d87f2221b00b..c30b4555290f 100644\n--- a/src/libcamera/ipa_manager.cpp\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -140,16 +140,20 @@ IPAManager *IPAManager::instance()\n }\n \n /**\n- * \\brief Load IPA modules from a directory\n- * \\param[in] libDir directory to search for IPA modules\n+ * \\brief Identify shared library objects within a directory\n+ * \\param[in] libDir The directory to search for IPA modules\n+ * \\param[in] files A vector of paths to shared object library files\n+ * \\param[in] maxDepth The maximum depth of sub-directories to parse\n  *\n- * This method tries to create an IPAModule instance for every shared object\n- * found in \\a libDir, and skips invalid IPA modules.\n+ * Search a directory for .so files, allowing recursion down to\n+ * subdirectories no further than the depth specified by \\a maxDepth.\n  *\n- * \\return Number of modules loaded by this call, or a negative error code\n- * otherwise\n+ * Discovered shared objects are added to the files vector.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n  */\n-int IPAManager::addDir(const char *libDir)\n+int IPAManager::parseDir(const char *libDir, std::vector<std::string> &files,\n+\t\t\t unsigned int maxDepth)\n {\n \tstruct dirent *ent;\n \tDIR *dir;\n@@ -158,30 +162,64 @@ int IPAManager::addDir(const char *libDir)\n \tif (!dir)\n \t\treturn -errno;\n \n-\tstd::vector<std::string> paths;\n \twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tif (ent->d_type == DT_DIR && maxDepth) {\n+\t\t\tif (strcmp(ent->d_name, \".\") == 0 ||\n+\t\t\t    strcmp(ent->d_name, \"..\") == 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tstd::string subdir = std::string(libDir) + \"/\" + ent->d_name;\n+\n+\t\t\t/* Recursion is limited to maxDepth. */\n+\t\t\tparseDir(subdir.c_str(), files, maxDepth - 1);\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tint offset = strlen(ent->d_name) - 3;\n \t\tif (offset < 0)\n \t\t\tcontinue;\n \t\tif (strcmp(&ent->d_name[offset], \".so\"))\n \t\t\tcontinue;\n \n-\t\tpaths.push_back(std::string(libDir) + \"/\" + ent->d_name);\n+\t\tfiles.push_back(std::string(libDir) + \"/\" + ent->d_name);\n \t}\n \tclosedir(dir);\n \n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Load IPA modules from a directory\n+ * \\param[in] libDir The directory to search for IPA modules\n+ * \\param[in] maxDepth The maximum depth of sub-directories to parse\n+ *\n+ * This method tries to create an IPAModule instance for every shared object\n+ * found in \\a libDir, and skips invalid IPA modules.\n+ *\n+ * \\return Number of modules loaded by this call, or a negative error code\n+ * otherwise\n+ */\n+int IPAManager::addDir(const char *libDir, unsigned int maxDepth)\n+{\n+\tstd::vector<std::string> files;\n+\n+\tint ret = parseDir(libDir, files, maxDepth);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n \t/* Ensure a stable ordering of modules. */\n-\tstd::sort(paths.begin(), paths.end());\n+\tstd::sort(files.begin(), files.end());\n \n \tunsigned int count = 0;\n-\tfor (const std::string &path : paths) {\n-\t\tIPAModule *ipaModule = new IPAModule(path);\n+\tfor (const std::string &file : files) {\n+\t\tIPAModule *ipaModule = new IPAModule(file);\n \t\tif (!ipaModule->isValid()) {\n \t\t\tdelete ipaModule;\n \t\t\tcontinue;\n \t\t}\n \n-\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << path << \"'\";\n+\t\tLOG(IPAManager, Debug) << \"Loaded IPA module '\" << file << \"'\";\n \n \t\tmodules_.push_back(ipaModule);\n \t\tcount++;\n@@ -193,6 +231,7 @@ int IPAManager::addDir(const char *libDir)\n /**\n  * \\brief Load IPA modules from a search path\n  * \\param[in] path The colon-separated list of directories to load IPA modules from\n+ * \\param[in] maxDepth The maximum number of sub-directories to parse\n  *\n  * This method tries to create an IPAModule instance for every shared object\n  * found in the directories listed in \\a path.\n@@ -200,7 +239,7 @@ int IPAManager::addDir(const char *libDir)\n  * \\return Number of modules loaded by this call, or a negative error code\n  * otherwise\n  */\n-int IPAManager::addPath(const char *path)\n+int IPAManager::addPath(const char *path, unsigned int maxDepth)\n {\n \tint ipaCount = 0;\n \n@@ -208,7 +247,7 @@ int IPAManager::addPath(const char *path)\n \t\tif (dir.empty())\n \t\t\tcontinue;\n \n-\t\tint ret = addDir(dir.c_str());\n+\t\tint ret = addDir(dir.c_str(), maxDepth);\n \t\tif (ret > 0)\n \t\t\tipaCount += ret;\n \t}\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "3/6"
    ]
}