Fix addDependency functionality

addDependency was acting weird - if a subcomponent was added as
dependency, the parent was not installed. It was installed the next time
the installer was launched and something else was added/removed.
addDependency should behave the same as when selecting the component
from UI - it should install the parents too

Task-number: QTIFW-1458
Change-Id: I21726ad6acda3b1fb382263405754c2d682dea76
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
This commit is contained in:
Katja Marttila 2019-10-18 15:03:01 +03:00
parent 730425abb0
commit 7dd35b336f
2 changed files with 27 additions and 6 deletions

View File

@ -158,6 +158,14 @@ bool InstallerCalculator::appendComponentsToInstall(const QList<Component *> &co
bool InstallerCalculator::appendComponentToInstall(Component *component, const QString &version)
{
QSet<QString> allDependencies = component->dependencies().toSet();
// All parents are kind of dependencies as well. If we select sub item in treeview, parent gets
// checked or partially checked as well. When adding component as dependency in script or
// config.xml we need to add the parent as dependency so the behavior is the same as in visual UI.
if (component->parentComponent() &&
!allDependencies.contains(component->parentComponent()->name()) &&
!m_visitedComponents.contains(component->parentComponent())) {
allDependencies.insert(component->parentComponent()->name());
}
QString requiredDependencyVersion = version;
foreach (const QString &dependencyComponentName, allDependencies) {
// PackageManagerCore::componentByName returns 0 if dependencyComponentName contains a

View File

@ -153,13 +153,17 @@ private slots:
NamedComponent *componentA = new NamedComponent(core, QLatin1String("A"));
NamedComponent *componentAA = new NamedComponent(core, QLatin1String("A.A"));
NamedComponent *componentAB = new NamedComponent(core, QLatin1String("A.B"));
NamedComponent *componentABC = new NamedComponent(core, QLatin1String("A.B.C"));
NamedComponent *componentABD = new NamedComponent(core, QLatin1String("A.B.D"));
componentA->appendComponent(componentAA);
componentA->appendComponent(componentAB);
componentAB->appendComponent(componentABC);
componentAB->appendComponent(componentABD);
NamedComponent *componentB = new NamedComponent(core, QLatin1String("B"));
NamedComponent *componentB_NewVersion = new NamedComponent(core, QLatin1String("B_version"), QLatin1String("2.0.0"));
NamedComponent *componentB_Auto = new NamedComponent(core, QLatin1String("B_auto"));
componentB->addDependency(QLatin1String("A.B"));
componentAB->addDependency(QLatin1String("B_version->=2.0.0"));
componentB->addDependency(QLatin1String("A.B.C"));
componentABC->addDependency(QLatin1String("B_version->=2.0.0"));
componentB_Auto->addAutoDependOn(QLatin1String("B_version"));
core->appendRootComponent(componentA);
core->appendRootComponent(componentB);
@ -168,8 +172,10 @@ private slots:
QTest::newRow("Installer resolved") << core
<< (QList<Component *>() << componentB)
<< (QList<Component *>() << componentB_NewVersion << componentAB << componentB << componentB_Auto)
<< (QList<Component *>() << componentA << componentAB << componentABC << componentB_NewVersion << componentB << componentB_Auto)
<< (QList<int>()
<< InstallerCalculator::Dependent
<< InstallerCalculator::Dependent
<< InstallerCalculator::Dependent
<< InstallerCalculator::Dependent
<< InstallerCalculator::Resolved
@ -186,12 +192,19 @@ private slots:
InstallerCalculator calc(core->components(PackageManagerCore::ComponentType::AllNoReplacements));
calc.appendComponentsToInstall(selectedComponents);
QList<Component *> result = calc.orderedComponentsToInstall();
int results = 0;
QCOMPARE(result.count(), expectedResult.count());
for (int i = 0; i < result.count(); i++) {
QCOMPARE(result.at(i), expectedResult.at(i));
QCOMPARE((int)calc.installReasonType(result.at(i)), installReason.at(i));
if (result.contains(expectedResult.at(i))) {
int index = result.indexOf(expectedResult.at(i));
QCOMPARE(result.at(index), expectedResult.at(i));
QCOMPARE((int)calc.installReasonType(result.at(index)), installReason.at(i));
results++;
}
}
// Check that we have found all expected results. Install order may vary
// for dependent components so we cannot do a direct compare
QCOMPARE(result.count(), results);
delete core;
}