{"id":3554,"url":"https://patchwork.libcamera.org/api/1.1/patches/3554/?format=json","web_url":"https://patchwork.libcamera.org/patch/3554/","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":"<20200427031713.14013-3-laurent.pinchart@ideasonboard.com>","date":"2020-04-27T03:17:04","name":"[libcamera-devel,02/11] libcamera: utils: Add a function to retrieve the libcamera source tree","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9aa5f0b97bfb5c1ba2ec3015d6a0fc8faf72c9aa","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3554/mbox/","series":[{"id":831,"url":"https://patchwork.libcamera.org/api/1.1/series/831/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=831","date":"2020-04-27T03:17:02","name":"libcamera: Add support for IPA configuration","version":1,"mbox":"https://patchwork.libcamera.org/series/831/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3554/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3554/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 A19FB601B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2020 05:17:33 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E4BF98D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2020 05:17:33 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jkmQwApG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1587957453;\n\tbh=uYFqjtDHmx0Sd0s9U3QQN1xno33zpkPgGM26TlOWy3I=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=jkmQwApGZvCGBSLNiQmOKFsipfBg2xQZ9Ea16hHUoalLogrnpaqygxNahCsRerYvO\n\taZZ7dKsT9KHoCv+NKu+Z8q5uL9dEu2YKTdH61HXlDblkCWzXpMsk3PbpMOasykubrg\n\tMUsYuPM8ko/M+K+Q1JF2XbYxHaqtxI3FAS4outFE=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 27 Apr 2020 06:17:04 +0300","Message-Id":"<20200427031713.14013-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","In-Reply-To":"<20200427031713.14013-1-laurent.pinchart@ideasonboard.com>","References":"<20200427031713.14013-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 02/11] libcamera: utils: Add a function to\n\tretrieve the libcamera source tree","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":"Mon, 27 Apr 2020 03:17:33 -0000"},"content":"Similarly to libcameraBuildPath(), there's a need to locate resources\nwithin the source tree when running libcamera without installing it.\nSupport this use case with a new utils::libcameraSourcePath() function.\n\nThe implementation currently leaks the path to the source tree in the\ninstalled binary. The data is put in a separate section named .zero\nwhich will need to be zeroed at installation time to fix this.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n meson.build                   |  2 ++\n src/libcamera/include/utils.h |  1 +\n src/libcamera/utils.cpp       | 37 ++++++++++++++++++++++++++++++++---\n 3 files changed, 37 insertions(+), 3 deletions(-)","diff":"diff --git a/meson.build b/meson.build\nindex c6e6a934e54e..2058a6a77ceb 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -26,6 +26,8 @@ libcamera_version = libcamera_git_version.split('+')[0]\n cc = meson.get_compiler('c')\n config_h = configuration_data()\n \n+config_h.set('LIBCAMERA_SOURCE_DIR', '\"' + meson.current_source_dir() + '\"')\n+\n if cc.has_header_symbol('execinfo.h', 'backtrace')\n     config_h.set('HAVE_BACKTRACE', 1)\n endif\ndiff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex 242eeded9d50..3334ff16613d 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -188,6 +188,7 @@ private:\n details::StringSplitter split(const std::string &str, const std::string &delim);\n \n std::string libcameraBuildPath();\n+std::string libcameraSourcePath();\n \n } /* namespace utils */\n \ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex 97f9b632e45b..056a67e93e0f 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -360,9 +360,10 @@ bool isLibcameraInstalled()\n  *\n  * During development, it is useful to run libcamera binaries directly from the\n  * build directory without installing them. This function helps components that\n- * need to locate resources, such as IPA modules or IPA proxy workers, by\n- * providing them with the path to the root of the build directory. Callers can\n- * then use it to complement or override searches in system-wide directories.\n+ * need to locate resources in the build tree, such as IPA modules or IPA proxy\n+ * workers, by providing them with the path to the root of the build directory.\n+ * Callers can then use it to complement or override searches in system-wide\n+ * directories.\n  *\n  * If libcamera has been installed, the build directory path is not available\n  * and this function returns an empty string.\n@@ -385,6 +386,36 @@ std::string libcameraBuildPath()\n \treturn dirname(info.dli_fname) + \"/../../\";\n }\n \n+namespace {\n+/* \\todo Figure out a way to zero this section at install time */\n+__attribute__((section(\".zero\")))\n+const char sourceDirectory[] = LIBCAMERA_SOURCE_DIR;\n+} /* namespace */\n+\n+/**\n+ * \\brief Retrieve the path to the source directory\n+ *\n+ * During development, it is useful to run libcamera binaries directly from the\n+ * build directory without installing them. This function helps components that\n+ * need to locate resources in the source tree, such as IPA configuration\n+ * files, by providing them with the path to the root of the source directory.\n+ * Callers can then use it to complement or override searches in system-wide\n+ * directories.\n+ *\n+ * If libcamera has been installed, the source directory path is not available\n+ * and this function returns an empty string.\n+ *\n+ * \\return The path to the source directory if running from a build, or an empty\n+ * string otherwise\n+ */\n+std::string libcameraSourcePath()\n+{\n+\tif (isLibcameraInstalled())\n+\t\treturn std::string();\n+\n+\treturn std::string(sourceDirectory) + \"/\";\n+}\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","02/11"]}