From ba21676c2b3b77c6f261f318d58c9ffe27e1329e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 8 Sep 2025 09:16:10 -0500 Subject: [PATCH] updated build system --- .../include/utils/unix/unix_utils.hpp | 27 ------ .../src/utils/unix/unix_utils.cpp | 89 ------------------ support/include/utils/unix.hpp | 32 +++++++ support/src/utils/unix.cpp | 93 +++++++++++++++++++ 4 files changed, 125 insertions(+), 116 deletions(-) diff --git a/repertory/librepertory/include/utils/unix/unix_utils.hpp b/repertory/librepertory/include/utils/unix/unix_utils.hpp index fdbe7c2e..e95ddb65 100644 --- a/repertory/librepertory/include/utils/unix/unix_utils.hpp +++ b/repertory/librepertory/include/utils/unix/unix_utils.hpp @@ -37,25 +37,6 @@ inline const std::array attribute_namespaces = { }; #endif -#if defined(__APPLE__) -enum class launchctl_type : std::uint8_t { - bootout, - bootstrap, - kickstart, -}; - -struct plist_cfg final { - std::vector args; - bool keep_alive{false}; - std::string label; - std::string plist_path; - bool run_at_load{false}; - std::string stderr_log{"/tmp/stderr.log"}; - std::string stdout_log{"/tmp/stdout.log"}; - std::string working_dir{"/tmp"}; -}; -#endif // defined(__APPLE__) - [[nodiscard]] auto create_daemon(std::function main_func) -> int; [[nodiscard]] auto from_api_error(api_error err) -> int; @@ -67,14 +48,6 @@ struct plist_cfg final { void windows_create_to_unix(const UINT32 &create_options, const UINT32 &granted_access, std::uint32_t &flags, remote::file_mode &mode); -#if defined(__APPLE__) -[[nodiscard]] auto generate_launchd_plist(const plist_cfg &cfg, - bool overwrite_existing = true) - -> bool; - -[[nodiscard]] auto launchctl_command(std::string_view label, - launchctl_type type) -> int; -#endif // defined(__APPLE__) } // namespace repertory::utils #endif // !defined(_WIN32) diff --git a/repertory/librepertory/src/utils/unix/unix_utils.cpp b/repertory/librepertory/src/utils/unix/unix_utils.cpp index a8e32a31..1b7f8b57 100644 --- a/repertory/librepertory/src/utils/unix/unix_utils.cpp +++ b/repertory/librepertory/src/utils/unix/unix_utils.cpp @@ -308,95 +308,6 @@ auto create_daemon(std::function main_func) -> int { return 0; } -#if defined(__APPLE__) -auto generate_launchd_plist(const plist_cfg &cfg, bool overwrite_existing) - -> bool { - auto file = utils::path::combine(cfg.plist_path, {cfg.label + ".plist"}); - if (utils::file::file{file}.exists() && not overwrite_existing) { - return true; - } - - pugi::xml_document doc; - auto decl = doc.append_child(pugi::node_declaration); - decl.append_attribute("version") = "1.0"; - decl.append_attribute("encoding") = "UTF-8"; - - auto plist = doc.append_child("plist"); - plist.append_attribute("version") = "1.0"; - - auto dict = plist.append_child("dict"); - - dict.append_child("key").text().set("Label"); - dict.append_child("string").text().set(cfg.label.c_str()); - - dict.append_child("key").text().set("ProgramArguments"); - auto array = dict.append_child("array"); - for (const auto &arg : cfg.args) { - array.append_child("string").text().set(arg.c_str()); - } - - dict.append_child("key").text().set("EnvironmentVariables"); - pugi::xml_node env_dict = dict.append_child("dict"); - if (not utils::get_environment_variable("PROJECT_TEST_CONFIG_DIR").empty()) { - env_dict.append_child("key").text().set("PROJECT_TEST_CONFIG_DIR"); - env_dict.append_child("string").text().set( - utils::get_environment_variable("PROJECT_TEST_CONFIG_DIR")); - } - if (not utils::get_environment_variable("PROJECT_TEST_INPUT_DIR").empty()) { - env_dict.append_child("key").text().set("PROJECT_TEST_INPUT_DIR"); - env_dict.append_child("string").text().set( - utils::get_environment_variable("PROJECT_TEST_INPUT_DIR")); - } - - dict.append_child("key").text().set("WorkingDirectory"); - dict.append_child("string").text().set(cfg.working_dir.c_str()); - - dict.append_child("key").text().set("KeepAlive"); - dict.append_child(cfg.keep_alive ? "true" : "false"); - - dict.append_child("key").text().set("RunAtLoad"); - dict.append_child(cfg.run_at_load ? "true" : "false"); - - dict.append_child("key").text().set("StandardOutPath"); - dict.append_child("string").text().set(cfg.stdout_log.c_str()); - - dict.append_child("key").text().set("StandardErrorPath"); - dict.append_child("string").text().set(cfg.stderr_log.c_str()); - - return doc.save_file(file.c_str(), " ", - pugi::format_indent | pugi::format_write_bom); -} - -auto launchctl_command(std::string_view label, launchctl_type type) -> int { - switch (type) { - case launchctl_type::bootout: - return system( - fmt::format("launchctl bootout gui/{} '{}' 1>/dev/null 2>&1", getuid(), - utils::path::combine("~", - { - "/Library/LaunchAgents", - fmt::format("{}.plist", label), - })) - .c_str()); - - case launchctl_type::bootstrap: - return system( - fmt::format("launchctl bootstrap gui/{} '{}' 1>/dev/null 2>&1", - getuid(), - utils::path::combine("~", - { - "/Library/LaunchAgents", - fmt::format("{}.plist", label), - })) - .c_str()); - - case launchctl_type::kickstart: - return system( - fmt::format("launchctl kickstart gui/{}/{}", getuid(), label).c_str()); - } - return -1; -} -#endif // defined(__APPLE__) } // namespace repertory::utils #endif // !defined(_WIN32) diff --git a/support/include/utils/unix.hpp b/support/include/utils/unix.hpp index 821034ec..1d172450 100644 --- a/support/include/utils/unix.hpp +++ b/support/include/utils/unix.hpp @@ -40,6 +40,27 @@ struct autostart_cfg final { }; #endif // defined(__linux__) +#if defined(__APPLE__) +enum class launchctl_type : std::uint8_t { + bootout, + bootstrap, + kickstart, +}; + +#if defined(PROJECT_ENABLE_PUGIXML) +struct plist_cfg final { + std::vector args; + bool keep_alive{false}; + std::string label; + std::string plist_path; + bool run_at_load{false}; + std::string stderr_log{"/tmp/stderr.log"}; + std::string stdout_log{"/tmp/stdout.log"}; + std::string working_dir{"/tmp"}; +}; +#endif // defined(PROJECT_ENABLE_PUGIXML) +#endif // defined(__APPLE__) + using passwd_callback_t = std::function; #if defined(__APPLE__) @@ -71,6 +92,17 @@ void set_last_error_code(int error_code); [[nodiscard]] auto remove_autostart_entry(std::string_view name) -> bool; #endif // defined(__linux__) +#if defined(__APPLE__) +#if defined(PROJECT_ENABLE_PUGIXML) +[[nodiscard]] auto generate_launchd_plist(const plist_cfg &cfg, + bool overwrite_existing = true) + -> bool; +#endif // defined(PROJECT_ENABLE_PUGIXML) + +[[nodiscard]] auto launchctl_command(std::string_view label, + launchctl_type type) -> int; +#endif // defined(__APPLE__) + // template implementations #if defined(__APPLE__) template diff --git a/support/src/utils/unix.cpp b/support/src/utils/unix.cpp index 0a41ad7d..759da41c 100644 --- a/support/src/utils/unix.cpp +++ b/support/src/utils/unix.cpp @@ -306,6 +306,99 @@ auto use_getpwuid(uid_t uid, passwd_callback_t callback) -> result { .function_name = std::string{function_name}, }; } + +#if defined(__APPLE__) +#if defined(PROJECT_ENABLE_PUGIXML) +auto generate_launchd_plist(const plist_cfg &cfg, bool overwrite_existing) + -> bool { + auto file = utils::path::combine(cfg.plist_path, {cfg.label + ".plist"}); + if (utils::file::file{file}.exists() && not overwrite_existing) { + return true; + } + + pugi::xml_document doc; + auto decl = doc.append_child(pugi::node_declaration); + decl.append_attribute("version") = "1.0"; + decl.append_attribute("encoding") = "UTF-8"; + + auto plist = doc.append_child("plist"); + plist.append_attribute("version") = "1.0"; + + auto dict = plist.append_child("dict"); + + dict.append_child("key").text().set("Label"); + dict.append_child("string").text().set(cfg.label.c_str()); + + dict.append_child("key").text().set("ProgramArguments"); + auto array = dict.append_child("array"); + for (const auto &arg : cfg.args) { + array.append_child("string").text().set(arg.c_str()); + } + + dict.append_child("key").text().set("EnvironmentVariables"); + pugi::xml_node env_dict = dict.append_child("dict"); + if (not utils::get_environment_variable("PROJECT_TEST_CONFIG_DIR").empty()) { + env_dict.append_child("key").text().set("PROJECT_TEST_CONFIG_DIR"); + env_dict.append_child("string").text().set( + utils::get_environment_variable("PROJECT_TEST_CONFIG_DIR")); + } + if (not utils::get_environment_variable("PROJECT_TEST_INPUT_DIR").empty()) { + env_dict.append_child("key").text().set("PROJECT_TEST_INPUT_DIR"); + env_dict.append_child("string").text().set( + utils::get_environment_variable("PROJECT_TEST_INPUT_DIR")); + } + + dict.append_child("key").text().set("WorkingDirectory"); + dict.append_child("string").text().set(cfg.working_dir.c_str()); + + dict.append_child("key").text().set("KeepAlive"); + dict.append_child(cfg.keep_alive ? "true" : "false"); + + dict.append_child("key").text().set("RunAtLoad"); + dict.append_child(cfg.run_at_load ? "true" : "false"); + + dict.append_child("key").text().set("StandardOutPath"); + dict.append_child("string").text().set(cfg.stdout_log.c_str()); + + dict.append_child("key").text().set("StandardErrorPath"); + dict.append_child("string").text().set(cfg.stderr_log.c_str()); + + return doc.save_file(file.c_str(), " ", + pugi::format_indent | pugi::format_write_bom); +} +#endif // defined(PROJECT_ENABLE_PUGIXML) + +auto launchctl_command(std::string_view label, launchctl_type type) -> int { + switch (type) { + case launchctl_type::bootout: + return system( + fmt::format("launchctl bootout gui/{} '{}' 1>/dev/null 2>&1", getuid(), + utils::path::combine("~", + { + "/Library/LaunchAgents", + fmt::format("{}.plist", label), + })) + .c_str()); + + case launchctl_type::bootstrap: + return system( + fmt::format("launchctl bootstrap gui/{} '{}' 1>/dev/null 2>&1", + getuid(), + utils::path::combine("~", + { + "/Library/LaunchAgents", + fmt::format("{}.plist", label), + })) + .c_str()); + + case launchctl_type::kickstart: + return system( + fmt::format("launchctl kickstart gui/{}/{}", getuid(), label).c_str()); + } + + return -1; +} +#endif // defined(__APPLE__) } // namespace repertory::utils #endif // !defined(_WIN32)