hyprpm: handle failed compilations gracefully

This commit is contained in:
Vaxry 2024-01-07 18:15:51 +01:00
parent 7904188de9
commit 9f2bde925b
4 changed files with 24 additions and 8 deletions

View file

@ -47,7 +47,8 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) {
DATA.emplace(p.name, toml::table{ DATA.emplace(p.name, toml::table{
{"filename", p.name + ".so"}, {"filename", p.name + ".so"},
{"enabled", p.enabled} {"enabled", p.enabled},
{"failed", p.failed}
}); });
} }
// clang-format on // clang-format on
@ -172,9 +173,10 @@ std::vector<SPluginRepository> DataState::getAllRepositories() {
continue; continue;
const auto ENABLED = STATE[key]["enabled"].value_or(false); const auto ENABLED = STATE[key]["enabled"].value_or(false);
const auto FAILED = STATE[key]["failed"].value_or(false);
const auto FILENAME = STATE[key]["filename"].value_or(""); const auto FILENAME = STATE[key]["filename"].value_or("");
repo.plugins.push_back(SPlugin{std::string{key.str()}, FILENAME, ENABLED}); repo.plugins.push_back(SPlugin{std::string{key.str()}, FILENAME, ENABLED, FAILED});
} }
repos.push_back(repo); repos.push_back(repo);
@ -201,6 +203,11 @@ bool DataState::setPluginEnabled(const std::string& name, bool enabled) {
if (key.str() != name) if (key.str() != name)
continue; continue;
const auto FAILED = STATE[key]["failed"].value_or(false);
if (FAILED)
return false;
(*STATE[key].as_table()).insert_or_assign("enabled", enabled); (*STATE[key].as_table()).insert_or_assign("enabled", enabled);
std::ofstream state(entry.path().string() + "/state.toml", std::ios::trunc); std::ofstream state(entry.path().string() + "/state.toml", std::ios::trunc);

View file

@ -19,6 +19,7 @@ class CManifest {
std::vector<std::string> authors; std::vector<std::string> authors;
std::vector<std::string> buildSteps; std::vector<std::string> buildSteps;
std::string output; std::string output;
bool failed = false;
}; };
struct { struct {

View file

@ -6,7 +6,8 @@
struct SPlugin { struct SPlugin {
std::string name; std::string name;
std::string filename; std::string filename;
bool enabled; bool enabled = false;
bool failed = false;
}; };
struct SPluginRepository { struct SPluginRepository {

View file

@ -195,12 +195,14 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) {
} }
if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) { if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " Plugin " << p.name << " failed to build.\n"; progress.printMessageAbove(std::string{Colors::RED} + "" + Colors::RESET + " Plugin " + p.name + " failed to build.\n");
if (m_bVerbose) if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n";
return false; p.failed = true;
continue;
} }
progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " built " + p.name + " into " + p.output); progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " built " + p.name + " into " + p.output);
@ -220,7 +222,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) {
repo.url = url; repo.url = url;
repo.hash = repohash; repo.hash = repohash;
for (auto& p : pManifest->m_vPlugins) { for (auto& p : pManifest->m_vPlugins) {
repo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/new/" + p.output, false}); repo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/new/" + p.output, false, p.failed});
} }
DataState::addNewPluginRepo(repo); DataState::addNewPluginRepo(repo);
@ -696,8 +698,13 @@ void CPluginManager::listAllPlugins() {
std::cout << std::string{Colors::RESET} + " → Repository " + r.name + ":\n"; std::cout << std::string{Colors::RESET} + " → Repository " + r.name + ":\n";
for (auto& p : r.plugins) { for (auto& p : r.plugins) {
std::cout << std::string{Colors::RESET} + " │ Plugin " + p.name + "\n └─ enabled: " << (p.enabled ? Colors::GREEN : Colors::RED) << (p.enabled ? "true" : "false")
<< Colors::RESET << "\n"; std::cout << std::string{Colors::RESET} + " │ Plugin " + p.name;
if (!p.failed)
std::cout << "\n └─ enabled: " << (p.enabled ? Colors::GREEN : Colors::RED) << (p.enabled ? "true" : "false") << Colors::RESET << "\n";
else
std::cout << "\n └─ enabled: " << Colors::RED << "Plugin failed to build" << Colors::RESET << "\n";
} }
} }
} }