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:
BlackAngelTV committed 2026-09-23 21:58:21 +02:00
1 parent 5b24cea9c8
commit b204d6814a
4 files changed
+212 -13

No files matched your search

+78
View File
@@ -119,6 +119,79 @@ static void testChooseMethod_noneWhenNothingAvailable() {
"method_none_without_anything");
}
// pacman can install whatever build tool is missing, so a minimal Arch system
// (no cmake, no compiler, not even git) still reaches the rebuilding methods:
// the update script installs the dependencies first, with the sudo password the
// user typed in the update dialog.
static void testChooseMethod_pacmanUnlocksClone() {
Caps caps;
caps.canInstallPackages = true; // nothing else installed
caps.hasGit = true; // git is the only tool the clone path
// strictly needs up front (deps install
// brings cmake + the compiler)
check(UpdateManager::chooseUpdateMethod(caps) == Method::Clone,
"method_clone_with_pacman_only");
}
static void testChooseMethod_pacmanWithoutGit_stillTarball() {
Caps caps;
caps.canInstallPackages = true;
caps.hasTarball = true; // no git: the tarball path also needs no tool now
check(UpdateManager::chooseUpdateMethod(caps) == Method::Tarball,
"method_tarball_with_pacman_only");
}
// Without pacman there is no way to fill a missing toolchain: the prebuilt
// archive (when the release ships one) stays the only option.
static void testChooseMethod_noPacman_prebuiltStillFallback() {
Caps caps;
caps.hasGit = true; // git alone cannot build, and pacman cannot fix it
caps.hasPrebuilt = true;
check(UpdateManager::chooseUpdateMethod(caps) == Method::Prebuilt,
"method_prebuilt_without_pacman");
}
// The dependency list and its `pacman -T` probe are pure data/IO: the list is
// asserted literally so a rename cannot silently break the install script, and
// the missing-dependency lookup must agree with pacman itself (empty on this
// machine means "nothing to install", not "unknown").
static void testBuildDependencies() {
const QStringList deps = UpdateManager::buildDependencies();
check(deps.contains("base-devel"), "deps_base_devel");
check(deps.contains("cmake"), "deps_cmake");
check(deps.contains("gcc"), "deps_gcc");
check(deps.contains("qt6-base"), "deps_qt6_base");
check(deps.contains("git"), "deps_git");
// On a machine without pacman this is empty and the update simply keeps
// its current behaviour; with pacman it must never report an installed
// package as missing.
const QStringList missing = UpdateManager::missingBuildDependencies();
for (const QString& pkg : missing) {
check(deps.contains(pkg), "missing_dependency_is_from_the_list");
}
}
// The generated snippet must install exactly what pacman -T reports, through
// sudo (with the password piped to -S), and skip everything on a complete
// system. Quoted here is the password safety: the quoting is the same as the
// one used for the install step.
static void testDependencyInstallScript() {
const QString script = UpdateManager::dependencyInstallScript("'secret'");
check(script.contains("pacman -T"), "script_asks_pacman_what_is_missing");
check(script.contains("base-devel"), "script_installs_base_devel");
check(script.contains("qt6-base"), "script_installs_qt6_base");
check(script.contains("--needed --noconfirm"), "script_pacman_flags");
check(script.contains("| sudo -S"), "script_pipes_password_to_sudo");
check(script.contains("'secret'"), "script_uses_the_given_password");
// No password: sudo -n fails fast on a password-requiring setup instead of
// hanging the background update on an unanswerable prompt.
const QString passwordless = UpdateManager::dependencyInstallScript(QString());
check(passwordless.contains("sudo -n"), "script_passwordless_uses_sudo_n");
check(!passwordless.contains("sudo -S"), "script_passwordless_has_no_pipe");
}
// Reconciliation of the two sources of truth: whichever is ahead wins, an empty
// side never does. This is what stops a release from being offered again when the
// binary and the installed marker disagree.
@@ -327,6 +400,11 @@ int main() {
testChooseMethod_tarballWithoutGit();
testChooseMethod_tarballRequiresCompiler();
testChooseMethod_noneWhenNothingAvailable();
testChooseMethod_pacmanUnlocksClone();
testChooseMethod_pacmanWithoutGit_stillTarball();
testChooseMethod_noPacman_prebuiltStillFallback();
testBuildDependencies();
testDependencyInstallScript();
#if !defined(Q_OS_WIN)
testStagedInstall_replacesRunningExecutable();