From patchwork Thu Mar 19 16:01:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3202 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30D8E60418 for ; Thu, 19 Mar 2020 17:01:50 +0100 (CET) Received: by mail-pj1-x1030.google.com with SMTP id nu11so1201146pjb.1 for ; Thu, 19 Mar 2020 09:01:50 -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=dIHTHOpvPakK4V0mqPDmtLrI2HiQfErKCftuioVKxdk=; b=aYeKXQHVDQI5osYjTh0ZciVhrg/18Y5aoywode6RAtaqvIrA5RVNghg8/YH733k8mV q3W3/EI6VrTYzNNYvIub20rquV8x1CadmsN6S8CL6HgkfNC1BZmUEgyd4AmR6otefCIK lagH32tEWFPOTY/ZsZjX37c6vdduczksRBnhcYScFjY17RxHzCDYy5X48OX9kA6mRM12 +us5bIzVhIjuGlGVonaPz6GVHTQ5BnNpv+Crc4XuCQsnTCRwYaMIdgXZhOF7ruGE6rqj tHw1onhV5iP152k96o8qUxTFmF4eWFq1KpGb03zkxhMOo+IuZl2yGGkvhNekPVHA1m+o 8LUQ== 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=dIHTHOpvPakK4V0mqPDmtLrI2HiQfErKCftuioVKxdk=; b=hcD5V28Y79aDW3VytuGbqmvnyd2of5vjMFonn0rXHIhDkOxt6qP90G+Ejg9zMhm58H et0FklxdhZzJjTjN11wtwVILnNAEow4RMy+ZwBGEmqIxf370rQwUNM2HCPAPE/bcwc19 PMbE6xnpSQEqkPUHiaQRdoTvUU1o5cFJeCn4g7aAEh4K2AkhEUKny+FPECVT1mxJmLK6 cx94D8FNfZXZgwVT0K9Z8fZG8RHUI1ukssR3hRngg3CEEQHrIl2x0D0RUM1GGmaSv+OY gr0uufJHEsIJsXRUTjLJywQQiBmLtBWVvBMsBLSE+CmwxRnv437rH0hINitep1C1pVP0 vAJw== X-Gm-Message-State: ANhLgQ3Hbf5URCvrX2V4fn1b+gMosY4uggIhSp3/uR/pervPEXjOs+1F gIoNmv045OdkdXBjxtrQXlS+kQ== X-Google-Smtp-Source: ADFU+vtQriIciWK1y2m6+B+MKVmIaLzzxzSLdw3ScifW+V3hpY09Se2WeZDmJDBZti1oL/ys/m0HJw== X-Received: by 2002:a17:90a:6c21:: with SMTP id x30mr4426650pjj.33.1584633708308; Thu, 19 Mar 2020 09:01:48 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.153]) by smtp.gmail.com with ESMTPSA id g19sm2915416pfh.141.2020.03.19.09.01.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 09:01:47 -0700 (PDT) Date: Thu, 19 Mar 2020 21:31:40 +0530 From: Kaaira Gupta To: Kieran Bingham , Laurent Pinchart , Helen Koike , Vaishali Thakkar , libcamera-devel@lists.libcamera.org Message-ID: <20200319160140.GA5590@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 v5] 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 16:01:50 -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 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 Reviewed-by: Kieran Bingham --- Changes since v4: - Updated documentation of libcameraBuildPath() 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 | 26 ++++++++++++++++++-------- 4 files changed, 25 insertions(+), 16 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..58ee7cc 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(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 */