diff options
author | Vaxry <[email protected]> | 2024-04-05 00:44:21 +0100 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-04-05 00:46:37 +0100 |
commit | 1ae592fcd94b86c4fee6b91786dfdc78724930fe (patch) | |
tree | 40b566cbcf0aa1c92f28c9ab4ff8e91b5639a8ba | |
parent | 51b3148f097f7cd371622aff5c144ca6ccbeda92 (diff) | |
download | Hyprland-1ae592fcd94b86c4fee6b91786dfdc78724930fe.tar.gz Hyprland-1ae592fcd94b86c4fee6b91786dfdc78724930fe.zip |
hyprpm: add support for minimum versions
-rw-r--r-- | hyprpm/src/core/Manifest.cpp | 1 | ||||
-rw-r--r-- | hyprpm/src/core/Manifest.hpp | 1 | ||||
-rw-r--r-- | hyprpm/src/core/PluginManager.cpp | 46 | ||||
-rw-r--r-- | hyprpm/src/core/PluginManager.hpp | 1 | ||||
-rwxr-xr-x | scripts/generateVersion.sh | 2 | ||||
-rw-r--r-- | src/debug/HyprCtl.cpp | 5 | ||||
-rw-r--r-- | src/plugins/PluginAPI.cpp | 2 | ||||
-rw-r--r-- | src/plugins/PluginAPI.hpp | 1 | ||||
-rw-r--r-- | src/version.h.in | 1 |
9 files changed, 47 insertions, 13 deletions
diff --git a/hyprpm/src/core/Manifest.cpp b/hyprpm/src/core/Manifest.cpp index 27ad058a..42a8357c 100644 --- a/hyprpm/src/core/Manifest.cpp +++ b/hyprpm/src/core/Manifest.cpp @@ -75,6 +75,7 @@ CManifest::CManifest(const eManifestType type, const std::string& path) { for (auto& plugin : m_vPlugins) { plugin.description = manifest[plugin.name]["description"].value_or("?"); plugin.output = manifest[plugin.name]["output"].value_or("?"); + plugin.since = manifest[plugin.name]["since_hyprland"].value_or(0); auto authors = manifest[plugin.name]["authors"].as_array(); if (authors) { for (auto&& a : *authors) { diff --git a/hyprpm/src/core/Manifest.hpp b/hyprpm/src/core/Manifest.hpp index 55b4a7f0..19f967eb 100644 --- a/hyprpm/src/core/Manifest.hpp +++ b/hyprpm/src/core/Manifest.hpp @@ -19,6 +19,7 @@ class CManifest { std::vector<std::string> authors; std::vector<std::string> buildSteps; std::string output; + int since = 0; bool failed = false; }; diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 956c0612..64b87379 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -70,10 +70,22 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() { std::string hlbranch = HLVERCALL.substr(HLVERCALL.find("from branch") + 12); hlbranch = hlbranch.substr(0, hlbranch.find(" at commit ")); + std::string hlcommits; + + if (HLVERCALL.contains("commits:")) { + hlcommits = HLVERCALL.substr(HLVERCALL.find("commits:") + 10); + hlcommits = hlcommits.substr(0, hlcommits.find(" ")); + } + + int commits = 0; + try { + commits = std::stoi(hlcommits); + } catch (...) { ; } + if (m_bVerbose) std::cout << Colors::BLUE << "[v] " << Colors::RESET << "parsed commit " << hlcommit << " at branch " << hlbranch << "\n"; - ver = SHyprlandVersion{hlbranch, hlcommit}; + ver = SHyprlandVersion{hlbranch, hlcommit, commits}; return ver; } @@ -214,6 +226,12 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& for (auto& p : pManifest->m_vPlugins) { std::string out; + if (p.since > HLVER.commits) { + progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Not building " + p.name + ": your Hyprland version is too old.\n"); + p.failed = true; + continue; + } + progress.printMessageAbove(std::string{Colors::RESET} + " → Building " + p.name); for (auto& bs : p.buildSteps) { @@ -225,10 +243,12 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) { - progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Plugin " + p.name + " failed to build.\n" << " This likely means that the plugin is either outdated, not yet available for your version, or broken.\n Try re-running with -v to see more verbose output.\n"); + progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Plugin " + p.name + " failed to build.\n" + + " This likely means that the plugin is either outdated, not yet available for your version, or broken.\n If you are on -git, update " + "first.\n Try re-running with -v to see " + "more verbose output.\n"); p.failed = true; - continue; } @@ -576,10 +596,15 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { } } - bool failed = false; for (auto& p : pManifest->m_vPlugins) { std::string out; + if (p.since > HLVER.commits) { + progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Not building " + p.name + ": your Hyprland version is too old.\n"); + p.failed = true; + continue; + } + progress.printMessageAbove(std::string{Colors::RESET} + " → Building " + p.name); for (auto& bs : p.buildSteps) { @@ -591,17 +616,18 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; if (!std::filesystem::exists("/tmp/hyprpm/update/" + p.output)) { - std::cerr << "\n" << Colors::RED << "✖" << Colors::RESET << " Plugin " << p.name << " failed to build.\n" << " This likely means that the plugin is either outdated, not yet available for your version, or broken.\n Try re-running with -v to see more verbose output.\n"; - failed = true; - break; + std::cerr << "\n" + << Colors::RED << "✖" << Colors::RESET << " Plugin " << p.name << " failed to build.\n" + << " This likely means that the plugin is either outdated, not yet available for your version, or broken.\n If you are on -git, update first.\n Try " + "re-running with -v to see more verbose " + "output.\n"; + p.failed = true; + continue; } progress.printMessageAbove(std::string{Colors::GREEN} + "✔" + Colors::RESET + " built " + p.name + " into " + p.output); } - if (failed) - continue; - // add repo toml to DataState SPluginRepository newrepo = repo; newrepo.plugins.clear(); diff --git a/hyprpm/src/core/PluginManager.hpp b/hyprpm/src/core/PluginManager.hpp index 028e6357..901a9b4b 100644 --- a/hyprpm/src/core/PluginManager.hpp +++ b/hyprpm/src/core/PluginManager.hpp @@ -32,6 +32,7 @@ enum ePluginLoadStateReturn { struct SHyprlandVersion { std::string branch; std::string hash; + int commits = 0; }; class CPluginManager { diff --git a/scripts/generateVersion.sh b/scripts/generateVersion.sh index 443c5c54..b0993709 100755 --- a/scripts/generateVersion.sh +++ b/scripts/generateVersion.sh @@ -7,6 +7,7 @@ MESSAGE=$(git show ${GIT_COMMIT_HASH} | head -n 5 | tail -n 1 | sed -e 's/#//g' DATE=$(git show ${GIT_COMMIT_HASH} --no-patch --format=%cd --date=local) DIRTY=$(git diff-index --quiet HEAD -- || echo dirty) TAG=$(git describe --tags) +COMMITS=$(git rev-list --count HEAD) sed -i -e "s#@HASH@#${HASH}#" ./src/version.h sed -i -e "s#@BRANCH@#${BRANCH}#" ./src/version.h @@ -14,3 +15,4 @@ sed -i -e "s#@MESSAGE@#${MESSAGE}#" ./src/version.h sed -i -e "s#@DATE@#${DATE}#" ./src/version.h sed -i -e "s#@DIRTY@#${DIRTY}#" ./src/version.h sed -i -e "s#@TAG@#${TAG}#" ./src/version.h +sed -i -e "s#@COMMITS@#${COMMITS}#" ./src/version.h diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 3c53d97f..d672a2d0 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -810,7 +810,7 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { std::string result = "Hyprland, built from branch " + std::string(GIT_BRANCH) + " at commit " + GIT_COMMIT_HASH + " " + GIT_DIRTY + " (" + commitMsg + - ").\nDate: " + GIT_COMMIT_DATE + "\nTag: " + GIT_TAG + "\n\nflags: (if any)\n"; + ").\nDate: " + GIT_COMMIT_DATE + "\nTag: " + GIT_TAG + ", commits: " + GIT_COMMITS + "\n\nflags: (if any)\n"; #ifdef LEGACY_RENDERER result += "legacyrenderer\n"; @@ -832,8 +832,9 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { "commit_message": "{}", "commit_date": "{}", "tag": "{}", + "commits": {}, "flags": [)#", - GIT_BRANCH, GIT_COMMIT_HASH, (strcmp(GIT_DIRTY, "dirty") == 0 ? "true" : "false"), escapeJSONStrings(commitMsg), GIT_COMMIT_DATE, GIT_TAG); + GIT_BRANCH, GIT_COMMIT_HASH, (strcmp(GIT_DIRTY, "dirty") == 0 ? "true" : "false"), escapeJSONStrings(commitMsg), GIT_COMMIT_DATE, GIT_TAG, GIT_COMMITS); #ifdef LEGACY_RENDERER result += "\"legacyrenderer\","; diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 494aa640..78870666 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -364,7 +364,7 @@ APICALL SVersionInfo HyprlandAPI::getHyprlandVersion(HANDLE handle) { if (!PLUGIN) return {}; - return {GIT_COMMIT_HASH, GIT_TAG, GIT_DIRTY != std::string(""), GIT_BRANCH, GIT_COMMIT_MESSAGE}; + return {GIT_COMMIT_HASH, GIT_TAG, GIT_DIRTY != std::string(""), GIT_BRANCH, GIT_COMMIT_MESSAGE, GIT_COMMITS}; } APICALL std::shared_ptr<SHyprCtlCommand> HyprlandAPI::registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd) { diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index a7a998b4..575fef40 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -49,6 +49,7 @@ struct SVersionInfo { bool dirty = false; std::string branch; std::string message; + std::string commits; }; #define APICALL extern "C" diff --git a/src/version.h.in b/src/version.h.in index e0dd8a83..a77b2468 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -5,3 +5,4 @@ #define GIT_COMMIT_DATE "@DATE@" #define GIT_DIRTY "@DIRTY@" #define GIT_TAG "@TAG@" +#define GIT_COMMITS "@COMMITS@" |