[libcamera-devel,v3,5/6] libcamera: ipa_manager: replace by utils functions

Message ID 20200318115846.7975-6-kgupta@es.iitr.ac.in
State Superseded
Headers show
Series
  • libcamera: determine IPA_PROXY_PATH at runtime
Related show

Commit Message

Kaaira Gupta March 18, 2020, 11:58 a.m. UTC
Now that functions isLibcameraInstalled() and libcameraPath() are
defined in utils, they don't need to be defined here again. Hence remove
them and replace them with utils' functions.

Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
---
 src/libcamera/ipa_manager.cpp | 36 ++---------------------------------
 1 file changed, 2 insertions(+), 34 deletions(-)

Comments

Laurent Pinchart March 18, 2020, 12:28 p.m. UTC | #1
Hi Kaaira,

Thank you for the patch.

On Wed, Mar 18, 2020 at 05:28:45PM +0530, Kaaira Gupta wrote:
> Now that functions isLibcameraInstalled() and libcameraPath() are
> defined in utils, they don't need to be defined here again. Hence remove
> them and replace them with utils' functions.

I would squash this with the patch that adds the functions to utils, and
name it

libcamera: utils: Move libcamera build path lookup to utils

The IPA proxy manager will need to find the libcamera build path exactly
the same way as the IPA module mnager. Move the isLibcameraInstalled()
and libcameraPath() functions to utils to make them reusable.

> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
> ---
>  src/libcamera/ipa_manager.cpp | 36 ++---------------------------------
>  1 file changed, 2 insertions(+), 34 deletions(-)
> 
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 238433d..0bd280c 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -9,9 +9,6 @@
>  
>  #include <algorithm>
>  #include <dirent.h>
> -#include <dlfcn.h>
> -#include <elf.h>
> -#include <link.h>
>  #include <string.h>
>  #include <sys/types.h>
>  
> @@ -27,35 +24,6 @@
>   * \brief Image Processing Algorithm module manager
>   */
>  
> -static bool isLibcameraInstalled()
> -{
> -	/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
> -	extern ElfW(Dyn) _DYNAMIC[];
> -
> -	/*
> -	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
> -	 * install.
> -	 */
> -	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
> -		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
> -			return false;
> -	}
> -
> -	return true;
> -}
> -
> -static std::string libcameraPath()
> -{
> -	Dl_info info;
> -
> -	/* Look up our own symbol. */
> -	int ret = dladdr(reinterpret_cast<void *>(libcameraPath), &info);
> -	if (ret == 0)
> -		return nullptr;
> -
> -	return info.dli_fname;
> -}
> -
>  namespace libcamera {
>  
>  LOG_DEFINE_CATEGORY(IPAManager)
> @@ -151,8 +119,8 @@ IPAManager::IPAManager()
>  	 * path for the IPA from that point. We need to recurse one level of
>  	 * sub-directories to match the build tree.
>  	 */
> -	if (!isLibcameraInstalled()) {
> -		std::string ipaBuildPath = utils::dirname(libcameraPath()) + "/../ipa";
> +	if (!utils::isLibcameraInstalled()) {
> +		std::string ipaBuildPath = utils::dirname(utils::libcameraPath()) + "/../ipa";
>  		constexpr int maxDepth = 1;
>  
>  		LOG(IPAManager, Info)
> -- 
> 2.17.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
index 238433d..0bd280c 100644
--- a/src/libcamera/ipa_manager.cpp
+++ b/src/libcamera/ipa_manager.cpp
@@ -9,9 +9,6 @@ 
 
 #include <algorithm>
 #include <dirent.h>
-#include <dlfcn.h>
-#include <elf.h>
-#include <link.h>
 #include <string.h>
 #include <sys/types.h>
 
@@ -27,35 +24,6 @@ 
  * \brief Image Processing Algorithm module manager
  */
 
-static bool isLibcameraInstalled()
-{
-	/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
-	extern ElfW(Dyn) _DYNAMIC[];
-
-	/*
-	 * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
-	 * install.
-	 */
-	for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
-		if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
-			return false;
-	}
-
-	return true;
-}
-
-static std::string libcameraPath()
-{
-	Dl_info info;
-
-	/* Look up our own symbol. */
-	int ret = dladdr(reinterpret_cast<void *>(libcameraPath), &info);
-	if (ret == 0)
-		return nullptr;
-
-	return info.dli_fname;
-}
-
 namespace libcamera {
 
 LOG_DEFINE_CATEGORY(IPAManager)
@@ -151,8 +119,8 @@  IPAManager::IPAManager()
 	 * path for the IPA from that point. We need to recurse one level of
 	 * sub-directories to match the build tree.
 	 */
-	if (!isLibcameraInstalled()) {
-		std::string ipaBuildPath = utils::dirname(libcameraPath()) + "/../ipa";
+	if (!utils::isLibcameraInstalled()) {
+		std::string ipaBuildPath = utils::dirname(utils::libcameraPath()) + "/../ipa";
 		constexpr int maxDepth = 1;
 
 		LOG(IPAManager, Info)