From patchwork Thu Mar 19 15:19:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3200 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03C21629AC for ; Thu, 19 Mar 2020 16:19:29 +0100 (CET) Received: by mail-pf1-x429.google.com with SMTP id l184so1592061pfl.7 for ; Thu, 19 Mar 2020 08:19:28 -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=xYNQMHyPKu8uqaR7FDWqvuxH569oUVfd3E6rB2FCNx4=; b=WU5eW9zXRJrnVTHQSJrNd67TuNMvbe4gP5xisnsdA5AT3e6UH6GAfvDD1O/xgOF9B0 VGieGBG61pCHQvzith+Pq9bdkXmPp9Bh99yadqzv0x9LwQCUeAMOnahuS7izIYoYqSVz Ld7JSDQjGrAKfrBlLedC360T6THqmykjCp5WcL8+X7Ys+/X8k3xDXeJ35iFWzwF+OkA3 +5iW9Fdk9XU+wdtHdpvzevvxmlCUoTWacrwCCy4mGztgEIXSACUguHcwR6wzkpJzcDwv +IteD/r2iQwC3jdtsvSr+8XBeF9IoGZmthcuGvPULxpIsBi6DfHdebS6jBzLfJXXLquh 8dhg== 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=xYNQMHyPKu8uqaR7FDWqvuxH569oUVfd3E6rB2FCNx4=; b=JkWO7TbQOJ1yFZhY2Sh9T9PKIRDO8gugdVZci8uXHPDrYROboQiRdnwXXGpNurEcXY rvOLHtSML2GM2u5m8O3YPdlYjO+c1qZS4H5KRMokHiI6zw5stpZaq2GydfhdFsNpP0vY 0PD2TiNbgmW0Y14rUsFBGBYsONLz73u+Q5SvtRYyx+6/LYyr9kYYWxujv21OvASctk5o wyANnrJbOnwEXxQpywolhQw3YEM/Qeq/X5x+Vli2kFPunURZU/Z4FiO5l4to7tAFJwPa EaqTKMWR4eLsOuTwu2qhSuK41Fs3m/xuHBi/C9basDiuR5SNOVPecT1zfkn4ol3KnSMn +A3A== X-Gm-Message-State: ANhLgQ1zPdLgvXgM8005g0w+uVyzJNG18ueg6A10lmXsCDeNNTVOmIgF cW4cK0DyVcj7G5paS5buVmoJHg== X-Google-Smtp-Source: ADFU+vtXNMqw2+ALe5WCJGVKo+EhxbWO84HpSsEw/OBVQV4+x5dfa5f2CmuYK/I7x1xCeFA7tSp+lA== X-Received: by 2002:aa7:95ae:: with SMTP id a14mr4342371pfk.164.1584631167462; Thu, 19 Mar 2020 08:19:27 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id 20sm2578676pfn.58.2020.03.19.08.19.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 08:19:26 -0700 (PDT) Date: Thu, 19 Mar 2020 20:49:19 +0530 From: Kaaira Gupta To: Helen Koike , Vaishali Thakkar , kieran.bingham@ideasonboard.com, libcamera-devel@lists.libcamera.org Message-ID: <20200319151919.GA4693@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:19:30 -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 --- 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 | 2 +- src/libcamera/ipa_manager.cpp | 5 +++-- src/libcamera/ipa_proxy.cpp | 6 +++--- src/libcamera/utils.cpp | 16 +++++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index bc96e79..5dea8d2 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -145,7 +145,7 @@ 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..42c5c76 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -347,16 +347,18 @@ bool isLibcameraInstalled() * * \return A string stating the path */ -std::string libcameraPath() +std::string libcameraBuildPath() { - Dl_info info; + if (!isLibcameraInstalled()) { + Dl_info info; - /* Look up our own symbol. */ - int ret = dladdr(reinterpret_cast(libcameraPath), &info); - if (ret == 0) - return nullptr; + /* Look up our own symbol. */ + int ret = dladdr(reinterpret_cast(libcameraBuildPath), &info); + if (ret) + return dirname(info.dli_fname) + "/../../"; + } - return info.dli_fname; + return std::string(); } } /* namespace utils */