From patchwork Thu Mar 19 15:25:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3201 Return-Path: Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14304629AC for ; Thu, 19 Mar 2020 16:25:43 +0100 (CET) Received: by mail-pl1-x635.google.com with SMTP id m1so1202173pll.6 for ; Thu, 19 Mar 2020 08:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=ps4FgPstPR09Br6RJ5ePHDC5/6I2wW7HsL2VU0fGD4E=; b=02hda8GYXXpAhGb1Z1KgQLWBMY+1cI1JIB5vS3f2A8unWZN7POPGyiDQaQZa/1kjYt D0+BcWkeDmWt8/UYjVLu/9FiXKwXnkKFwi0nXc4+Wl/0Mbt4hzWgzFtgVUa4y3BDzA8V O1+kAaIfgBkGv25wyNXEtq4kajtUuYt23kLxGCyYl5/70JymQI76o+b0VSR2tkNcTD2H oL0SFxFhzOq9/kWWt2KW7sfMj1d2Tn4jqZachJOL4e7h2IZ6ajh8kEYHKObykBo5gaDb n2M7TSkcutmR2gognAhiAmkKq6HudwiHjw4/sDvzHZ1BRXQn74wyNrn+980ZExskQh7K PYtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=ps4FgPstPR09Br6RJ5ePHDC5/6I2wW7HsL2VU0fGD4E=; b=SmX8rmOlrNVVfF6TBR6U8DjzGN6TjbJhTPtpGm72VQGGuhYdXd26DNQacca4I+Xbj/ kticZsvkfCk1HiImBZdZlrcBULyWUWjU4BoXH+h/xin254/ci+++JF1GeCLauQhhKOVH titduOsU6OG6MFujTlk68/juSBJ6cuuAo7EDVlc7ceaTbVDqCQbm2qCSUlCnaOoCL9Dn 28RsLC4o9BYe9jx88Fsbxy2ePeKFiTdrhF5dAdB7Dj0h21xNmyy5X8qsfHVisfsYA8M6 wsUsNymoKEm4smoRYXq3nfTWrvK4KzXJV6QgAtznYH56zhvz7eIIEH20RlaGVi9hn2W7 uTEw== X-Gm-Message-State: ANhLgQ3yPBZjyhESbnh3J55KsE385GbvAi12M+IxQXXiuY6+hOfuXpg8 QLIhmeYnAoAL4lKpxmnsFKEo5g== X-Google-Smtp-Source: ADFU+vulA4aQ2NNy9UVizV4VgMTrAg1viLtRrS60Gg18kwmynUCA4+x+igWfWQMFNCYse31yQxMHhg== X-Received: by 2002:a17:90a:228c:: with SMTP id s12mr4420935pjc.68.1584631541258; Thu, 19 Mar 2020 08:25:41 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id gc16sm2417024pjb.8.2020.03.19.08.25.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 08:25:40 -0700 (PDT) Date: Thu, 19 Mar 2020 20:55:33 +0530 From: Kaaira Gupta To: Kieran Bingham , Laurent Pinchart , Kaaira Gupta , Helen Koike , Vaishali Thakkar , libcamera-devel@lists.libcamera.org Message-ID: <20200319152533.GA4938@kaaira-HP-Pavilion-Notebook> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [libcamera-devel] [PATCH LIBCAMERA v4] libcamera: utils: adapt libcameraPath to match use cases 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: Thu, 19 Mar 2020 15:25:43 -0000 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, 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 Reviewed-by: Laurent Pinchart --- Changes since v3: - removed isLibcameraInstalled() from utils.h - reformatted the code to reduce indentation of the code that implements actual logic, also, to catch the errors immediately. - changes in spellings and whitespaces in commit messages. Changes since v2: - rename subject line and add necessary details in commit message. - Solve whitespace issues. - specify the final 'slash' for directory path in return statement itself. Changes since v1: - rename function to libcameraBuildPath() instead, and return the root of libcamera source, and not the source directory root. - Return empty string instead of nullptr when ret==0 src/libcamera/include/utils.h | 4 +--- src/libcamera/ipa_manager.cpp | 5 +++-- src/libcamera/ipa_proxy.cpp | 6 +++--- src/libcamera/utils.cpp | 11 +++++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index bc96e79..cfa620f 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 0bd280c..bcaae35 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 2f866cc..5fd88a4 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 7e118fa..40a8367 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -347,16 +347,19 @@ bool isLibcameraInstalled() * * \return A string stating the path */ -std::string libcameraPath() +std::string libcameraBuildPath() { + if (isLibcameraInstalled()) + return std::string(); + Dl_info info; /* Look up our own symbol. */ - int ret = dladdr(reinterpret_cast(libcameraPath), &info); + int ret = dladdr(reinterpret_cast(libcameraBuildPath), &info); if (ret == 0) - return nullptr; + return std::string(); - return info.dli_fname; + return dirname(info.dli_fname) + "/../../"; } } /* namespace utils */