Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local config file #24

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions src/libpisp/backend/backend_default_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
#include "backend.hpp"

#include <dlfcn.h>
#include <elf.h>
#include <fstream>
#include <link.h>
#include <string>
#include <vector>

Expand All @@ -25,6 +28,40 @@ using json = nlohmann::json;
namespace
{

// Check if the RPATH or RUNPATH definitions exist in the ELF file. If they don't exist, it means that meson has
// stripped them out when doing the install step.
//
// Source: https://stackoverflow.com/questions/2836330/is-there-a-programmatic-way-to-inspect-the-current-rpath-on-linux
bool is_installed()
{
const ElfW(Dyn) *dyn = _DYNAMIC;
for (; dyn->d_tag != DT_NULL; dyn++)
{
if (dyn->d_tag == DT_RPATH || dyn->d_tag == DT_RUNPATH)
return false;
}
return true;
}

std::string source_path()
{
Dl_info dl_info;
std::string path;

if (dladdr(reinterpret_cast<void *>(source_path), &dl_info))
path = dl_info.dli_fname;

if (path.empty())
return {};

auto const pos = path.find_last_of('/');
if (pos == std::string::npos)
return {};

path.erase(pos, path.length() - pos);
return path;
}

void initialise_debin(pisp_be_debin_config &debin, const json &root)
{
constexpr unsigned int num_coefs = sizeof(debin.coeffs) / sizeof(debin.coeffs[0]);
Expand Down Expand Up @@ -269,8 +306,22 @@ void BackEnd::InitialiseSharpen(pisp_be_sharpen_config &sharpen, pisp_be_sh_fc_c

void BackEnd::initialiseDefaultConfig(const std::string &filename)
{
std::string file = filename.empty() ? std::string(PISP_BE_CONFIG_DIR) + "/" + "backend_default_config.json"
: filename;
std::string file(filename);

if (file.empty())
{
if (!is_installed())
{
std::string path = source_path();
if (path.empty())
throw std::runtime_error("BE: Could not determine the local source path");

file = path + "/libpisp/backend/backend_default_config.json";
}
else
file = std::string(PISP_BE_CONFIG_DIR) + "/" + "backend_default_config.json";
}

std::ifstream ifs(file);
if (!ifs.good())
throw std::runtime_error("BE: Could not find config json file: " + file);
Expand Down
8 changes: 8 additions & 0 deletions src/libpisp/backend/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ install_headers(backend_headers, subdir: backend_include_dir)
install_data('backend_default_config.json',
install_dir : config_install_dir)

# Copy the json config file to the build directory for running locally.
custom_target('Default config to build dir',
input : 'backend_default_config.json',
output : 'backend_default_config.json',
command : ['cp', '@INPUT@', '@OUTPUT@'],
install : false,
build_by_default : true)

subdir('tiling')
5 changes: 5 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pisp_deps = [
dependency('threads')
]

# Meson version >= 0.64 can simply use dependency('dl') for this, but we don't want to bump up the min version just yet.
dl_dep = meson.get_compiler('c').find_library('dl', required : true)
pisp_deps += dl_dep

logging_dep = dependency('boost', modules : ['log', 'log_setup', 'thread', 'system'], required : get_option('logging'))
if logging_dep.found()
logging_args = ['-DPISP_LOGGING_ENABLE=1', '-DBOOST_BIND_GLOBAL_PLACEHOLDERS', '-DBOOST_LOG_DYN_LINK=1']
Expand Down Expand Up @@ -54,6 +58,7 @@ libpisp = library(
include_directories : include_directories(inc_dirs),
name_prefix : '',
install : true,
build_rpath : meson.project_source_root(),
dependencies : pisp_deps,
)

Expand Down
Loading