summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2024-05-07 18:02:02 +0300
committerKatja Marttila <katja.marttila@qt.io>2024-05-10 13:53:35 +0300
commit0633bf6ab32facd4e5b34de3311ff77baf20a662 (patch)
tree850cbfaa9a65c2359feb5db88aaf0290651d793c
parent61fa5adf0eef1207ea2d14f8a639ab006fa6d3cd (diff)
CLI: Fix fetching components in alias from fallback repositories4.8.0
Alias components can refer to a individual components which can exist in fallback repository. If alias is marked as unstable, try fetching the fallback repositories, if those are not fetched already. Also resolve only the alias packages that are selected for install. There is no point in resolving aliases which we are not interested in, and it also provided unnecessary warning messages if the components belonging to certain aliases exists in fallback repositories. Fixed also bug where alias with optional broken dependency was not installed. Change-Id: I69a197e652ba83300551e054b41e5932311dfd61 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r--src/libs/installer/componentalias.cpp2
-rw-r--r--src/libs/installer/packagemanagercore.cpp4
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp54
-rw-r--r--src/libs/installer/packagemanagercore_p.h1
-rw-r--r--tests/auto/installer/componentalias/tst_componentalias.cpp6
5 files changed, 56 insertions, 11 deletions
diff --git a/src/libs/installer/componentalias.cpp b/src/libs/installer/componentalias.cpp
index 955d715fd..7bb745341 100644
--- a/src/libs/installer/componentalias.cpp
+++ b/src/libs/installer/componentalias.cpp
@@ -599,6 +599,8 @@ void ComponentAlias::addRequiredAliases(const QStringList &aliases, const bool o
}
if (alias->isUnstable()) {
+ if (optional)
+ continue;
const QString error = QLatin1String("Alias requires another alias "
"that is marked unstable: ") + aliasName;
qCWarning(lcInstallerInstallLog) << error;
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 5c6f481f9..cfcd8ecb7 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -1754,6 +1754,7 @@ bool PackageManagerCore::fetchRemotePackagesTree(const QStringList& components)
if (!d->installablePackagesFound(components))
return false;
+ d->m_componentsToBeInstalled = components;
return fetchPackagesTree(packages, installedPackages);
}
@@ -2849,7 +2850,8 @@ bool PackageManagerCore::checkComponentsForInstallation(const QStringList &names
errorMessage.append(tr("Cannot select alias %1. There was a problem loading this alias, "
"so it is marked unstable and cannot be selected.").arg(name) + QLatin1Char('\n'));
unstableAliasFound = true;
- continue;
+ setCanceled();
+ return false;
} else if (alias->isVirtual()) {
errorMessage.append(tr("Cannot select %1. Alias is marked virtual, meaning it cannot "
"be selected manually.").arg(name) + QLatin1Char('\n'));
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 8f78cb23d..3e8eca029 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -498,8 +498,39 @@ bool PackageManagerCorePrivate::buildComponentAliases()
// 1. Component check state is changed by alias selection, so store the initial state
storeCheckState();
+ QStringList aliasNamesSelectedForInstall;
+ if (m_core->isPackageViewer()) {
+ aliasNamesSelectedForInstall.append(m_componentAliases.keys());
+ } else {
+ // 2. Get a list of alias names to be installed, dependency aliases needs to be listed first
+ // to get proper unstable state for parents
+ std::function<void(QStringList)> fetchAliases = [&](QStringList aliases) {
+ for (const QString &aliasName : aliases) {
+ ComponentAlias *alias = m_componentAliases.value(aliasName);
+ if (!alias || aliasNamesSelectedForInstall.contains(aliasName))
+ continue;
+ if (!aliasNamesSelectedForInstall.contains(aliasName))
+ aliasNamesSelectedForInstall.prepend(aliasName);
+ fetchAliases(QStringList() << QInstaller::splitStringWithComma(alias->value(scRequiredAliases))
+ << QInstaller::splitStringWithComma(alias->value(scOptionalAliases)));
+ }
+ };
+ for (const QString &installComponent : m_componentsToBeInstalled) {
+ ComponentAlias *alias = m_componentAliases.value(installComponent);
+ if (!alias)
+ continue;
+ if (!aliasNamesSelectedForInstall.contains(installComponent))
+ aliasNamesSelectedForInstall.prepend(installComponent);
+ fetchAliases(QStringList() << QInstaller::splitStringWithComma(alias->value(scRequiredAliases))
+ << QInstaller::splitStringWithComma(alias->value(scOptionalAliases)));
+ }
+ }
Graph<QString> aliasGraph;
- for (auto *alias : qAsConst(m_componentAliases)) {
+ QList<ComponentAlias *> aliasesSelectedForInstall;
+ for (auto &aliasName : std::as_const(aliasNamesSelectedForInstall)) {
+ ComponentAlias *alias = m_componentAliases.value(aliasName);
+ if (!alias)
+ continue;
aliasGraph.addNode(alias->name());
aliasGraph.addEdges(alias->name(),
QInstaller::splitStringWithComma(alias->value(scRequiredAliases)) <<
@@ -513,10 +544,12 @@ bool PackageManagerCorePrivate::buildComponentAliases()
tr("Alias declares name that conflicts with an existing component \"%1\"")
.arg(alias->name()));
}
+ if (!aliasesSelectedForInstall.contains(alias))
+ aliasesSelectedForInstall.append(alias);
}
const QList<QString> sortedAliases = aliasGraph.sort();
- // 2. Check for cyclic dependency errors
+ // 3. Check for cyclic dependency errors
if (aliasGraph.hasCycle()) {
setStatus(PackageManagerCore::Failure, installerCalculator()->error());
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), QLatin1String("Error"),
@@ -527,7 +560,7 @@ bool PackageManagerCorePrivate::buildComponentAliases()
return false;
}
- // 3. Test for required aliases and components, this triggers setting the
+ // 4. Test for required aliases and components, this triggers setting the
// alias unstable in case of a broken reference.
for (const auto &aliasName : sortedAliases) {
ComponentAlias *alias = m_componentAliases.value(aliasName);
@@ -539,8 +572,8 @@ bool PackageManagerCorePrivate::buildComponentAliases()
}
clearInstallerCalculator();
- // 4. Check for other errors preventing resolving components to install
- if (!installerCalculator()->solve(m_componentAliases.values())) {
+ // 5. Check for other errors preventing resolving components to install
+ if (!installerCalculator()->solve(aliasesSelectedForInstall)) {
setStatus(PackageManagerCore::Failure, installerCalculator()->error());
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), QLatin1String("Error"),
tr("Unresolved component aliases"), installerCalculator()->error());
@@ -548,10 +581,10 @@ bool PackageManagerCorePrivate::buildComponentAliases()
return false;
}
- for (auto *alias : qAsConst(m_componentAliases))
+ for (auto *alias : std::as_const(m_componentAliases))
alias->setSelected(false);
- // 5. Restore original state
+ // 6. Restore original state
restoreCheckState();
return true;
@@ -2674,6 +2707,7 @@ PackageManagerCore::Status PackageManagerCorePrivate::fetchComponentsAndInstall(
// We found unstable alias and all repos were not fetched. Alias might have dependency to component
// which exists in non-default repository. Fetch all repositories now.
if (unstableAliasFound && !fallbackReposFetched) {
+ qCDebug(QInstaller::lcInstallerInstallLog).noquote().nospace() << errorMessage;
return false;
}
else {
@@ -2686,6 +2720,12 @@ PackageManagerCore::Status PackageManagerCorePrivate::fetchComponentsAndInstall(
if (!fetchComponents() && !fallbackReposFetched) {
setStatus(PackageManagerCore::Running);
+ qCDebug(QInstaller::lcInstallerInstallLog).noquote()
+ << "Components not found with the current selection."
+ << "Searching from additional repositories";
+ if (!ProductKeyCheck::instance()->securityWarning().isEmpty()) {
+ qCWarning(QInstaller::lcInstallerInstallLog) << ProductKeyCheck::instance()->securityWarning();
+ }
enableAllCategories();
fetchComponents();
}
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index c0c55c4cc..9c5baeb18 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -342,6 +342,7 @@ private:
QString m_datFileName;
bool m_allowCompressedRepositoryInstall;
int m_connectedOperations;
+ QStringList m_componentsToBeInstalled;
};
} // namespace QInstaller
diff --git a/tests/auto/installer/componentalias/tst_componentalias.cpp b/tests/auto/installer/componentalias/tst_componentalias.cpp
index f6742af1f..d8ee48760 100644
--- a/tests/auto/installer/componentalias/tst_componentalias.cpp
+++ b/tests/auto/installer/componentalias/tst_componentalias.cpp
@@ -201,10 +201,10 @@ private slots:
<< PackageManagerCore::Success
<< (QStringList() << "A" << "B");
- QTest::newRow("Alias with optional broken alias (will not install)")
+ QTest::newRow("Alias with optional broken alias (will install)")
<< AliasSource(AliasSource::SourceFileFormat::Xml, ":///data/aliases-optional.xml", -1)
<< (QStringList() << "set-optional-broken")
- << PackageManagerCore::Canceled
+ << PackageManagerCore::Success
<< QStringList();
}
@@ -257,7 +257,7 @@ private slots:
core->setCommandLineInstance(true);
- QCOMPARE(status, core->installSelectedComponentsSilently(selectedAliases));
+ QCOMPARE(core->installSelectedComponentsSilently(selectedAliases), status);
}
private: