From patchwork Mon Apr 27 03:17:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3554 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A19FB601B8 for ; Mon, 27 Apr 2020 05:17:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jkmQwApG"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E4BF98D for ; Mon, 27 Apr 2020 05:17:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1587957453; bh=uYFqjtDHmx0Sd0s9U3QQN1xno33zpkPgGM26TlOWy3I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jkmQwApGZvCGBSLNiQmOKFsipfBg2xQZ9Ea16hHUoalLogrnpaqygxNahCsRerYvO aZZ7dKsT9KHoCv+NKu+Z8q5uL9dEu2YKTdH61HXlDblkCWzXpMsk3PbpMOasykubrg MUsYuPM8ko/M+K+Q1JF2XbYxHaqtxI3FAS4outFE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 06:17:04 +0300 Message-Id: <20200427031713.14013-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200427031713.14013-1-laurent.pinchart@ideasonboard.com> References: <20200427031713.14013-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/11] libcamera: utils: Add a function to retrieve the libcamera source tree 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: Mon, 27 Apr 2020 03:17:33 -0000 Similarly to libcameraBuildPath(), there's a need to locate resources within the source tree when running libcamera without installing it. Support this use case with a new utils::libcameraSourcePath() function. The implementation currently leaks the path to the source tree in the installed binary. The data is put in a separate section named .zero which will need to be zeroed at installation time to fix this. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- meson.build | 2 ++ src/libcamera/include/utils.h | 1 + src/libcamera/utils.cpp | 37 ++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index c6e6a934e54e..2058a6a77ceb 100644 --- a/meson.build +++ b/meson.build @@ -26,6 +26,8 @@ libcamera_version = libcamera_git_version.split('+')[0] cc = meson.get_compiler('c') config_h = configuration_data() +config_h.set('LIBCAMERA_SOURCE_DIR', '"' + meson.current_source_dir() + '"') + if cc.has_header_symbol('execinfo.h', 'backtrace') config_h.set('HAVE_BACKTRACE', 1) endif diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 242eeded9d50..3334ff16613d 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -188,6 +188,7 @@ private: details::StringSplitter split(const std::string &str, const std::string &delim); std::string libcameraBuildPath(); +std::string libcameraSourcePath(); } /* namespace utils */ diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 97f9b632e45b..056a67e93e0f 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -360,9 +360,10 @@ bool isLibcameraInstalled() * * 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. + * need to locate resources in the build tree, 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. * * If libcamera has been installed, the build directory path is not available * and this function returns an empty string. @@ -385,6 +386,36 @@ std::string libcameraBuildPath() return dirname(info.dli_fname) + "/../../"; } +namespace { +/* \todo Figure out a way to zero this section at install time */ +__attribute__((section(".zero"))) +const char sourceDirectory[] = LIBCAMERA_SOURCE_DIR; +} /* namespace */ + +/** + * \brief Retrieve the path to the source directory + * + * 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 in the source tree, such as IPA configuration + * files, by providing them with the path to the root of the source directory. + * Callers can then use it to complement or override searches in system-wide + * directories. + * + * If libcamera has been installed, the source directory path is not available + * and this function returns an empty string. + * + * \return The path to the source directory if running from a build, or an empty + * string otherwise + */ +std::string libcameraSourcePath() +{ + if (isLibcameraInstalled()) + return std::string(); + + return std::string(sourceDirectory) + "/"; +} + } /* namespace utils */ } /* namespace libcamera */