updated build system
This commit is contained in:
parent
c0dba76ecd
commit
99c0246720
24
support/3rd_party/src/utils/common.cpp
vendored
24
support/3rd_party/src/utils/common.cpp
vendored
@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "utils/common.hpp"
|
#include "utils/common.hpp"
|
||||||
|
|
||||||
|
#include "utils/path.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
namespace repertory::utils {
|
namespace repertory::utils {
|
||||||
@ -138,28 +139,7 @@ auto get_next_available_port(std::uint16_t first_port,
|
|||||||
#endif // defined(PROJECT_ENABLE_BOOST)
|
#endif // defined(PROJECT_ENABLE_BOOST)
|
||||||
|
|
||||||
auto resolve_variables(std::string str) -> std::string {
|
auto resolve_variables(std::string str) -> std::string {
|
||||||
#if defined(HAS_WORDEXP_H)
|
return utils::path::absolute(str);
|
||||||
wordexp_t wt{};
|
|
||||||
int ret{};
|
|
||||||
if ((ret = wordexp(std::string{str}.c_str(), &wt, 0)) != 0) {
|
|
||||||
throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret));
|
|
||||||
}
|
|
||||||
str = wt.we_wordv[0U];
|
|
||||||
wordfree(&wt);
|
|
||||||
#else // !defined(HAS_WORDEXP_H)
|
|
||||||
std::string dest;
|
|
||||||
dest.resize(::ExpandEnvironmentStringsA(str.c_str(), nullptr, 0));
|
|
||||||
::ExpandEnvironmentStringsA(str.c_str(), dest.data(),
|
|
||||||
static_cast<DWORD>(dest.size()));
|
|
||||||
str = std::string(dest.c_str(), strlen(dest.c_str()));
|
|
||||||
|
|
||||||
dest.resize(::GetFullPathNameA(str.c_str(), 0, nullptr, nullptr));
|
|
||||||
::GetFullPathNameA(str.c_str(), static_cast<DWORD>(dest.size()), dest.data(),
|
|
||||||
nullptr);
|
|
||||||
str = std::string(dest.c_str(), strlen(dest.c_str()));
|
|
||||||
#endif // defined(HAS_WORDEXP_H)
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto resolve_variables(std::wstring_view str) -> std::wstring {
|
auto resolve_variables(std::wstring_view str) -> std::wstring {
|
||||||
|
31
support/3rd_party/src/utils/path.cpp
vendored
31
support/3rd_party/src/utils/path.cpp
vendored
@ -36,23 +36,28 @@ static const std::wstring directory_seperator_str_w{
|
|||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
[[nodiscard]] auto resolve(std::string path) -> std::string {
|
[[nodiscard]] auto resolve(std::string path) -> std::string {
|
||||||
std::string home{};
|
#if defined(HAS_WORDEXP_H)
|
||||||
repertory::utils::use_getpwuid(getuid(), [&home](struct passwd *pw) {
|
wordexp_t wt{};
|
||||||
home = (pw->pw_dir ? pw->pw_dir : "");
|
int ret{};
|
||||||
if (home.empty() || ((home == "/") && (getuid() != 0))) {
|
if ((ret = wordexp(path.c_str(), &wt, 0)) != 0) {
|
||||||
home = repertory::utils::path::combine("/home", {pw->pw_name});
|
throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret));
|
||||||
}
|
}
|
||||||
});
|
path = wt.we_wordv[0U];
|
||||||
|
wordfree(&wt);
|
||||||
|
#else // !defined(HAS_WORDEXP_H)
|
||||||
|
utils::string::replace(path, "~", "%USERPROFILE%");
|
||||||
|
|
||||||
return repertory::utils::string::replace(path, "~", home);
|
std::string dest;
|
||||||
}
|
dest.resize(::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0));
|
||||||
|
::ExpandEnvironmentStringsA(path.c_str(), dest.data(),
|
||||||
|
static_cast<DWORD>(dest.size()));
|
||||||
|
path = dest.c_str();
|
||||||
|
|
||||||
[[nodiscard]] auto resolve(std::wstring_view path) -> std::wstring {
|
#endif // defined(HAS_WORDEXP_H)
|
||||||
return repertory::utils::string::from_utf8(
|
|
||||||
resolve(repertory::utils::string::to_utf8(path)));
|
return path;
|
||||||
}
|
}
|
||||||
#endif // !defined(_WIN32)
|
#endif // !defined(_WIN32)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory::utils::path {
|
namespace repertory::utils::path {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user