updated build system

This commit is contained in:
Scott E. Graves 2024-08-02 21:41:44 -05:00
parent c0dba76ecd
commit 99c0246720
2 changed files with 20 additions and 35 deletions

View File

@ -21,6 +21,7 @@
*/
#include "utils/common.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory::utils {
@ -138,28 +139,7 @@ auto get_next_available_port(std::uint16_t first_port,
#endif // defined(PROJECT_ENABLE_BOOST)
auto resolve_variables(std::string str) -> std::string {
#if defined(HAS_WORDEXP_H)
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;
return utils::path::absolute(str);
}
auto resolve_variables(std::wstring_view str) -> std::wstring {

View File

@ -36,23 +36,28 @@ static const std::wstring directory_seperator_str_w{
#if !defined(_WIN32)
[[nodiscard]] auto resolve(std::string path) -> std::string {
std::string home{};
repertory::utils::use_getpwuid(getuid(), [&home](struct passwd *pw) {
home = (pw->pw_dir ? pw->pw_dir : "");
if (home.empty() || ((home == "/") && (getuid() != 0))) {
home = repertory::utils::path::combine("/home", {pw->pw_name});
#if defined(HAS_WORDEXP_H)
wordexp_t wt{};
int ret{};
if ((ret = wordexp(path.c_str(), &wt, 0)) != 0) {
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 {
return repertory::utils::string::from_utf8(
resolve(repertory::utils::string::to_utf8(path)));
#endif // defined(HAS_WORDEXP_H)
return path;
}
#endif // !defined(_WIN32)
} // namespace
namespace repertory::utils::path {