feat(update): install missing build dependencies before rebuilding
A minimal Arch system has no cmake, no compiler and no qt6-base, so the self-update used to fail or fall back to the releases page. The update now asks pacman what is missing, installs it through sudo with the password typed in the update dialog, then resumes the build. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
4 files changed
+212
-13
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QProcess>
|
||||
|
||||
// Checks the Gitea repository for new releases and tracks the last check
|
||||
@@ -19,6 +20,10 @@
|
||||
// into ~/.local/share/PacManager/src, built, and installed in place;
|
||||
// - Prebuilt: the release's prebuilt archive is unpacked (no compiler);
|
||||
// - Tarball: the release sources are built and installed in place.
|
||||
// The three rebuilding methods (Checkout, Clone, Tarball) first make sure the
|
||||
// build dependencies (base-devel, cmake, git, qt6-base) are installed: the
|
||||
// update script asks pacman what is missing and installs it through sudo, so
|
||||
// a minimal Arch system only needs its sudo password to self-update.
|
||||
// The running binary stays untouched (it keeps the inode that was replaced on
|
||||
// disk); the UI hands over to the freshly installed build by relaunching it.
|
||||
class UpdateManager : public QObject {
|
||||
@@ -95,6 +100,16 @@ public:
|
||||
enum class UpdateMethod { None, Checkout, Clone, Prebuilt, Tarball };
|
||||
UpdateMethod updateMethod() const;
|
||||
|
||||
// Packages needed to rebuild the app. base-devel pulls gcc, make and the
|
||||
// rest of the toolchain, git feeds the Clone method, and qt6-base provides
|
||||
// the Widgets + Network modules the build links against.
|
||||
static QStringList buildDependencies();
|
||||
|
||||
// Subset of buildDependencies() that pacman reports as missing (`pacman -T`,
|
||||
// exit code 127), cached for the process lifetime. Empty when everything is
|
||||
// installed, when pacman is absent (non-Arch system) or on Windows.
|
||||
static QStringList missingBuildDependencies();
|
||||
|
||||
// Inputs of the strategy decision, split out so the choice is a pure
|
||||
// function that can be unit-tested without a network, a filesystem or an
|
||||
// installed toolchain.
|
||||
@@ -105,6 +120,9 @@ public:
|
||||
bool hasCompiler = false;
|
||||
bool hasPrebuilt = false; // the release ships a prebuilt binary archive
|
||||
bool hasTarball = false; // the release ships a source tarball
|
||||
// pacman is available, so whatever build tool is missing can be
|
||||
// installed (with the user's sudo password) before rebuilding.
|
||||
bool canInstallPackages = false;
|
||||
};
|
||||
static UpdateMethod chooseUpdateMethod(const UpdateCapabilities& capabilities);
|
||||
|
||||
@@ -122,6 +140,14 @@ public:
|
||||
// binary.
|
||||
static QString stagedInstallScript();
|
||||
|
||||
// Shell snippet run at the start of every rebuilding method: installs the
|
||||
// build dependencies pacman reports as missing (`pacman -T`) through sudo,
|
||||
// piping the given (already shell-quoted) password to `sudo -S`. Without a
|
||||
// password, `sudo -n` keeps a passwordless-sudo setup working while a
|
||||
// password-requiring one fails fast instead of hanging the background run.
|
||||
// Exposed so the unit test can assert what the update would install.
|
||||
static QString dependencyInstallScript(const QString& quotedPassword);
|
||||
|
||||
// Whether a self-update is possible with the current state.
|
||||
bool canSelfUpdate() const;
|
||||
|
||||
|
||||
Reference in new issue
Block a user