Skip to content

Commit 8acd27a

Browse files
committed
Add a CPS_CONFIG_LIBDIR_NAME which overrides the libdir name rules
This allows our unit tests to be portable without having to explicitly override Meson's libdir setting
1 parent f4cf481 commit 8acd27a

6 files changed

Lines changed: 18 additions & 9 deletions

File tree

meson.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ test(
3939
find_program('python', version : '>=3.11', required : build_tests, disabler : true),
4040
args: [files('tests/runner.py'), cps_config, 'tests/cases.toml'],
4141
protocol : 'tap',
42-
env : {'CPS_PREFIX_PATH' : meson.current_source_dir() / 'tests' / 'cases' },
42+
env : {
43+
'CPS_PREFIX_PATH' : meson.current_source_dir() / 'tests' / 'cases',
44+
'CPS_CONFIG_LIBDIR_NAME' : 'lib',
45+
},
4346
)
4447

4548
dep_gtest = dependency('gtest_main', required : build_tests, disabler : true, allow_fallback : true)

src/cps/env.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace cps {
1717
if (const char * env_c = std::getenv("CPS_PREFIX_PATH")) {
1818
env.cps_prefix_path = std::string(env_c);
1919
}
20+
if (const char * env_c = std::getenv("CPS_CONFIG_LIBDIR_NAME")) {
21+
env.libdir = std::string(env_c);
22+
}
2023
if (std::getenv("PKG_CONFIG_DEBUG_SPEW") || std::getenv("CPS_CONFIG_DEBUG_SPEW")) {
2124
env.debug_spew = true;
2225
}

src/cps/env.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace cps {
1212
struct Env {
1313
std::optional<std::string> cps_path = std::nullopt;
1414
std::optional<std::string> cps_prefix_path = std::nullopt;
15+
std::optional<std::string> libdir = std::nullopt;
1516
bool debug_spew = false;
1617
};
1718

src/cps/platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace fs = std::filesystem;
88

99
namespace cps::platform {
1010

11-
fs::path libdir() {
11+
fs::path libdir(const Env & env) {
1212
// TODO: libdir needs to be configurable based on the personality,
1313
// and different name schemes.
1414
// This is complicated by the fact that different distros have
1515
// different schemes.
16-
return CPS_LIBDIR;
16+
return env.libdir.value_or(CPS_LIBDIR);
1717
}
1818

1919
} // namespace cps::platform

src/cps/platform.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#include <filesystem>
1111

12+
#include "env.hpp"
13+
1214
namespace cps::platform {
1315

14-
std::filesystem::path libdir();
16+
std::filesystem::path libdir(const Env & env);
1517

1618
} // namespace cps::platform

src/cps/search.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace cps::search {
105105
roots.emplace_back("/usr");
106106
roots.emplace_back("/usr/local");
107107

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

111111
if (env.cps_path) {
@@ -294,7 +294,7 @@ namespace cps::search {
294294
}
295295
}
296296

297-
fs::path calculate_prefix(const fs::path & path, std::string_view name) {
297+
fs::path calculate_prefix(const fs::path & path, std::string_view name, const Env & env) {
298298
// TODO: Windows
299299
// TODO: Mac
300300

@@ -319,7 +319,7 @@ namespace cps::search {
319319
}
320320
// Match only share or libdir, but not a potential odd situation
321321
// like `/opt/share/libdir/`
322-
if (split.back() == "share" || split.back() == platform::libdir()) {
322+
if (split.back() == "share" || split.back() == platform::libdir(env)) {
323323
split.pop_back();
324324
}
325325
fs::path p{"/"};
@@ -407,8 +407,8 @@ namespace cps::search {
407407
// TODO: Windows…
408408
auto && split = utils::split(s, "/");
409409
if (split[0] == "@prefix@") {
410-
auto p =
411-
prefix_path.value_or(calculate_prefix(node->data.package.cps_path, node->data.package.name));
410+
auto p = prefix_path.value_or(
411+
calculate_prefix(node->data.package.cps_path, node->data.package.name, env));
412412
for (auto it = split.begin() + 1; it != split.end(); ++it) {
413413
p /= *it;
414414
}

0 commit comments

Comments
 (0)