hyprland/opensuse-hyprpm-use-hyprland-devel-subpkg.patch

230 lines
9.4 KiB
Diff
Raw Permalink Normal View History

From e8c470eb87494ad48f038323e0b2f36d606f1712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20sp1rit=E2=80=8B?= <sp1rit@disroot.org>
Date: Fri, 14 Jun 2024 23:43:46 +0200
Subject: [PATCH] openSUSE: Use hyprland-devel instead of downloading from
upstream
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The plugin manager needs headers in order to build plugins for hyprland.
This patch removes the ability of hyprpm to download another copy of
hyprland upstream and instead forces hyprpm to use the headers already
installed from the hyprland-devel subpackage.
It also adds a new check to ensure that the subpackage is instealled.
Signed-off-by: Florian "sp1rit" <sp1rit@disroot.org>
---
hyprpm/src/core/DataState.cpp | 5 +-
hyprpm/src/core/PluginManager.cpp | 140 ++++--------------------------
2 files changed, 20 insertions(+), 125 deletions(-)
diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp
index 55f148a..2c8f66f 100644
--- a/hyprpm/src/core/DataState.cpp
+++ b/hyprpm/src/core/DataState.cpp
@@ -20,7 +20,7 @@ std::filesystem::path DataState::getDataStatePath() {
}
std::string DataState::getHeadersPath() {
- return getDataStatePath() / "headersRoot";
+ return "REPLACE_ME_WITH_PREFIX/";
}
std::vector<std::filesystem::path> DataState::getPluginStates() {
@@ -45,9 +45,6 @@ void DataState::ensureStateStoreExists() {
if (!std::filesystem::exists(PATH))
std::filesystem::create_directories(PATH);
-
- if (!std::filesystem::exists(getHeadersPath()))
- std::filesystem::create_directories(getHeadersPath());
}
void DataState::addNewPluginRepo(const SPluginRepository& repo) {
diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp
index 3343cbe..b619a85 100644
--- a/hyprpm/src/core/PluginManager.cpp
+++ b/hyprpm/src/core/PluginManager.cpp
@@ -15,6 +15,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <pwd.h>
#include <unistd.h>
@@ -435,143 +436,27 @@ bool CPluginManager::updateHeaders(bool force) {
const auto HLVER = getHyprlandVersion(false);
if (!hasDeps()) {
- std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio, pkg-config"));
+ std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: hyprland-devel, cmake, meson, cpio, pkg-config"));
return false;
}
- if (!std::filesystem::exists(getTempRoot())) {
- std::filesystem::create_directory(getTempRoot());
- std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace);
- }
-
- if (!force && headersValid() == HEADERS_OK) {
- std::println("\n{}", successString("Headers up to date."));
- return true;
- }
-
CProgressBar progress;
- progress.m_iMaxSteps = 5;
+ progress.m_iMaxSteps = 1;
progress.m_iSteps = 0;
- progress.m_szCurrentMessage = "Cloning the hyprland repository";
+ progress.m_szCurrentMessage = "Checking headers";
progress.print();
- const std::string USERNAME = getpwuid(getuid())->pw_name;
- const auto WORKINGDIR = getTempRoot() + "hyprland-" + USERNAME;
-
- if (!createSafeDirectory(WORKINGDIR)) {
- std::println("\n{}", failureString("Could not prepare working dir for hl"));
- return false;
- }
-
- const auto& HL_URL = m_szCustomHlUrl.empty() ? "https://github.com/hyprwm/Hyprland" : m_szCustomHlUrl;
-
- progress.printMessageAbove(statusString("!", Colors::YELLOW, "Cloning {}, this might take a moment.", HL_URL));
-
- const bool bShallow = (HLVER.branch == "main") && !m_bNoShallow;
-
- // let us give a bit of leg-room for shallowing
- // due to timezones, etc.
- const std::string SHALLOW_DATE = trim(HLVER.date).empty() ? "" : execAndGet("LC_TIME=\"en_US.UTF-8\" date --date='" + HLVER.date + " - 1 weeks' '+%a %b %d %H:%M:%S %Y'");
-
- if (m_bVerbose && bShallow)
- progress.printMessageAbove(verboseString("will shallow since: {}", SHALLOW_DATE));
-
- std::string ret =
- execAndGet(std::format("cd {} && git clone --recursive {} hyprland-{}{}", getTempRoot(), HL_URL, USERNAME, (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : "")));
-
- if (!std::filesystem::exists(WORKINGDIR)) {
- progress.printMessageAbove(failureString("Clone failed. Retrying without shallow."));
- ret = execAndGet(std::format("cd {} && git clone --recursive {} hyprland-{}", getTempRoot(), HL_URL, USERNAME));
- }
-
- if (!std::filesystem::exists(WORKINGDIR + "/.git")) {
- std::println(stderr, "\n{}", failureString("Could not clone the Hyprland repository. shell returned:\n{}", ret));
- return false;
- }
-
- progress.printMessageAbove(successString("Hyprland cloned"));
- progress.m_iSteps = 2;
- progress.m_szCurrentMessage = "Checking out sources";
- progress.print();
-
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("will run: cd {} && git checkout {} 2>&1", WORKINGDIR, HLVER.hash));
-
- ret = execAndGet("cd " + WORKINGDIR + " && git checkout " + HLVER.hash + " 2>&1");
-
- if (ret.contains("fatal: unable to read tree")) {
- std::println(stderr, "\n{}",
- failureString("Could not checkout the running Hyprland commit. If you are on -git, try updating.\n"
- "You can also try re-running hyprpm update with --no-shallow."));
- return false;
- }
-
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("git returned (co): {}", ret));
-
- ret = execAndGet("cd " + WORKINGDIR + " ; git rm subprojects/tracy ; git submodule update --init 2>&1 ; git reset --hard --recurse-submodules " + HLVER.hash);
-
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("git returned (rs): {}", ret));
-
- progress.printMessageAbove(successString("checked out to running ver"));
- progress.m_iSteps = 3;
- progress.m_szCurrentMessage = "Building Hyprland";
- progress.print();
-
- progress.printMessageAbove(statusString("!", Colors::YELLOW, "configuring Hyprland"));
-
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("setting PREFIX for cmake to {}", DataState::getHeadersPath()));
-
- ret = execAndGet(std::format("cd {} && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING=\"{}\" -S . -B ./build -G Ninja", WORKINGDIR,
- DataState::getHeadersPath()));
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("cmake returned: {}", ret));
-
- if (ret.contains("CMake Error at")) {
- // missing deps, let the user know.
- std::string missing = ret.substr(ret.find("CMake Error at"));
- missing = ret.substr(ret.find_first_of('\n') + 1);
- missing = missing.substr(0, missing.find("-- Configuring incomplete"));
- missing = missing.substr(0, missing.find_last_of('\n'));
-
- std::println(stderr, "\n{}",
- failureString("Could not configure the hyprland source, cmake complained:\n{}\n\n"
- "This likely means that you are missing the above dependencies or they are out of date.",
- missing));
- return false;
- }
-
- progress.printMessageAbove(successString("configured Hyprland"));
- progress.m_iSteps = 4;
- progress.m_szCurrentMessage = "Installing sources";
- progress.print();
-
- const std::string& cmd =
- std::format("sed -i -e \"s#PREFIX = /usr/local#PREFIX = {}#\" {}/Makefile && cd {} && make installheaders", DataState::getHeadersPath(), WORKINGDIR, WORKINGDIR);
- if (m_bVerbose)
- progress.printMessageAbove(verboseString("installation will run: {}", cmd));
-
- ret = execAndGet(cmd);
-
- if (m_bVerbose)
- std::println("{}", verboseString("installer returned: {}", ret));
-
- // remove build files
- std::filesystem::remove_all(WORKINGDIR);
-
auto HEADERSVALID = headersValid();
if (HEADERSVALID == HEADERS_OK) {
progress.printMessageAbove(successString("installed headers"));
- progress.m_iSteps = 5;
+ progress.m_iSteps = 1;
progress.m_szCurrentMessage = "Done!";
progress.print();
std::print("\n");
} else {
progress.printMessageAbove(failureString("failed to install headers with error code {} ({})", (int)HEADERSVALID, headerErrorShort(HEADERSVALID)));
- progress.m_iSteps = 5;
+ progress.m_iSteps = 1;
progress.m_szCurrentMessage = "Failed";
progress.print();
@@ -947,6 +832,19 @@ std::string CPluginManager::headerErrorShort(const eHeadersErrors err) {
}
bool CPluginManager::hasDeps() {
+ pid_t pid = fork();
+ if (pid == 0) {
+ close(STDOUT_FILENO);
+ execlp("rpm", "rpm", "-q", "hyprland-devel", NULL);
+ exit(1);
+ }
+ int status;
+ pid = waitpid(pid, &status, 0);
+ if (pid < 0)
+ return false;
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ return false;
+
std::vector<std::string> deps = {"meson", "cpio", "cmake", "pkg-config"};
for (auto const& d : deps) {
if (!execAndGet("command -v " + d).contains("/"))
--
2.47.0