diff --git a/meson.build b/meson.build index 6d6beed..b092c1c 100644 --- a/meson.build +++ b/meson.build @@ -39,7 +39,10 @@ test( find_program('python', version : '>=3.11', required : build_tests, disabler : true), args: [files('tests/runner.py'), cps_config, 'tests/cases.toml'], protocol : 'tap', - env : {'CPS_PREFIX_PATH' : meson.current_source_dir() / 'tests' / 'cases' }, + env : { + 'CPS_PREFIX_PATH' : meson.current_source_dir() / 'tests' / 'cases', + 'CPS_CONFIG_LIBDIR_NAME' : 'lib', + }, ) dep_gtest = dependency('gtest_main', required : build_tests, disabler : true, allow_fallback : true) diff --git a/src/cps/env.cpp b/src/cps/env.cpp index 8fe4b71..c5369b4 100644 --- a/src/cps/env.cpp +++ b/src/cps/env.cpp @@ -17,6 +17,9 @@ namespace cps { if (const char * env_c = std::getenv("CPS_PREFIX_PATH")) { env.cps_prefix_path = std::string(env_c); } + if (const char * env_c = std::getenv("CPS_CONFIG_LIBDIR_NAME")) { + env.libdir = std::string(env_c); + } if (std::getenv("PKG_CONFIG_DEBUG_SPEW") || std::getenv("CPS_CONFIG_DEBUG_SPEW")) { env.debug_spew = true; } diff --git a/src/cps/env.hpp b/src/cps/env.hpp index 9b12160..871cdea 100644 --- a/src/cps/env.hpp +++ b/src/cps/env.hpp @@ -12,6 +12,7 @@ namespace cps { struct Env { std::optional cps_path = std::nullopt; std::optional cps_prefix_path = std::nullopt; + std::optional libdir = std::nullopt; bool debug_spew = false; }; diff --git a/src/cps/platform.cpp b/src/cps/platform.cpp index 63af296..5647798 100644 --- a/src/cps/platform.cpp +++ b/src/cps/platform.cpp @@ -8,12 +8,12 @@ namespace fs = std::filesystem; namespace cps::platform { - fs::path libdir() { + fs::path libdir(const Env & env) { // TODO: libdir needs to be configurable based on the personality, // and different name schemes. // This is complicated by the fact that different distros have // different schemes. - return CPS_LIBDIR; + return env.libdir.value_or(CPS_LIBDIR); } } // namespace platform diff --git a/src/cps/platform.hpp b/src/cps/platform.hpp index 1b8feb9..ca2f748 100644 --- a/src/cps/platform.hpp +++ b/src/cps/platform.hpp @@ -9,8 +9,10 @@ #include +#include "env.hpp" + namespace cps::platform { - std::filesystem::path libdir(); + std::filesystem::path libdir(const Env & env); } // namespace platform diff --git a/src/cps/search.cpp b/src/cps/search.cpp index aa93988..4d34679 100644 --- a/src/cps/search.cpp +++ b/src/cps/search.cpp @@ -105,7 +105,7 @@ namespace cps::search { roots.emplace_back("/usr"); roots.emplace_back("/usr/local"); - const std::vector segments{platform::libdir(), "share"}; + const std::vector segments{platform::libdir(env), "share"}; std::vector paths; if (env.cps_path) { @@ -294,7 +294,7 @@ namespace cps::search { } } - fs::path calculate_prefix(const fs::path & path, std::string_view name) { + fs::path calculate_prefix(const fs::path & path, std::string_view name, const Env & env) { // TODO: Windows // TODO: Mac @@ -319,7 +319,7 @@ namespace cps::search { } // Match only share or libdir, but not a potential odd situation // like `/opt/share/libdir/` - if (split.back() == "share" || split.back() == platform::libdir()) { + if (split.back() == "share" || split.back() == platform::libdir(env)) { split.pop_back(); } fs::path p{"/"}; @@ -408,7 +408,7 @@ namespace cps::search { auto && split = utils::split(s, "/"); if (split[0] == "@prefix@") { auto p = - prefix_path.value_or(calculate_prefix(node->data.package.cps_path, node->data.package.name)); + prefix_path.value_or(calculate_prefix(node->data.package.cps_path, node->data.package.name, env)); for (auto it = split.begin() + 1; it != split.end(); ++it) { p /= *it; }