Skip to content

Commit

Permalink
Add a CPS_CONFIG_LIBDIR_NAME which overrides the libdir name rules
Browse files Browse the repository at this point in the history
This allows our unit tests to be portable without having to explicitly
override Meson's libdir setting
  • Loading branch information
dcbaker committed Mar 15, 2024
1 parent 56b433b commit 7f0627c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/cps/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/cps/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace cps {
struct Env {
std::optional<std::string> cps_path = std::nullopt;
std::optional<std::string> cps_prefix_path = std::nullopt;
std::optional<std::string> libdir = std::nullopt;
bool debug_spew = false;
};

Expand Down
4 changes: 2 additions & 2 deletions src/cps/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/cps/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#include <filesystem>

#include "env.hpp"

namespace cps::platform {

std::filesystem::path libdir();
std::filesystem::path libdir(const Env & env);

} // namespace platform
8 changes: 4 additions & 4 deletions src/cps/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace cps::search {
roots.emplace_back("/usr");
roots.emplace_back("/usr/local");

const std::vector<fs::path> segments{platform::libdir(), "share"};
const std::vector<fs::path> segments{platform::libdir(env), "share"};
std::vector<fs::path> paths;

if (env.cps_path) {
Expand Down Expand Up @@ -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

Expand All @@ -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{"/"};
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7f0627c

Please sign in to comment.