From patchwork Wed Mar 18 15:24:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3173 Return-Path: Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 76C6260418 for ; Wed, 18 Mar 2020 16:25:54 +0100 (CET) Received: by mail-pj1-x1035.google.com with SMTP id np9so1478178pjb.4 for ; Wed, 18 Mar 2020 08:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u86HCsBqr7w/2SZeUAv8KIRZ2eJWE3vQOxp62VxrhBE=; b=I8MucxoiNDV5yeTbLDaENx+NKBQPh4+Lm7WvTnzMpvhAJdXFJv7U3RFjwyJDxNwcUV C2SJFQHjo4uaA6foJXGFnh4elM94ZeKt3xdt4nIhoFZ5RHRmlNSh3/prj+e2uuNZ5/eD yY4Gs+YsYUX6bLXkMol33kPepCp+ohO5ZRmHY/ptpObXO6FpWBOLw0gFEIRLH+8tbLxD BXM08CaTasJhPdY3YKv/MuOzRBsWZ26QY41+QoVYmoKYQnF6fQnvfmHsfl6i3MCVDKkD jnzvmksm/RqRDsjLENWhBQQEVK0NRoT8wbCax+iNanZXU0fzX8lwSuPQB8jVSfjpSDko 6S3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u86HCsBqr7w/2SZeUAv8KIRZ2eJWE3vQOxp62VxrhBE=; b=hpv0Yy4hnQoIxHgtsm6nuL3Lt+ZDK8m68oOWadZizEEpRXKq7cc/SVTIX8UKFym12E xWnZSzEXNQIzMfSDDkCMYvGNaRKnVYhwKqL7WGyPk0b0wcmqHUYwo4fHcOMgcj0DVWRy lqoL69OaN8w+xCLT0BdC8rQ8yTYwQhT/Rm4nFEtdYwBWQ6ISbrb0y3nZhuaCilEZxfZh vRQ30CfR4Wxp3noSqVTnse1B1IqpyA4Sc97k+Rwj2tsb7hGsFytWDY7xB0FP4A1/KFH5 3km7WDMaHBf9/lEN47/mEay9h26p0LrelLn3QlyeJiShv5VE8I+a7lND9rQ6GSnft0CA rTcA== X-Gm-Message-State: ANhLgQ1VjeKUAbWMYC1xKnPndJNN6oSFKk1LdCSxvqq0kAH2B1dXGJ4O LyoyLcsazVFm0yw0Ivs4O7/2mQ== X-Google-Smtp-Source: ADFU+vt/ok0w1co6rWn3pnLTYuKuDq+HSg1QVAPZ70F6QXaKY26WeTfviOJBLGomv73xc6Gy5yoaOA== X-Received: by 2002:a17:90a:bd96:: with SMTP id z22mr5085942pjr.172.1584545152805; Wed, 18 Mar 2020 08:25:52 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id h95sm2815201pjb.46.2020.03.18.08.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 08:25:52 -0700 (PDT) From: Kaaira Gupta To: Vaishali Thakkar , Helen Koike , kieran.bingham@ideasonboard.com, libcamera-devel@lists.libcamera.org Cc: Kaaira Gupta Date: Wed, 18 Mar 2020 20:54:25 +0530 Message-Id: <20200318152427.13126-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318152427.13126-1-kgupta@es.iitr.ac.in> References: <20200318152427.13126-1-kgupta@es.iitr.ac.in> Subject: [libcamera-devel] [PATCH LIBCAMERA v4 3/5] libcamera: utils: Move libcamera build path lookup to utis X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2020 15:25:54 -0000 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 Reviewed-by: Laurent Pinchart --- src/libcamera/include/utils.h | 4 +++ src/libcamera/ipa_manager.cpp | 36 ++----------------------- src/libcamera/utils.cpp | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 9405977..bc96e79 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -143,6 +143,10 @@ private: details::StringSplitter split(const std::string &str, const std::string &delim); +bool isLibcameraInstalled(); + +std::string libcameraPath(); + } /* namespace utils */ } /* namespace libcamera */ 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 #include -#include -#include -#include #include #include @@ -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(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) diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index f566e88..7e118fa 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -7,7 +7,10 @@ #include "utils.h" +#include +#include #include +#include #include #include #include @@ -18,6 +21,9 @@ * \brief Miscellaneous utility functions */ +/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */ +extern ElfW(Dyn) _DYNAMIC[]; + namespace libcamera { namespace utils { @@ -310,6 +316,49 @@ details::StringSplitter split(const std::string &str, const std::string &delim) return details::StringSplitter(str, delim); } +/** + * \brief Check if libcamera is installed or not + * + * Utilise the build_rpath dynamic tag which is stripped out by meson at + * install time to determine at runtime if the library currently executing + * has been installed or not. + * + * \return True if libcamera is installed, false otherwise + */ +bool isLibcameraInstalled() +{ + /* + * 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; +} + +/** + * \brief Identify the libcamera.so path + * + * This function locates the running libcamera.so and returns its full path, + * including the file name. + * + * \return A string stating the path + */ +std::string libcameraPath() +{ + Dl_info info; + + /* Look up our own symbol. */ + int ret = dladdr(reinterpret_cast(libcameraPath), &info); + if (ret == 0) + return nullptr; + + return info.dli_fname; +} + } /* namespace utils */ } /* namespace libcamera */