From 7dd35b336fbaa78e5f3b347c5e1875743d146fb0 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Fri, 18 Oct 2019 15:03:01 +0300 Subject: 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 --- src/libs/installer/installercalculator.cpp | 8 ++++++++ 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 &co bool InstallerCalculator::appendComponentToInstall(Component *component, const QString &version) { QSet 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,8 +172,10 @@ private slots: QTest::newRow("Installer resolved") << core << (QList() << componentB) - << (QList() << componentB_NewVersion << componentAB << componentB << componentB_Auto) + << (QList() << componentA << componentAB << componentABC << componentB_NewVersion << componentB << componentB_Auto) << (QList() + << 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 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; } -- cgit v1.2.3