[{"id":4105,"web_url":"https://patchwork.libcamera.org/comment/4105/","msgid":"<20200319154142.GD14585@pendragon.ideasonboard.com>","date":"2020-03-19T15:41:42","subject":"Re: [libcamera-devel] [PATCH LIBCAMERA v4] libcamera: utils: adapt\n\tlibcameraPath to match use cases","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kaaira,\n\nThank you for the patch.\n\nOn Thu, Mar 19, 2020 at 08:55:33PM +0530, Kaaira Gupta wrote:\n> The two callers of functions libcameraPath() and isLibcameraInstalled()\n> end up using the same process and finally use the path with\n> libcamera.so. Hence write a function libcameraBuildPath() which\n> combines their functions and returns the root of the build sources\n> when the library has not been installed, but is running, thereby making\n\ns/running/running from the build directory/ ?\n\n> call sites simpler.\n> \n> When the library is installed, libcameraBuildPath() will return an empty\n> string.\n> \n> Make changes in the call sites accordingly.\n> \n> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> ---\n> Changes since v3:\n>         - removed isLibcameraInstalled() from utils.h\n>         - reformatted the code to reduce indentation of the code that\n>           implements actual logic, also, to catch the errors\n>           immediately.\n>         - changes in spellings and whitespaces in commit messages.\n> \n> Changes since v2:\n>         - rename subject line and add necessary details in commit\n>           message.\n>         - Solve whitespace issues.\n>         - specify the final 'slash' for directory path in return\n>           statement itself.\n> \n> Changes since v1:\n>         - rename function to libcameraBuildPath() instead, and return\n>           the root of libcamera source, and not the source directory\n>           root.\n>         - Return empty string instead of nullptr when ret==0\n> \n>  src/libcamera/include/utils.h |  4 +---\n>  src/libcamera/ipa_manager.cpp |  5 +++--\n>  src/libcamera/ipa_proxy.cpp   |  6 +++---\n>  src/libcamera/utils.cpp       | 11 +++++++----\n>  4 files changed, 14 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> index bc96e79..cfa620f 100644\n> --- a/src/libcamera/include/utils.h\n> +++ b/src/libcamera/include/utils.h\n> @@ -143,9 +143,7 @@ private:\n>  \n>  details::StringSplitter split(const std::string &str, const std::string &delim);\n>  \n> -bool isLibcameraInstalled();\n> -\n> -std::string libcameraPath();\n> +std::string libcameraBuildPath();\n>  \n>  } /* namespace utils */\n>  \n> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> index 0bd280c..bcaae35 100644\n> --- a/src/libcamera/ipa_manager.cpp\n> +++ b/src/libcamera/ipa_manager.cpp\n> @@ -119,8 +119,9 @@ IPAManager::IPAManager()\n>  \t * path for the IPA from that point. We need to recurse one level of\n>  \t * sub-directories to match the build tree.\n>  \t */\n> -\tif (!utils::isLibcameraInstalled()) {\n> -\t\tstd::string ipaBuildPath = utils::dirname(utils::libcameraPath()) + \"/../ipa\";\n> +\tstd::string root = utils::libcameraBuildPath();\n> +\tif (!root.empty()) {\n> +\t\tstd::string ipaBuildPath = root + \"src/ipa\";\n>  \t\tconstexpr int maxDepth = 1;\n>  \n>  \t\tLOG(IPAManager, Info)\n> diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp\n> index 2f866cc..5fd88a4 100644\n> --- a/src/libcamera/ipa_proxy.cpp\n> +++ b/src/libcamera/ipa_proxy.cpp\n> @@ -97,9 +97,9 @@ std::string IPAProxy::resolvePath(const std::string &file) const\n>  \t * This requires identifying the path of the libcamera.so, and\n>  \t * referencing a relative path for the proxy workers from that point.\n>  \t */\n> -\tif (!utils::isLibcameraInstalled()) {\n> -\t\tstd::string ipaProxyDir = utils::dirname(utils::libcameraPath())\n> -\t\t\t\t\t  + \"/proxy/worker\";\n> +\tstd::string root = utils::libcameraBuildPath();\n> +\tif (!root.empty()) {\n> +\t\tstd::string ipaProxyDir = root + \"src/libcamera/proxy/worker\";\n>  \n>  \t\tLOG(IPAProxy, Info)\n>  \t\t\t<< \"libcamera is not installed. Loading proxy workers from'\"\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index 7e118fa..40a8367 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -347,16 +347,19 @@ bool isLibcameraInstalled()\n>   *\n>   * \\return A string stating the path\n\nI think you forgot to update the documentation :-) I propose the\nfollowing.\n\n/**\n * \\brief Retrieve the path to the build directory\n *\n * During development, it is useful to run libcamera binaries directly from the\n * build directory without installing them. This function helps components that\n * need to locate resources, such as IPA modules or IPA proxy workers, by\n * providing them with the path to the root of the build directory. Callers can\n * then use it to complement or override searches in system-wide directories.\n *\n * If libcamera has been installed, the build directory path is not available\n * and this function returns an empty string.\n *\n * \\return The path to the build directory if running from a build, or an empty\n * string otherwise\n */\n\nIf that works for you, I'll add this when applying.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>   */\n> -std::string libcameraPath()\n> +std::string libcameraBuildPath()\n>  {\n> +\tif (isLibcameraInstalled())\n> +\t\treturn std::string();\n> +\n>  \tDl_info info;\n>  \n>  \t/* Look up our own symbol. */\n> -\tint ret = dladdr(reinterpret_cast<void *>(libcameraPath), &info);\n> +\tint ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);\n>  \tif (ret == 0)\n> -\t\treturn nullptr;\n> +\t\treturn std::string();\n>  \n> -\treturn info.dli_fname;\n> +\treturn dirname(info.dli_fname) + \"/../../\";\n>  }\n>  \n>  } /* namespace utils */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CC6F460418\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2020 16:41:48 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E063A53;\n\tThu, 19 Mar 2020 16:41:48 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584632508;\n\tbh=jbrCcjqwD5nAKqCkinlb4Pmni8Ufwm3kTDyG+2oScSk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ri9hrJOGno4Un6pt5TxKrybw4Z9MlXc2AMtuRF93qvWRH2SSUx8QdHdzYEzrKatyW\n\tnG0/32HUF3z8f3pV196fbmaJMh2EQsLOHvNsofQWeBCHm8lKtB0bDbO2sXkpGOgYAd\n\tRNUnURv9ke1Ugk7gzbrgcf8q91aRt9rhv0YgekQU=","Date":"Thu, 19 Mar 2020 17:41:42 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>,\n\tlibcamera-devel@lists.libcamera.org","Message-ID":"<20200319154142.GD14585@pendragon.ideasonboard.com>","References":"<20200319152533.GA4938@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200319152533.GA4938@kaaira-HP-Pavilion-Notebook>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH LIBCAMERA v4] libcamera: utils: adapt\n\tlibcameraPath to match use cases","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 19 Mar 2020 15:41:49 -0000"}},{"id":4106,"web_url":"https://patchwork.libcamera.org/comment/4106/","msgid":"<20200319154938.GA5324@kaaira-HP-Pavilion-Notebook>","date":"2020-03-19T15:49:38","subject":"Re: [libcamera-devel] [PATCH LIBCAMERA v4] libcamera: utils: adapt\n\tlibcameraPath to match use cases","submitter":{"id":39,"url":"https://patchwork.libcamera.org/api/people/39/","name":"Kaaira Gupta","email":"kgupta@es.iitr.ac.in"},"content":"On Thu, Mar 19, 2020 at 05:41:42PM +0200, Laurent Pinchart wrote:\n> Hi Kaaira,\n> \n> Thank you for the patch.\n> \n> On Thu, Mar 19, 2020 at 08:55:33PM +0530, Kaaira Gupta wrote:\n> > The two callers of functions libcameraPath() and isLibcameraInstalled()\n> > end up using the same process and finally use the path with\n> > libcamera.so. Hence write a function libcameraBuildPath() which\n> > combines their functions and returns the root of the build sources\n> > when the library has not been installed, but is running, thereby making\n> \n> s/running/running from the build directory/ ?\n\nYes I should clear that explicitly. I'll do that.\n\n> \n> > call sites simpler.\n> > \n> > When the library is installed, libcameraBuildPath() will return an empty\n> > string.\n> > \n> > Make changes in the call sites accordingly.\n> > \n> > Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> > ---\n> > Changes since v3:\n> >         - removed isLibcameraInstalled() from utils.h\n> >         - reformatted the code to reduce indentation of the code that\n> >           implements actual logic, also, to catch the errors\n> >           immediately.\n> >         - changes in spellings and whitespaces in commit messages.\n> > \n> > Changes since v2:\n> >         - rename subject line and add necessary details in commit\n> >           message.\n> >         - Solve whitespace issues.\n> >         - specify the final 'slash' for directory path in return\n> >           statement itself.\n> > \n> > Changes since v1:\n> >         - rename function to libcameraBuildPath() instead, and return\n> >           the root of libcamera source, and not the source directory\n> >           root.\n> >         - Return empty string instead of nullptr when ret==0\n> > \n> >  src/libcamera/include/utils.h |  4 +---\n> >  src/libcamera/ipa_manager.cpp |  5 +++--\n> >  src/libcamera/ipa_proxy.cpp   |  6 +++---\n> >  src/libcamera/utils.cpp       | 11 +++++++----\n> >  4 files changed, 14 insertions(+), 12 deletions(-)\n> > \n> > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> > index bc96e79..cfa620f 100644\n> > --- a/src/libcamera/include/utils.h\n> > +++ b/src/libcamera/include/utils.h\n> > @@ -143,9 +143,7 @@ private:\n> >  \n> >  details::StringSplitter split(const std::string &str, const std::string &delim);\n> >  \n> > -bool isLibcameraInstalled();\n> > -\n> > -std::string libcameraPath();\n> > +std::string libcameraBuildPath();\n> >  \n> >  } /* namespace utils */\n> >  \n> > diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> > index 0bd280c..bcaae35 100644\n> > --- a/src/libcamera/ipa_manager.cpp\n> > +++ b/src/libcamera/ipa_manager.cpp\n> > @@ -119,8 +119,9 @@ IPAManager::IPAManager()\n> >  \t * path for the IPA from that point. We need to recurse one level of\n> >  \t * sub-directories to match the build tree.\n> >  \t */\n> > -\tif (!utils::isLibcameraInstalled()) {\n> > -\t\tstd::string ipaBuildPath = utils::dirname(utils::libcameraPath()) + \"/../ipa\";\n> > +\tstd::string root = utils::libcameraBuildPath();\n> > +\tif (!root.empty()) {\n> > +\t\tstd::string ipaBuildPath = root + \"src/ipa\";\n> >  \t\tconstexpr int maxDepth = 1;\n> >  \n> >  \t\tLOG(IPAManager, Info)\n> > diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp\n> > index 2f866cc..5fd88a4 100644\n> > --- a/src/libcamera/ipa_proxy.cpp\n> > +++ b/src/libcamera/ipa_proxy.cpp\n> > @@ -97,9 +97,9 @@ std::string IPAProxy::resolvePath(const std::string &file) const\n> >  \t * This requires identifying the path of the libcamera.so, and\n> >  \t * referencing a relative path for the proxy workers from that point.\n> >  \t */\n> > -\tif (!utils::isLibcameraInstalled()) {\n> > -\t\tstd::string ipaProxyDir = utils::dirname(utils::libcameraPath())\n> > -\t\t\t\t\t  + \"/proxy/worker\";\n> > +\tstd::string root = utils::libcameraBuildPath();\n> > +\tif (!root.empty()) {\n> > +\t\tstd::string ipaProxyDir = root + \"src/libcamera/proxy/worker\";\n> >  \n> >  \t\tLOG(IPAProxy, Info)\n> >  \t\t\t<< \"libcamera is not installed. Loading proxy workers from'\"\n> > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> > index 7e118fa..40a8367 100644\n> > --- a/src/libcamera/utils.cpp\n> > +++ b/src/libcamera/utils.cpp\n> > @@ -347,16 +347,19 @@ bool isLibcameraInstalled()\n> >   *\n> >   * \\return A string stating the path\n> \n> I think you forgot to update the documentation :-) I propose the\n> following.\n\nSorry, I should be more careful.\n\n> \n> /**\n>  * \\brief Retrieve the path to the build directory\n>  *\n>  * During development, it is useful to run libcamera binaries directly from the\n>  * build directory without installing them. This function helps components that\n>  * need to locate resources, such as IPA modules or IPA proxy workers, by\n>  * providing them with the path to the root of the build directory. Callers can\n>  * then use it to complement or override searches in system-wide directories.\n>  *\n>  * If libcamera has been installed, the build directory path is not available\n>  * and this function returns an empty string.\n>  *\n>  * \\return The path to the build directory if running from a build, or an empty\n>  * string otherwise\n>  */\n> \n> If that works for you, I'll add this when applying.\n\nI'll do that and send another version now itself if that's fine.\n\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> >   */\n> > -std::string libcameraPath()\n> > +std::string libcameraBuildPath()\n> >  {\n> > +\tif (isLibcameraInstalled())\n> > +\t\treturn std::string();\n> > +\n> >  \tDl_info info;\n> >  \n> >  \t/* Look up our own symbol. */\n> > -\tint ret = dladdr(reinterpret_cast<void *>(libcameraPath), &info);\n> > +\tint ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);\n> >  \tif (ret == 0)\n> > -\t\treturn nullptr;\n> > +\t\treturn std::string();\n> >  \n> > -\treturn info.dli_fname;\n> > +\treturn dirname(info.dli_fname) + \"/../../\";\n> >  }\n> >  \n> >  } /* namespace utils */\n> \n\nThanks for the time!\n\n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pf1-x442.google.com (mail-pf1-x442.google.com\n\t[IPv6:2607:f8b0:4864:20::442])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72D9760418\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2020 16:49:48 +0100 (CET)","by mail-pf1-x442.google.com with SMTP id d25so1634701pfn.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2020 08:49:48 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.153])\n\tby smtp.gmail.com with ESMTPSA id\n\ty15sm2934441pfc.206.2020.03.19.08.49.43\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 19 Mar 2020 08:49:46 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623;\n\th=from:date:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=wA3tyuQmD5bv6FRHfUoVxKZPVBWddq2+/G4kqhmk9ck=;\n\tb=Pl6292ERJom5hhjqOcRPdmAdx5Gd010Uib2vPGl5uKNJBTpDqcAxzI3JzSV0mvl3rn\n\tQooudwNQ2efvQSKRGTodQ1sG1jkQwWA/aWM65gEu6SemPDArQ15a5WtL421QHGgho6rz\n\tBK11TxV8gYTfRK4YlQe9oqXN+q/FQmf5oGC96POBQaAmNbOQWNdpQ6VnBpZb3JcdimQT\n\tSQ9cpWZkRlzZOxgxF4pc2Vvol1b8Fw4wPCUA1VTv0XdWVwm3HySgman8j2MlMqVli4SU\n\tGBk2iG/OAfZ2GmvDWjkrmopEYVSBdXoWW0UL8tS6nHOn7tUtqV7GVKrhz5Ygwi1xc//X\n\tDTAw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:date:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=wA3tyuQmD5bv6FRHfUoVxKZPVBWddq2+/G4kqhmk9ck=;\n\tb=bfN7lJa/6hFyw3hoSlS11m4T6TJg4kojaT/awpMSYeM+VKvaBkIFILosRRZJZ/szbN\n\t3L7An900GDAyXOFmTVAStVtcy35lxNtDyMnrRR319d+af1jnTbBBg5nRujSSq+jA3xIk\n\tfcEZfvCDxCFb7yzQwngZnMwzATl9RxujofCe63LpV7wa6Q9hzoWNQCUqVcpJFRkfwSDV\n\tO/WcB3SJC0gPLv1gkZM8+w7mcG10hmhRkYlnmveIHmJ7WzMd6MAl8ljKD/J8ZTxwaW51\n\tIiZyeWjjrutlnuy9xsRDY3Vj1NX+T+3s2qU7PFZT5S1hiTtntTi//5j8VNIafKGmitmr\n\tDVBg==","X-Gm-Message-State":"ANhLgQ1Vfvl1nOjrGL1Gh0LwhEE0lVjVG0JdBKGYS48/Df7Ogmb8Y7E5\n\tIf7HFj/A2ekLlbNT/wj/io1MAA0Z8/c=","X-Google-Smtp-Source":"ADFU+vt0jfdvIQYw9btQIKXx9udgIuknBjPPkzqsBJCnLex3OCiZFZUCj0DcoaLT1G+/NbYyreYRcQ==","X-Received":"by 2002:a62:5cc1:: with SMTP id\n\tq184mr4525502pfb.259.1584632986596; \n\tThu, 19 Mar 2020 08:49:46 -0700 (PDT)","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","X-Google-Original-From":"Kaaira Gupta <Kaairakgupta@es.iitr.ac.in>","Date":"Thu, 19 Mar 2020 21:19:38 +0530","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kaaira Gupta <kgupta@es.iitr.ac.in>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>,\n\tlibcamera-devel@lists.libcamera.org","Message-ID":"<20200319154938.GA5324@kaaira-HP-Pavilion-Notebook>","References":"<20200319152533.GA4938@kaaira-HP-Pavilion-Notebook>\n\t<20200319154142.GD14585@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20200319154142.GD14585@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.9.4 (2018-02-28)","Subject":"Re: [libcamera-devel] [PATCH LIBCAMERA v4] libcamera: utils: adapt\n\tlibcameraPath to match use cases","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 19 Mar 2020 15:49:48 -0000"}}]