diff options
author | Katja Marttila <katja.marttila@qt.io> | 2019-10-18 15:03:01 +0300 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2019-10-21 11:05:56 +0000 |
commit | 7dd35b336fbaa78e5f3b347c5e1875743d146fb0 (patch) | |
tree | 7dcc3afbcbaeb6f49ea8d3028198a2afd13970a6 | |
parent | 730425abb092592e4b74e2d38f5e8a0b998966f9 (diff) |
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>
-rw-r--r-- | src/libs/installer/installercalculator.cpp | 8 | ||||
-rw-r--r-- | tests/auto/installer/solver/tst_solver.cpp | 25 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index db1f88563..a35cb99fb 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -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 diff --git a/tests/auto/installer/solver/tst_solver.cpp b/tests/auto/installer/solver/tst_solver.cpp index d1c3aaa14..139aa7581 100644 --- a/tests/auto/installer/solver/tst_solver.cpp +++ b/tests/auto/installer/solver/tst_solver.cpp @@ -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,10 +172,12 @@ 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 << InstallerCalculator::Automatic); } @@ -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; } |