libcamera: Separate source and build path helpers
The libcameraSourcePath and libcameraBuildPath helper functions are internal and specific to libcamera needs while operating with the meson build system. In preparation for the upcoming move of utils to a common library, move these helpers out of utils and into their own build unit. Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Hirokazu Honda<hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
ec7afef665
commit
b96ab21cdb
5 changed files with 160 additions and 111 deletions
|
@ -39,6 +39,7 @@ libcamera_internal_headers = files([
|
||||||
'process.h',
|
'process.h',
|
||||||
'pub_key.h',
|
'pub_key.h',
|
||||||
'semaphore.h',
|
'semaphore.h',
|
||||||
|
'source_paths.h',
|
||||||
'sysfs.h',
|
'sysfs.h',
|
||||||
'thread.h',
|
'thread.h',
|
||||||
'timer.h',
|
'timer.h',
|
||||||
|
|
19
include/libcamera/internal/source_paths.h
Normal file
19
include/libcamera/internal/source_paths.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021, Google Inc.
|
||||||
|
*
|
||||||
|
* source_paths.h - Identify libcamera source and build paths
|
||||||
|
*/
|
||||||
|
#ifndef __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
|
||||||
|
#define __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace libcamera::utils {
|
||||||
|
|
||||||
|
std::string libcameraBuildPath();
|
||||||
|
std::string libcameraSourcePath();
|
||||||
|
|
||||||
|
} /* namespace libcamera::utils */
|
||||||
|
|
||||||
|
#endif /* __LIBCAMERA_INTERNAL_SOURCE_PATHS_H__ */
|
|
@ -46,6 +46,7 @@ libcamera_sources = files([
|
||||||
'request.cpp',
|
'request.cpp',
|
||||||
'semaphore.cpp',
|
'semaphore.cpp',
|
||||||
'signal.cpp',
|
'signal.cpp',
|
||||||
|
'source_paths.cpp',
|
||||||
'stream.cpp',
|
'stream.cpp',
|
||||||
'sysfs.cpp',
|
'sysfs.cpp',
|
||||||
'thread.cpp',
|
'thread.cpp',
|
||||||
|
|
139
src/libcamera/source_paths.cpp
Normal file
139
src/libcamera/source_paths.cpp
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021, Google Inc.
|
||||||
|
*
|
||||||
|
* source_paths.cpp - Identify libcamera source and build paths
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libcamera/internal/source_paths.h"
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <elf.h>
|
||||||
|
#include <link.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "libcamera/internal/utils.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file source_paths.h
|
||||||
|
* \brief Identify the build and source path of a not-yet-installed library
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
|
||||||
|
extern ElfW(Dyn) _DYNAMIC[];
|
||||||
|
|
||||||
|
namespace libcamera {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Check if libcamera is installed or not
|
||||||
|
*
|
||||||
|
* Utilise the build_rpath dynamic tag which is stripped out by meson at
|
||||||
|
* install time to determine at runtime if the library currently executing
|
||||||
|
* has been installed or not.
|
||||||
|
*
|
||||||
|
* \return True if libcamera is installed, false otherwise
|
||||||
|
*/
|
||||||
|
bool isLibcameraInstalled()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
|
||||||
|
* install.
|
||||||
|
*/
|
||||||
|
for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
|
||||||
|
if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace */
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieve the path to the build 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 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.
|
||||||
|
*
|
||||||
|
* \return The path to the build directory if running from a build, or an empty
|
||||||
|
* string otherwise
|
||||||
|
*/
|
||||||
|
std::string libcameraBuildPath()
|
||||||
|
{
|
||||||
|
if (isLibcameraInstalled())
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
Dl_info info;
|
||||||
|
|
||||||
|
/* Look up our own symbol. */
|
||||||
|
int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
|
||||||
|
if (ret == 0)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
std::string path = dirname(info.dli_fname) + "/../../";
|
||||||
|
|
||||||
|
char *real = realpath(path.c_str(), nullptr);
|
||||||
|
if (!real)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
path = real;
|
||||||
|
free(real);
|
||||||
|
|
||||||
|
return path + "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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 directory,
|
||||||
|
* or an empty string otherwise
|
||||||
|
*/
|
||||||
|
std::string libcameraSourcePath()
|
||||||
|
{
|
||||||
|
std::string path = libcameraBuildPath();
|
||||||
|
if (path.empty())
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
path += "source";
|
||||||
|
|
||||||
|
char *real = realpath(path.c_str(), nullptr);
|
||||||
|
if (!real)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
path = real;
|
||||||
|
free(real);
|
||||||
|
|
||||||
|
struct stat statbuf;
|
||||||
|
int ret = stat(path.c_str(), &statbuf);
|
||||||
|
if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
return path + "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace utils */
|
||||||
|
|
||||||
|
} /* namespace libcamera */
|
|
@ -7,16 +7,10 @@
|
||||||
|
|
||||||
#include "libcamera/internal/utils.h"
|
#include "libcamera/internal/utils.h"
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <elf.h>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <limits.h>
|
|
||||||
#include <link.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,9 +18,6 @@
|
||||||
* \brief Miscellaneous utility functions
|
* \brief Miscellaneous utility functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* musl doesn't declare _DYNAMIC in link.h, declare it manually. */
|
|
||||||
extern ElfW(Dyn) _DYNAMIC[];
|
|
||||||
|
|
||||||
namespace libcamera {
|
namespace libcamera {
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
@ -351,108 +342,6 @@ std::string toAscii(const std::string &str)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Check if libcamera is installed or not
|
|
||||||
*
|
|
||||||
* Utilise the build_rpath dynamic tag which is stripped out by meson at
|
|
||||||
* install time to determine at runtime if the library currently executing
|
|
||||||
* has been installed or not.
|
|
||||||
*
|
|
||||||
* \return True if libcamera is installed, false otherwise
|
|
||||||
*/
|
|
||||||
bool isLibcameraInstalled()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on
|
|
||||||
* install.
|
|
||||||
*/
|
|
||||||
for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) {
|
|
||||||
if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Retrieve the path to the build 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 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.
|
|
||||||
*
|
|
||||||
* \return The path to the build directory if running from a build, or an empty
|
|
||||||
* string otherwise
|
|
||||||
*/
|
|
||||||
std::string libcameraBuildPath()
|
|
||||||
{
|
|
||||||
if (isLibcameraInstalled())
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
Dl_info info;
|
|
||||||
|
|
||||||
/* Look up our own symbol. */
|
|
||||||
int ret = dladdr(reinterpret_cast<void *>(libcameraBuildPath), &info);
|
|
||||||
if (ret == 0)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
std::string path = dirname(info.dli_fname) + "/../../";
|
|
||||||
|
|
||||||
char *real = realpath(path.c_str(), nullptr);
|
|
||||||
if (!real)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
path = real;
|
|
||||||
free(real);
|
|
||||||
|
|
||||||
return path + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \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 directory,
|
|
||||||
* or an empty string otherwise
|
|
||||||
*/
|
|
||||||
std::string libcameraSourcePath()
|
|
||||||
{
|
|
||||||
std::string path = libcameraBuildPath();
|
|
||||||
if (path.empty())
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
path += "source";
|
|
||||||
|
|
||||||
char *real = realpath(path.c_str(), nullptr);
|
|
||||||
if (!real)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
path = real;
|
|
||||||
free(real);
|
|
||||||
|
|
||||||
struct stat statbuf;
|
|
||||||
int ret = stat(path.c_str(), &statbuf);
|
|
||||||
if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
return path + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn alignDown(unsigned int value, unsigned int alignment)
|
* \fn alignDown(unsigned int value, unsigned int alignment)
|
||||||
* \brief Align \a value down to \a alignment
|
* \brief Align \a value down to \a alignment
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue