FIXME, TODO: decouple dependency resolution from loading FIXME: This works directly with the PackProfile internals. It shouldn't! It needs richer data types than PackProfile uses. FIXME: throw all this away and use a graph
| 424 | // FIXME: This works directly with the PackProfile internals. It shouldn't! It needs richer data types than PackProfile uses. |
| 425 | // FIXME: throw all this away and use a graph |
| 426 | void ComponentUpdateTask::resolveDependencies(bool checkOnly) |
| 427 | { |
| 428 | qCDebug(instanceProfileResolveC) << "Resolving dependencies"; |
| 429 | /* |
| 430 | * this is a naive dependency resolving algorithm. all it does is check for following conditions and react in simple ways: |
| 431 | * 1. There are conflicting dependencies on the same uid with different exact version numbers |
| 432 | * -> hard error |
| 433 | * 2. A dependency has non-matching exact version number |
| 434 | * -> hard error |
| 435 | * 3. A dependency is entirely missing and needs to be injected before the dependee(s) |
| 436 | * -> requirements are injected |
| 437 | * |
| 438 | * NOTE: this is a placeholder and should eventually be replaced with something 'serious' |
| 439 | */ |
| 440 | auto& components = d->m_profile->d->components; |
| 441 | auto& componentIndex = d->m_profile->d->componentIndex; |
| 442 | |
| 443 | RequireExSet allRequires; |
| 444 | QStringList toRemove; |
| 445 | do { |
| 446 | allRequires.clear(); |
| 447 | toRemove.clear(); |
| 448 | if (!gatherRequirementsFromComponents(components, allRequires)) { |
| 449 | finalizeComponents(); |
| 450 | emitFailed(tr("Conflicting requirements detected during dependency checking!")); |
| 451 | return; |
| 452 | } |
| 453 | getTrivialRemovals(components, allRequires, toRemove); |
| 454 | if (!toRemove.isEmpty()) { |
| 455 | qCDebug(instanceProfileResolveC) << "Removing obsolete components..."; |
| 456 | for (auto& remove : toRemove) { |
| 457 | qCDebug(instanceProfileResolveC) << "Removing" << remove; |
| 458 | d->m_profile->remove(remove); |
| 459 | } |
| 460 | } |
| 461 | } while (!toRemove.isEmpty()); |
| 462 | RequireExSet toAdd; |
| 463 | RequireExSet toChange; |
| 464 | bool succeeded = getTrivialComponentChanges(componentIndex, allRequires, toAdd, toChange); |
| 465 | if (!succeeded) { |
| 466 | finalizeComponents(); |
| 467 | emitFailed(tr("Instance has conflicting dependencies.")); |
| 468 | return; |
| 469 | } |
| 470 | if (checkOnly) { |
| 471 | finalizeComponents(); |
| 472 | if (toAdd.size() || toChange.size()) { |
| 473 | emitFailed(tr("Instance has unresolved dependencies while loading/checking for launch.")); |
| 474 | } else { |
| 475 | emitSucceeded(); |
| 476 | } |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | bool recursionNeeded = false; |
| 481 | if (toAdd.size()) { |
| 482 | // add stuff... |
| 483 | for (auto& add : toAdd) { |
nothing calls this directly
no test coverage detected