summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaaira Gupta <kgupta@es.iitr.ac.in>2020-03-19 21:31:40 +0530
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-19 19:04:32 +0200
commit1b8ac8473c948ee7f5956ea0a71ad264a4485db4 (patch)
tree1bbf8a0df9e381f0a13572a81933a80e0be1d8d5
parent6c34a2d386ac99d3732147fe65d0a2cb69ec3856 (diff)
libcamera: utils: Adapt libcameraPath to match use cases
The two callers of functions libcameraPath() and isLibcameraInstalled() end up using the same process and finally use the path with libcamera.so. Hence write a function libcameraBuildPath() which combines their functions and returns the root of the build sources when the library has not been installed, but is running from the build tree, thereby making call sites simpler. When the library is installed, libcameraBuildPath() will return an empty string. Make changes in the call sites accordingly. Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--src/libcamera/include/utils.h4
-rw-r--r--src/libcamera/ipa_manager.cpp5
-rw-r--r--src/libcamera/ipa_proxy.cpp6
-rw-r--r--src/libcamera/utils.cpp26
4 files changed, 25 insertions, 16 deletions
diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
index bc96e79c..cfa620f2 100644
--- a/src/libcamera/include/utils.h
+++ b/src/libcamera/include/utils.h
@@ -143,9 +143,7 @@ private:
details::StringSplitter split(const std::string &str, const std::string &delim);
-bool isLibcameraInstalled();
-
-std::string libcameraPath();
+std::string libcameraBuildPath();
} /* namespace utils */
diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
index 0bd280c2..bcaae356 100644
--- a/src/libcamera/ipa_manager.cpp
+++ b/src/libcamera/ipa_manager.cpp
@@ -119,8 +119,9 @@ IPAManager::IPAManager()
* path for the IPA from that point. We need to recurse one level of
* sub-directories to match the build tree.
*/
- if (!utils::isLibcameraInstalled()) {
- std::string ipaBuildPath = utils::dirname(utils::libcameraPath()) + "/../ipa";
+ std::string root = utils::libcameraBuildPath();
+ if (!root.empty()) {
+ std::string ipaBuildPath = root + "src/ipa";
constexpr int maxDepth = 1;
LOG(IPAManager, Info)
diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
index 2f866cc4..5fd88a4b 100644
--- a/src/libcamera/ipa_proxy.cpp
+++ b/src/libcamera/ipa_proxy.cpp
@@ -97,9 +97,9 @@ std::string IPAProxy::resolvePath(const std::string &file) const
* This requires identifying the path of the libcamera.so, and
* referencing a relative path for the proxy workers from that point.
*/
- if (!utils::isLibcameraInstalled()) {
- std::string ipaProxyDir = utils::dirname(utils::libcameraPath())
- + "/proxy/worker";
+ std::string root = utils::libcameraBuildPath();
+ if (!root.empty()) {
+ std::string ipaProxyDir = root + "src/libcamera/proxy/worker";
LOG(IPAProxy, Info)
<< "libcamera is not installed. Loading proxy workers from'"
diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
index 7e118faf..58ee7cc1 100644
--- a/src/libcamera/utils.cpp
+++ b/src/libcamera/utils.cpp
@@ -340,23 +340,33 @@ bool isLibcameraInstalled()
}
/**
- * \brief Identify the libcamera.so path
+ * \brief Retrieve the path to the build directory
*
- * This function locates the running libcamera.so and returns its full path,
- * including the file name.
+ * During development, it is useful to run libcamera binaries directly from the
+ * build directory without installing them. This function helps components that
+ * need to locate resources, such as IPA modules or IPA proxy workers, by
+ * providing them with the path to the root of the build directory. Callers can
+ * then use it to complement or override searches in system-wide directories.
*
- * \return A string stating the path
+ * If libcamera has been installed, the build directory path is not available
+ * and this function returns an empty string.
+ *
+ * \return The path to the build directory if running from a build, or an empty
+ * string otherwise
*/
-std::string libcameraPath()
+std::string libcameraBuildPath()
{
+ if (isLibcameraInstalled())
+ return std::string();
+
Dl_info info;
/* Look up our own symbol. */
- int ret = dladdr(reinterpret_cast<void *>(libcameraPath), &info);
+ int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
if (ret == 0)
- return nullptr;
+ return std::string();
- return info.dli_fname;
+ return dirname(info.dli_fname) + "/../../";
}
} /* namespace utils */