updated build system
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
@@ -37,25 +37,6 @@ inline const std::array<std::string, 4U> attribute_namespaces = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
enum class launchctl_type : std::uint8_t {
|
||||
bootout,
|
||||
bootstrap,
|
||||
kickstart,
|
||||
};
|
||||
|
||||
struct plist_cfg final {
|
||||
std::vector<std::string> 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<int()> 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)
|
||||
|
@@ -308,95 +308,6 @@ auto create_daemon(std::function<int()> 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)
|
||||
|
@@ -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<std::string> 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<void(struct passwd *pass)>;
|
||||
|
||||
#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 <typename thread_t>
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user