updated build system
This commit is contained in:
parent
9c01d51334
commit
fff3dc4685
@ -30,10 +30,13 @@
|
|||||||
namespace {
|
namespace {
|
||||||
[[nodiscard]] auto resolve(std::string path) -> std::string {
|
[[nodiscard]] auto resolve(std::string path) -> std::string {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (repertory::utils::string::contains(path, "~\\") ||
|
if (repertory::utils::string::contains(path, "~\\")) {
|
||||||
repertory::utils::string::contains(path, "%")) {
|
|
||||||
repertory::utils::string::replace(path, "~\\", "%USERPROFILE%\\");
|
repertory::utils::string::replace(path, "~\\", "%USERPROFILE%\\");
|
||||||
|
} else if (repertory::utils::string::contains(path, "~/")) {
|
||||||
|
repertory::utils::string::replace(path, "~/", "%USERPROFILE%\\");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repertory::utils::string::contains(path, "%")) {
|
||||||
auto size = ::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0);
|
auto size = ::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0);
|
||||||
|
|
||||||
std::string dest;
|
std::string dest;
|
||||||
@ -43,6 +46,10 @@ namespace {
|
|||||||
path = dest.c_str();
|
path = dest.c_str();
|
||||||
}
|
}
|
||||||
#else // !defined (_WIN32)
|
#else // !defined (_WIN32)
|
||||||
|
if (repertory::utils::string::contains(path, "~\\")) {
|
||||||
|
repertory::utils::string::replace(path, "~\\", "~/");
|
||||||
|
}
|
||||||
|
|
||||||
if (repertory::utils::string::contains(path, "~/")) {
|
if (repertory::utils::string::contains(path, "~/")) {
|
||||||
std::string home{};
|
std::string home{};
|
||||||
auto res =
|
auto res =
|
||||||
@ -57,11 +64,11 @@ namespace {
|
|||||||
throw std::runtime_error("failed to getpwuid: " + res.reason);
|
throw std::runtime_error("failed to getpwuid: " + res.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
return repertory::utils::string::replace(path, "~/", home + "/");
|
path = repertory::utils::string::replace(path, "~/", home + "/");
|
||||||
}
|
}
|
||||||
#endif // defined (_WIN32)
|
#endif // defined (_WIN32)
|
||||||
|
|
||||||
return path;
|
return finalize(path);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -72,7 +79,7 @@ auto absolute(std::string_view path) -> std::string {
|
|||||||
return abs_path;
|
return abs_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_path = resolve(finalize(abs_path));
|
abs_path = resolve(abs_path);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (not utils::string::contains(abs_path, dot)) {
|
if (not utils::string::contains(abs_path, dot)) {
|
||||||
return abs_path;
|
return abs_path;
|
||||||
|
@ -387,16 +387,7 @@ TEST(utils_path, absolute) {
|
|||||||
|
|
||||||
path = utils::path::absolute(R"(\\server\share)");
|
path = utils::path::absolute(R"(\\server\share)");
|
||||||
EXPECT_STREQ(R"(/server/share)", path.c_str());
|
EXPECT_STREQ(R"(/server/share)", path.c_str());
|
||||||
|
|
||||||
auto home_env = utils::get_environment_variable("HOME");
|
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
auto home = utils::path::absolute(home_env);
|
|
||||||
|
|
||||||
path = utils::path::absolute("~/");
|
|
||||||
EXPECT_STREQ(home.c_str(), path.c_str());
|
|
||||||
|
|
||||||
path = utils::path::absolute("~\\");
|
|
||||||
EXPECT_STREQ(home.c_str(), path.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(utils_path, absolute_can_resolve_path_variables) {
|
TEST(utils_path, absolute_can_resolve_path_variables) {
|
||||||
@ -411,19 +402,20 @@ TEST(utils_path, absolute_can_resolve_path_variables) {
|
|||||||
static_cast<DWORD>(home.size()));
|
static_cast<DWORD>(home.size()));
|
||||||
home = utils::path::absolute(home);
|
home = utils::path::absolute(home);
|
||||||
|
|
||||||
auto expanded_str = utils::path::absolute("%USERPROFILE%");
|
EXPECT_STREQ(home.c_str(), utils::path::absolute("%USERPROFILE%").c_str());
|
||||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
|
||||||
|
|
||||||
expanded_str = utils::path::absolute("~\\");
|
|
||||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
|
||||||
EXPECT_STREQ((home + home).c_str(), expanded_str.c_str());
|
|
||||||
#else // !defined(_WIN32)
|
#else // !defined(_WIN32)
|
||||||
home = std::getenv("HOME");
|
home = std::getenv("HOME");
|
||||||
home = utils::path::absolute(home);
|
home = utils::path::absolute(home);
|
||||||
|
|
||||||
auto expanded_str = utils::path::absolute("~/");
|
|
||||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
|
auto expanded_str = utils::path::absolute("~\\");
|
||||||
|
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||||
|
|
||||||
|
expanded_str = utils::path::absolute("~/");
|
||||||
|
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||||
|
|
||||||
|
expanded_str = utils::path::absolute("~");
|
||||||
|
EXPECT_STREQ("~", expanded_str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(utils_path, get_parent_path) {
|
TEST(utils_path, get_parent_path) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user