2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
21 #include "solver_private.h"
27 #include "solverdebug.h"
29 #include "linkedpkg.h"
31 #define RULES_BLOCK 63
34 /********************************************************************
36 * dependency check helpers
40 /*-------------------------------------------------------------------
41 * handle split provides
43 * a splitprovides dep looks like
44 * namespace:splitprovides(pkg REL_WITH path)
45 * and is only true if pkg is installed and contains the specified path.
46 * we also make sure that pkg is selected for an update, otherwise the
47 * update would always be forced onto the user.
48 * Map m is the map used when called from dep_possible.
52 solver_is_updating(Solver *solv, Id p)
54 /* check if the update rule is true */
55 Pool *pool = solv->pool;
58 if (solv->decisionmap[p] >= 0)
59 return 0; /* old package stayed */
60 r = solv->rules + solv->updaterules + (p - solv->installed->start);
61 FOR_RULELITERALS(l, pp, r)
62 if (l > 0 && l != p && solv->decisionmap[l] > 0)
68 solver_splitprovides(Solver *solv, Id dep, Map *m)
70 Pool *pool = solv->pool;
75 if (!solv->dosplitprovides || !solv->installed)
79 rd = GETRELDEP(pool, dep);
80 if (rd->flags != REL_WITH)
83 * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
84 * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
85 * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
86 * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
87 * we filter the package name further down anyway).
89 if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
90 pp = pool_searchlazywhatprovidesq(pool, rd->evr);
92 pp = pool_whatprovides(pool, dep);
93 while ((p = pool->whatprovidesdata[pp++]) != 0)
95 /* here we have packages that provide the correct name and contain the path,
96 * now do extra filtering */
97 s = pool->solvables + p;
98 if (s->repo != solv->installed || s->name != rd->name)
100 /* check if the package is updated. if m is set, we're called from dep_possible */
101 if (m || solver_is_updating(solv, p))
108 /* mirrors solver_dep_fulfilled, but returns 2 if a new package
111 solver_dep_fulfilled_alreadyinstalled(Solver *solv, Id dep)
113 Pool *pool = solv->pool;
119 Reldep *rd = GETRELDEP(pool, dep);
120 if (rd->flags == REL_COND)
123 if (ISRELDEP(rd->evr))
125 Reldep *rd2 = GETRELDEP(pool, rd->evr);
126 if (rd2->flags == REL_ELSE)
128 r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd2->name);
131 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
132 return r2 && r1 == 2 ? 2 : r2;
134 return solver_dep_fulfilled_alreadyinstalled(solv, rd2->evr);
137 r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
138 r2 = !solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
141 return r1 == 2 ? 2 : 1;
143 if (rd->flags == REL_AND)
145 int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
148 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
151 return r1 == 2 || r2 == 2 ? 2 : 1;
153 if (rd->flags == REL_OR)
155 int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
156 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
159 return r1 == 2 || r2 == 2 ? 2 : 1;
161 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
162 return solver_splitprovides(solv, rd->evr, 0);
163 if (rd->flags == REL_NAMESPACE && solv->installsuppdepq)
165 Queue *q = solv->installsuppdepq;
167 for (i = 0; i < q->count; i++)
168 if (q->elements[i] == dep || q->elements[i] == rd->name)
173 FOR_PROVIDES(p, pp, dep)
174 if (solv->decisionmap[p] > 0)
176 Solvable *s = pool->solvables + p;
177 if (s->repo && s->repo != solv->installed)
185 solver_is_supplementing_alreadyinstalled(Solver *solv, Solvable *s)
188 supp = s->repo->idarraydata + s->supplements;
189 while ((sup = *supp++) != 0)
190 if (solver_dep_fulfilled_alreadyinstalled(solv, sup) == 2)
196 autouninstall(Solver *solv, Id *problem)
198 Pool *pool = solv->pool;
200 int lastfeature = 0, lastupdate = 0;
205 if (!solv->allowuninstall && !solv->allowuninstall_all)
207 if (!solv->allowuninstallmap.size)
208 return 0; /* why did we get called? */
209 m = &solv->allowuninstallmap;
211 for (i = 0; (v = problem[i]) != 0; i++)
214 extraflags &= solv->job.elements[-v - 1];
215 if (v >= solv->updaterules && v < solv->updaterules_end)
218 if (m && !MAPTST(m, v - solv->updaterules))
220 /* check if identical to feature rule, we don't like that */
221 r = solv->rules + solv->featurerules + (v - solv->updaterules);
224 /* update rule == feature rule */
233 if (!lastupdate && !lastfeature)
235 v = lastupdate ? lastupdate : lastfeature;
236 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
237 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
238 solver_disableproblem(solv, v);
239 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
241 /* add the package to the updatepkgs list, this will automatically turn
242 * on cleandeps mode */
243 Id p = solv->rules[v].p;
244 if (!solv->cleandeps_updatepkgs)
246 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
247 queue_init(solv->cleandeps_updatepkgs);
251 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
252 queue_pushunique(solv->cleandeps_updatepkgs, p);
253 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
254 solver_disablepolicyrules(solv);
260 /************************************************************************/
263 * enable/disable learnt rules
265 * we have enabled or disabled some of our rules. We now reenable all
266 * of our learnt rules except the ones that were learnt from rules that
270 enabledisablelearntrules(Solver *solv)
272 Pool *pool = solv->pool;
277 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
278 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
280 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
281 while ((why = *whyp++) != 0)
283 assert(why > 0 && why < i);
284 if (solv->rules[why].d < 0)
287 /* why != 0: we found a disabled rule, disable the learnt rule */
288 if (why && r->d >= 0)
290 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
292 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
293 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
295 solver_disablerule(solv, r);
297 else if (!why && r->d < 0)
299 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
301 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
302 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
304 solver_enablerule(solv, r);
311 * make assertion rules into decisions
313 * Go through rules and add direct assertions to the decisionqueue.
314 * If we find a conflict, disable rules and add them to problem queue.
318 makeruledecisions(Solver *solv)
320 Pool *pool = solv->pool;
325 int record_proof = 1;
327 int havedisabled = 0;
329 /* The system solvable is always installed first */
330 assert(solv->decisionq.count == 0);
331 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
332 queue_push(&solv->decisionq_why, 0);
333 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
335 decisionstart = solv->decisionq.count;
338 /* if we needed to re-run, back up decisions to decisionstart */
339 while (solv->decisionq.count > decisionstart)
341 v = solv->decisionq.elements[--solv->decisionq.count];
342 --solv->decisionq_why.count;
344 solv->decisionmap[vv] = 0;
347 /* note that the ruleassertions queue is ordered */
348 for (ii = 0; ii < solv->ruleassertions.count; ii++)
350 ri = solv->ruleassertions.elements[ii];
351 r = solv->rules + ri;
353 if (havedisabled && ri >= solv->learntrules)
355 /* just started with learnt rule assertions. If we have disabled
356 * some rules, adapt the learnt rule status */
357 enabledisablelearntrules(solv);
361 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
364 /* do weak rules in phase 2 */
365 if (ri < solv->learntrules && solv->weakrulemap.size && MAPTST(&solv->weakrulemap, ri))
371 if (!solv->decisionmap[vv]) /* if not yet decided */
373 queue_push(&solv->decisionq, v);
374 queue_push(&solv->decisionq_why, r - solv->rules);
375 solv->decisionmap[vv] = v > 0 ? 1 : -1;
376 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
378 Solvable *s = solv->pool->solvables + vv;
380 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
382 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
387 /* check against previous decision: is there a conflict? */
388 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
390 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
396 * The rule (r) we're currently processing says something
397 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
401 if (ri >= solv->learntrules)
403 /* conflict with a learnt rule */
404 /* can happen when packages cannot be installed for multiple reasons. */
405 /* we disable the learnt rule in this case */
406 /* (XXX: we should really call analyze_unsolvable_rule here!) */
407 solver_disablerule(solv, r);
412 * find the decision which is the "opposite" of the rule
414 for (i = 0; i < solv->decisionq.count; i++)
415 if (solv->decisionq.elements[i] == -v)
417 assert(i < solv->decisionq.count); /* assert that we found it */
418 oldproblemcount = solv->problems.count;
421 * conflict with system solvable ?
423 if (v == -SYSTEMSOLVABLE)
427 queue_push(&solv->problems, solv->learnt_pool.count);
428 queue_push(&solv->learnt_pool, ri);
429 queue_push(&solv->learnt_pool, 0);
432 queue_push(&solv->problems, 0);
433 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
434 if (ri >= solv->jobrules && ri < solv->jobrules_end)
435 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
438 queue_push(&solv->problems, v);
439 queue_push(&solv->problems, 0);
440 if (v >= solv->featurerules && v < solv->updaterules_end)
442 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
443 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
445 solv->problems.count = oldproblemcount;
447 break; /* start over */
450 solver_disableproblem(solv, v);
452 break; /* start over */
455 assert(solv->decisionq_why.elements[i] > 0);
458 * conflict with a pkg rule ?
460 if (solv->decisionq_why.elements[i] < solv->pkgrules_end)
464 queue_push(&solv->problems, solv->learnt_pool.count);
465 queue_push(&solv->learnt_pool, ri);
466 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
467 queue_push(&solv->learnt_pool, 0);
470 queue_push(&solv->problems, 0);
471 assert(v > 0 || v == -SYSTEMSOLVABLE);
472 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with pkg rule, disabling rule #%d\n", ri);
473 if (ri >= solv->jobrules && ri < solv->jobrules_end)
474 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
477 queue_push(&solv->problems, v);
478 queue_push(&solv->problems, 0);
479 if (v >= solv->featurerules && v < solv->updaterules_end)
481 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
482 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
484 solv->problems.count = oldproblemcount;
486 break; /* start over */
489 solver_disableproblem(solv, v);
491 break; /* start over */
495 * conflict with another job or update/feature rule
501 queue_push(&solv->problems, solv->learnt_pool.count);
502 queue_push(&solv->learnt_pool, ri);
503 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
504 queue_push(&solv->learnt_pool, 0);
507 queue_push(&solv->problems, 0);
509 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
512 * push all of our rules (can only be feature or job rules)
513 * asserting this literal on the problem stack
515 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
517 if (rr->d < 0 /* disabled */
518 || rr->w2) /* or no assertion */
520 if (rr->p != vv /* not affecting the literal */
523 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
526 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
527 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
530 if (i >= solv->jobrules && i < solv->jobrules_end)
531 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
532 queue_push(&solv->problems, v);
534 queue_push(&solv->problems, 0);
536 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
537 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
539 solv->problems.count = oldproblemcount;
541 break; /* start over */
544 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
545 solver_disableproblem(solv, solv->problems.elements[i]);
547 break; /* start over */
549 if (ii < solv->ruleassertions.count)
553 * phase 2: now do the weak assertions
555 if (!solv->weakrulemap.size)
556 break; /* no weak rules, no phase 2 */
557 for (ii = 0; ii < solv->ruleassertions.count; ii++)
559 ri = solv->ruleassertions.elements[ii];
560 r = solv->rules + ri;
561 if (r->d < 0 || r->w2) /* disabled or no assertion */
563 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
568 if (!solv->decisionmap[vv]) /* if not yet decided */
570 queue_push(&solv->decisionq, v);
571 queue_push(&solv->decisionq_why, r - solv->rules);
572 solv->decisionmap[vv] = v > 0 ? 1 : -1;
573 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
575 Solvable *s = solv->pool->solvables + vv;
577 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
579 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
583 /* check against previous decision: is there a conflict? */
584 if (v > 0 && solv->decisionmap[vv] > 0)
586 if (v < 0 && solv->decisionmap[vv] < 0)
589 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
590 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
592 if (ri >= solv->jobrules && ri < solv->jobrules_end)
593 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
596 solver_disableproblem(solv, v);
598 solver_reenablepolicyrules(solv, -v);
600 break; /* start over */
602 if (ii == solv->ruleassertions.count)
603 break; /* finished! */
608 /********************************************************************/
612 /*-------------------------------------------------------------------
615 * initial setup for all watches
619 makewatches(Solver *solv)
623 int nsolvables = solv->pool->nsolvables;
625 solv_free(solv->watches);
626 /* lower half for removals, upper half for installs */
627 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
628 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
630 if (!r->w2) /* assertions do not need watches */
633 /* see addwatches_rule(solv, r) */
634 r->n1 = solv->watches[nsolvables + r->w1];
635 solv->watches[nsolvables + r->w1] = r - solv->rules;
637 r->n2 = solv->watches[nsolvables + r->w2];
638 solv->watches[nsolvables + r->w2] = r - solv->rules;
643 /*-------------------------------------------------------------------
645 * add watches (for a new learned rule)
646 * sets up watches for a single rule
648 * see also makewatches() above.
652 addwatches_rule(Solver *solv, Rule *r)
654 int nsolvables = solv->pool->nsolvables;
656 r->n1 = solv->watches[nsolvables + r->w1];
657 solv->watches[nsolvables + r->w1] = r - solv->rules;
659 r->n2 = solv->watches[nsolvables + r->w2];
660 solv->watches[nsolvables + r->w2] = r - solv->rules;
664 /********************************************************************/
670 /* shortcuts to check if a literal (positive or negative) assignment
671 * evaluates to 'true' or 'false'
673 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
674 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
675 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
677 /*-------------------------------------------------------------------
681 * make decision and propagate to all rules
683 * Evaluate each term affected by the decision (linked through watches).
684 * If we find unit rules we make new decisions based on them.
686 * return : 0 = everything is OK
687 * rule = conflict found in this rule
691 propagate(Solver *solv, int level)
693 Pool *pool = solv->pool;
694 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
696 Id p, pkg, other_watch;
698 Id *decisionmap = solv->decisionmap;
699 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
701 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
703 /* foreach non-propagated decision */
704 while (solv->propagate_index < solv->decisionq.count)
707 * 'pkg' was just decided
708 * negate because our watches trigger if literal goes FALSE
710 pkg = -solv->decisionq.elements[solv->propagate_index++];
712 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
714 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
715 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
718 /* foreach rule where 'pkg' is now FALSE */
719 for (rp = watches + pkg; *rp; rp = next_rp)
721 r = solv->rules + *rp;
724 /* rule is disabled, goto next */
732 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
734 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
735 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
739 * 'pkg' was just decided (was set to FALSE), so this rule
742 /* find the other watch */
755 * if the other watch is true we have nothing to do
757 if (DECISIONMAP_TRUE(other_watch))
761 * The other literal is FALSE or UNDEF
767 /* Not a binary clause, try to move our watch.
769 * Go over all literals and find one that is
773 * (TRUE is also ok, in that case the rule is fulfilled)
774 * As speed matters here we do not use the FOR_RULELITERALS
777 if (r->p /* we have a 'p' */
778 && r->p != other_watch /* which is not watched */
779 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
783 else /* go find a 'd' to make 'true' */
786 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
788 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
790 if (p != other_watch /* which is not watched */
791 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
799 * if we found some p that is UNDEF or TRUE, move
802 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
805 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
807 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
823 watches[p] = r - solv->rules;
826 /* search failed, thus all unwatched literals are FALSE */
831 * unit clause found, set literal other_watch to TRUE
834 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
835 return r; /* eek, a conflict! */
837 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
839 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
840 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
844 decisionmap[other_watch] = level; /* install! */
846 decisionmap[-other_watch] = -level; /* remove! */
848 queue_push(&solv->decisionq, other_watch);
849 queue_push(&solv->decisionq_why, r - solv->rules);
851 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
854 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
856 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
859 } /* foreach rule involving 'pkg' */
861 } /* while we have non-decided decisions */
863 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
865 return 0; /* all is well */
869 /********************************************************************/
872 /*-------------------------------------------------------------------
875 * revert decisionq to a level
879 revert(Solver *solv, int level)
881 Pool *pool = solv->pool;
883 while (solv->decisionq.count)
885 v = solv->decisionq.elements[solv->decisionq.count - 1];
887 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
889 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
890 solv->decisionmap[vv] = 0;
891 solv->decisionq.count--;
892 solv->decisionq_why.count--;
893 solv->propagate_index = solv->decisionq.count;
895 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
896 solv->branches.count -= solv->branches.elements[solv->branches.count - 2];
897 if (solv->recommends_index > solv->decisionq.count)
898 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
899 if (solv->decisionq.count < solv->decisioncnt_jobs)
900 solv->decisioncnt_jobs = 0;
901 if (solv->decisionq.count < solv->decisioncnt_update)
902 solv->decisioncnt_update = 0;
903 if (solv->decisionq.count < solv->decisioncnt_keep)
904 solv->decisioncnt_keep = 0;
905 if (solv->decisionq.count < solv->decisioncnt_resolve)
906 solv->decisioncnt_resolve = 0;
907 if (solv->decisionq.count < solv->decisioncnt_weak)
908 solv->decisioncnt_weak= 0;
909 if (solv->decisionq.count < solv->decisioncnt_orphan)
910 solv->decisioncnt_orphan = 0;
913 /*-------------------------------------------------------------------
915 * watch2onhighest - put watch2 on literal with highest level
919 watch2onhighest(Solver *solv, Rule *r)
924 d = r->d < 0 ? -r->d - 1 : r->d;
926 return; /* binary rule, both watches are set */
927 dp = solv->pool->whatprovidesdata + d;
928 while ((v = *dp++) != 0)
930 l = solv->decisionmap[v < 0 ? -v : v];
942 /*-------------------------------------------------------------------
949 analyze(Solver *solv, int level, Rule *c, Rule **lrp)
951 Pool *pool = solv->pool;
956 Map seen; /* global? */
957 Id p = 0, pp, v, vv, why;
959 int num = 0, l1num = 0;
960 int learnt_why = solv->learnt_pool.count;
961 Id *decisionmap = solv->decisionmap;
963 queue_init_buffer(&q, q_buf, sizeof(q_buf)/sizeof(*q_buf));
965 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
966 map_init(&seen, pool->nsolvables);
967 idx = solv->decisionq.count;
970 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
971 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
972 queue_push(&solv->learnt_pool, c - solv->rules);
973 FOR_RULELITERALS(v, pp, c)
975 if (DECISIONMAP_TRUE(v)) /* the one true literal */
978 if (MAPTST(&seen, vv))
980 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
981 l = solv->decisionmap[vv];
985 l1num++; /* need to do this one in level1 pass */
987 num++; /* need to do this one as well */
990 queue_push(&q, v); /* not level1 or conflict level, add to new rule */
996 if (!num && !--l1num)
997 break; /* all literals done */
999 /* find the next literal to investigate */
1000 /* (as num + l1num > 0, we know that we'll always find one) */
1004 v = solv->decisionq.elements[--idx];
1005 vv = v > 0 ? v : -v;
1006 if (MAPTST(&seen, vv))
1011 if (num && --num == 0)
1013 /* done with normal literals, now start level 1 literal processing */
1014 p = -v; /* so that v doesn't get lost */
1017 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1018 /* clear non-l1 bits from seen map */
1019 for (i = 0; i < q.count; i++)
1022 MAPCLR(&seen, v > 0 ? v : -v);
1024 /* only level 1 marks left in seen map */
1025 l1num++; /* as l1retry decrements it */
1029 why = solv->decisionq_why.elements[idx];
1030 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
1032 c = solv->rules + why;
1036 assert(rlevel > 0 && rlevel < level);
1037 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1039 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1040 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1041 for (i = 0; i < q.count; i++)
1042 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, q.elements[i]);
1044 /* push end marker on learnt reasons stack */
1045 queue_push(&solv->learnt_pool, 0);
1046 solv->stats_learned++;
1048 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, rlevel);
1050 revert(solv, level);
1053 Id d = q.count ? q.elements[0] : 0;
1055 r = solver_addrule(solv, p, d, 0);
1059 Id d = pool_queuetowhatprovides(pool, &q);
1061 r = solver_addrule(solv, p, 0, d);
1063 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1064 queue_push(&solv->learnt_why, learnt_why);
1068 watch2onhighest(solv, r);
1069 addwatches_rule(solv, r);
1073 /* rule is an assertion */
1074 queue_push(&solv->ruleassertions, r - solv->rules);
1081 /*-------------------------------------------------------------------
1085 * reset all solver decisions
1086 * called after rules have been enabled/disabled
1090 solver_reset(Solver *solv)
1095 /* rewind all decisions */
1096 for (i = solv->decisionq.count - 1; i >= 0; i--)
1098 v = solv->decisionq.elements[i];
1099 solv->decisionmap[v > 0 ? v : -v] = 0;
1101 queue_empty(&solv->decisionq_why);
1102 queue_empty(&solv->decisionq);
1103 solv->recommends_index = -1;
1104 solv->propagate_index = 0;
1105 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
1106 queue_empty(&solv->branches);
1108 /* adapt learnt rule status to new set of enabled/disabled rules */
1109 enabledisablelearntrules(solv);
1113 /*-------------------------------------------------------------------
1115 * analyze_unsolvable_rule
1117 * recursion helper used by analyze_unsolvable
1121 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1123 Pool *pool = solv->pool;
1125 Id why = r - solv->rules;
1127 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1128 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1129 if (solv->learntrules && why >= solv->learntrules)
1131 if (MAPTST(rseen, why - solv->learntrules))
1133 MAPSET(rseen, why - solv->learntrules);
1134 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1135 if (solv->learnt_pool.elements[i] > 0)
1136 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1139 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, why))
1140 if (!*lastweakp || why > *lastweakp)
1142 /* do not add pkg rules to problem */
1143 if (why < solv->pkgrules_end)
1145 /* turn rule into problem */
1146 if (why >= solv->jobrules && why < solv->jobrules_end)
1147 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1148 /* normalize dup/infarch rules */
1149 if (why > solv->infarchrules && why < solv->infarchrules_end)
1151 Id name = pool->solvables[-solv->rules[why].p].name;
1152 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1155 if (why > solv->duprules && why < solv->duprules_end)
1157 Id name = pool->solvables[-solv->rules[why].p].name;
1158 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1162 /* return if problem already countains our rule */
1163 if (solv->problems.count)
1165 for (i = solv->problems.count - 1; i >= 0; i--)
1166 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1168 else if (solv->problems.elements[i] == why)
1171 queue_push(&solv->problems, why);
1175 /*-------------------------------------------------------------------
1177 * analyze_unsolvable (called from setpropagatelearn)
1179 * We know that the problem is not solvable. Record all involved
1180 * rules (i.e. the "proof") into solv->learnt_pool.
1181 * Record the learnt pool index and all non-pkg rules into
1182 * solv->problems. (Our solutions to fix the problems are to
1183 * disable those rules.)
1185 * If the proof contains at least one weak rule, we disable the
1188 * Otherwise we return -1 if disablerules is not set or disable
1189 * _all_ of the problem rules and return 0.
1191 * return: 0 - disabled some rules, try again
1196 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1198 Pool *pool = solv->pool;
1200 Map involved; /* global to speed things up? */
1204 Id *decisionmap = solv->decisionmap;
1205 int oldproblemcount;
1206 int oldlearntpoolcount;
1208 int record_proof = 1;
1210 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1211 solv->stats_unsolvable++;
1212 oldproblemcount = solv->problems.count;
1213 oldlearntpoolcount = solv->learnt_pool.count;
1215 /* make room for proof index */
1216 /* must update it later, as analyze_unsolvable_rule would confuse
1217 * it with a rule index if we put the real value in already */
1218 queue_push(&solv->problems, 0);
1221 map_init(&involved, pool->nsolvables);
1222 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1224 queue_push(&solv->learnt_pool, r - solv->rules);
1226 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1227 FOR_RULELITERALS(v, pp, r)
1229 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1231 vv = v > 0 ? v : -v;
1232 MAPSET(&involved, vv);
1234 idx = solv->decisionq.count;
1237 v = solv->decisionq.elements[--idx];
1238 vv = v > 0 ? v : -v;
1239 if (!MAPTST(&involved, vv) || vv == SYSTEMSOLVABLE)
1241 why = solv->decisionq_why.elements[idx];
1244 queue_push(&solv->learnt_pool, why);
1245 r = solv->rules + why;
1246 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1247 FOR_RULELITERALS(v, pp, r)
1249 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1251 vv = v > 0 ? v : -v;
1252 MAPSET(&involved, vv);
1255 map_free(&involved);
1257 queue_push(&solv->problems, 0); /* mark end of this problem */
1261 /* disable last weak rule */
1262 solv->problems.count = oldproblemcount;
1263 solv->learnt_pool.count = oldlearntpoolcount;
1264 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1265 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1268 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1269 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1270 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1271 solver_disablechoicerules(solv, solv->rules + lastweak);
1272 solver_disableproblem(solv, v);
1274 solver_reenablepolicyrules(solv, -v);
1279 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
1280 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
1282 solv->problems.count = oldproblemcount;
1283 solv->learnt_pool.count = oldlearntpoolcount;
1291 queue_push(&solv->learnt_pool, 0);
1292 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1295 /* + 2: index + trailing zero */
1296 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1298 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1299 solver_disableproblem(solv, solv->problems.elements[i]);
1300 /* XXX: might want to enable all weak rules again */
1304 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1309 /*-------------------------------------------------------------------
1313 * add free decision (solvable to install) to decisionq
1314 * increase level and propagate decision
1315 * return if no conflict.
1317 * in conflict case, analyze conflict rule, add resulting
1318 * rule to learnt rule set, make decision from learnt
1319 * rule (always unit) and re-propagate.
1321 * returns the new solver level or -1 if unsolvable
1326 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1328 Pool *pool = solv->pool;
1335 solv->decisionmap[decision] = level;
1337 solv->decisionmap[-decision] = -level;
1338 queue_push(&solv->decisionq, decision);
1339 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1341 assert(ruleid >= 0 && level > 0);
1344 r = propagate(solv, level);
1348 return analyze_unsolvable(solv, r, disablerules);
1349 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1350 level = analyze(solv, level, r, &lr);
1351 /* the new rule is unit by design */
1353 solv->decisionmap[decision > 0 ? decision : -decision] = decision > 0 ? level : -level;
1354 queue_push(&solv->decisionq, decision);
1355 queue_push(&solv->decisionq_why, lr - solv->rules);
1356 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1358 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1359 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, decision);
1360 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1361 solver_printrule(solv, SOLV_DEBUG_ANALYZE, lr);
1368 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1370 Pool *pool = solv->pool;
1371 int i, j, haveone = 0, dqcount = dq->count;
1372 int decisionqcount = solv->decisionq.count;
1376 /* at the time we process jobrules the installed packages are not kept yet */
1377 /* reorder so that "future-supplemented" packages come first */
1378 FOR_REPO_SOLVABLES(solv->installed, p, s)
1380 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1382 if (solv->decisionmap[p] == 0)
1384 if (s->recommends || s->suggests)
1385 queue_push(&solv->decisionq, p);
1386 solv->decisionmap[p] = level + 1;
1392 policy_update_recommendsmap(solv);
1393 for (i = 0; i < dqcount; i++)
1395 p = dq->elements[i];
1396 if (!(pool->solvables[p].repo == solv->installed || MAPTST(&solv->suggestsmap, p) || solver_is_enhancing(solv, pool->solvables + p)))
1399 dq->elements[i] = 0;
1402 dqcount = dq->count;
1403 for (i = 0; i < dqcount; i++)
1405 p = dq->elements[i];
1406 if (p && !(pool->solvables[p].repo == solv->installed || MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
1409 dq->elements[i] = 0;
1412 for (i = j = 0; i < dq->count; i++)
1413 if (dq->elements[i])
1414 dq->elements[j++] = dq->elements[i];
1415 queue_truncate(dq, j);
1416 FOR_REPO_SOLVABLES(solv->installed, p, s)
1417 if (solv->decisionmap[p] == level + 1)
1418 solv->decisionmap[p] = 0;
1419 if (solv->decisionq.count != decisionqcount)
1421 solv->recommends_index = -1;
1422 queue_truncate(&solv->decisionq, decisionqcount);
1426 /*-------------------------------------------------------------------
1432 createbranch(Solver *solv, int level, Queue *dq, Id p, Id data)
1434 Pool *pool = solv->pool;
1436 IF_POOLDEBUG (SOLV_DEBUG_POLICY)
1438 POOL_DEBUG (SOLV_DEBUG_POLICY, "creating a branch:\n");
1439 for (i = 0; i < dq->count; i++)
1440 POOL_DEBUG (SOLV_DEBUG_POLICY, " - %s\n", pool_solvid2str(pool, dq->elements[i]));
1442 queue_push(&solv->branches, -dq->elements[0]);
1443 for (i = 1; i < dq->count; i++)
1444 queue_push(&solv->branches, dq->elements[i]);
1445 queue_push2(&solv->branches, p, data);
1446 queue_push2(&solv->branches, dq->count + 4, level);
1450 takebranch(Solver *solv, int pos, int end, const char *msg, int disablerules)
1452 Pool *pool = solv->pool;
1458 printf("branch group level %d [%d-%d] %d %d:\n", solv->branches.elements[end - 1], start, end, solv->branches.elements[end - 4], solv->branches.elements[end - 3]);
1459 for (i = end - solv->branches.elements[end - 2]; i < end - 4; i++)
1460 printf("%c %c%s\n", i == pos ? 'x' : ' ', solv->branches.elements[i] >= 0 ? ' ' : '-', pool_solvid2str(pool, solv->branches.elements[i] >= 0 ? solv->branches.elements[i] : -solv->branches.elements[i]));
1463 level = solv->branches.elements[end - 1];
1464 p = solv->branches.elements[pos];
1465 solv->branches.elements[pos] = -p;
1466 POOL_DEBUG(SOLV_DEBUG_SOLVER, "%s %d -> %d with %s\n", msg, solv->decisionmap[p], level, pool_solvid2str(pool, p));
1467 /* hack: set level to zero so that revert does not remove the branch */
1468 solv->branches.elements[end - 1] = 0;
1469 revert(solv, level);
1470 solv->branches.elements[end - 1] = level;
1471 /* hack: revert simply sets the count, so we can still access the reverted elements */
1472 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
1474 return setpropagatelearn(solv, level, p, disablerules, why);
1477 /*-------------------------------------------------------------------
1479 * select and install
1481 * install best package from the queue. We add an extra package, inst, if
1482 * provided. See comment in weak install section.
1484 * returns the new solver level or -1 if unsolvable
1489 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1491 Pool *pool = solv->pool;
1495 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1496 /* if we're resolving job rules and didn't resolve the installed packages yet,
1497 * do some special supplements ordering */
1498 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed && !solv->focus_installed)
1499 reorder_dq_for_jobrules(solv, level, dq);
1500 /* if we have multiple candidates we open a branch */
1502 createbranch(solv, level, dq, 0, ruleid);
1503 p = dq->elements[0];
1504 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1505 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1509 /********************************************************************/
1510 /* Main solver interface */
1513 /*-------------------------------------------------------------------
1516 * create solver structure
1518 * pool: all available solvables
1519 * installed: installed Solvables
1522 * Upon solving, rules are created to flag the Solvables
1523 * of the 'installed' Repo as installed.
1527 solver_create(Pool *pool)
1530 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1532 solv->installed = pool->installed;
1534 solv->allownamechange = 1;
1536 solv->dup_allowdowngrade = 1;
1537 solv->dup_allownamechange = 1;
1538 solv->dup_allowarchchange = 1;
1539 solv->dup_allowvendorchange = 1;
1541 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1543 queue_init(&solv->ruletojob);
1544 queue_init(&solv->decisionq);
1545 queue_init(&solv->decisionq_why);
1546 queue_init(&solv->problems);
1547 queue_init(&solv->orphaned);
1548 queue_init(&solv->learnt_why);
1549 queue_init(&solv->learnt_pool);
1550 queue_init(&solv->branches);
1551 queue_init(&solv->weakruleq);
1552 queue_init(&solv->ruleassertions);
1553 queue_init(&solv->addedmap_deduceq);
1555 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1557 map_init(&solv->recommendsmap, pool->nsolvables);
1558 map_init(&solv->suggestsmap, pool->nsolvables);
1559 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1560 solv->recommends_index = 0;
1562 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1564 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1565 memset(solv->rules, 0, sizeof(Rule));
1572 resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
1574 Pool *pool = solv->pool;
1575 int oldlevel = level;
1579 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1580 if (!solv->decisioncnt_jobs)
1581 solv->decisioncnt_jobs = solv->decisionq.count;
1582 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1585 if (r->d < 0) /* ignore disabled rules */
1588 FOR_RULELITERALS(l, pp, r)
1592 if (solv->decisionmap[-l] <= 0)
1597 if (solv->decisionmap[l] > 0)
1599 if (solv->decisionmap[l] == 0)
1603 if (l || !dq->count)
1605 /* prune to installed if not updating */
1606 if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
1607 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1610 for (j = k = 0; j < dq->count; j++)
1612 Solvable *s = pool->solvables + dq->elements[j];
1613 if (s->repo == solv->installed)
1615 dq->elements[k++] = dq->elements[j];
1616 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
1618 k = 0; /* package wants to be updated, do not prune */
1627 level = selectandinstall(solv, level, dq, disablerules, i);
1628 if (level <= olevel)
1630 if (level == olevel)
1634 continue; /* try something else */
1636 if (level < oldlevel)
1638 /* redo from start of jobrules */
1639 i = solv->jobrules - 1;
1640 r = solv->rules + i;
1646 /*-------------------------------------------------------------------
1652 queuep_free(Queue **qp)
1657 *qp = solv_free(*qp);
1661 map_zerosize(Map *m)
1671 solver_free(Solver *solv)
1673 queue_free(&solv->job);
1674 queue_free(&solv->ruletojob);
1675 queue_free(&solv->decisionq);
1676 queue_free(&solv->decisionq_why);
1677 queue_free(&solv->learnt_why);
1678 queue_free(&solv->learnt_pool);
1679 queue_free(&solv->problems);
1680 queue_free(&solv->solutions);
1681 queue_free(&solv->orphaned);
1682 queue_free(&solv->branches);
1683 queue_free(&solv->weakruleq);
1684 queue_free(&solv->ruleassertions);
1685 queue_free(&solv->addedmap_deduceq);
1686 queuep_free(&solv->cleandeps_updatepkgs);
1687 queuep_free(&solv->cleandeps_mistakes);
1688 queuep_free(&solv->update_targets);
1689 queuep_free(&solv->installsuppdepq);
1690 queuep_free(&solv->recommendscplxq);
1691 queuep_free(&solv->suggestscplxq);
1692 queuep_free(&solv->brokenorphanrules);
1694 map_free(&solv->recommendsmap);
1695 map_free(&solv->suggestsmap);
1696 map_free(&solv->noupdate);
1697 map_free(&solv->weakrulemap);
1698 map_free(&solv->multiversion);
1700 map_free(&solv->updatemap);
1701 map_free(&solv->bestupdatemap);
1702 map_free(&solv->fixmap);
1703 map_free(&solv->dupmap);
1704 map_free(&solv->dupinvolvedmap);
1705 map_free(&solv->droporphanedmap);
1706 map_free(&solv->cleandepsmap);
1707 map_free(&solv->allowuninstallmap);
1709 solv_free(solv->decisionmap);
1710 solv_free(solv->rules);
1711 solv_free(solv->watches);
1712 solv_free(solv->obsoletes);
1713 solv_free(solv->obsoletes_data);
1714 solv_free(solv->specialupdaters);
1715 solv_free(solv->choicerules_ref);
1716 solv_free(solv->bestrules_pkg);
1717 solv_free(solv->yumobsrules_info);
1718 solv_free(solv->instbuddy);
1723 solver_get_flag(Solver *solv, int flag)
1727 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1728 return solv->allowdowngrade;
1729 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1730 return solv->allownamechange;
1731 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1732 return solv->allowarchchange;
1733 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1734 return solv->allowvendorchange;
1735 case SOLVER_FLAG_ALLOW_UNINSTALL:
1736 return solv->allowuninstall;
1737 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1738 return solv->noupdateprovide;
1739 case SOLVER_FLAG_SPLITPROVIDES:
1740 return solv->dosplitprovides;
1741 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1742 return solv->dontinstallrecommended;
1743 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1744 return solv->addalreadyrecommended;
1745 case SOLVER_FLAG_NO_INFARCHCHECK:
1746 return solv->noinfarchcheck;
1747 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1748 return solv->keepexplicitobsoletes;
1749 case SOLVER_FLAG_BEST_OBEY_POLICY:
1750 return solv->bestobeypolicy;
1751 case SOLVER_FLAG_NO_AUTOTARGET:
1752 return solv->noautotarget;
1753 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1754 return solv->dup_allowdowngrade;
1755 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1756 return solv->dup_allownamechange;
1757 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1758 return solv->dup_allowarchchange;
1759 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1760 return solv->dup_allowvendorchange;
1761 case SOLVER_FLAG_KEEP_ORPHANS:
1762 return solv->keep_orphans;
1763 case SOLVER_FLAG_BREAK_ORPHANS:
1764 return solv->break_orphans;
1765 case SOLVER_FLAG_FOCUS_INSTALLED:
1766 return solv->focus_installed;
1767 case SOLVER_FLAG_YUM_OBSOLETES:
1768 return solv->do_yum_obsoletes;
1769 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1770 return solv->needupdateprovide;
1778 solver_set_flag(Solver *solv, int flag, int value)
1780 int old = solver_get_flag(solv, flag);
1783 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1784 solv->allowdowngrade = value;
1786 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1787 solv->allownamechange = value;
1789 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1790 solv->allowarchchange = value;
1792 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1793 solv->allowvendorchange = value;
1795 case SOLVER_FLAG_ALLOW_UNINSTALL:
1796 solv->allowuninstall = value;
1798 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1799 solv->noupdateprovide = value;
1801 case SOLVER_FLAG_SPLITPROVIDES:
1802 solv->dosplitprovides = value;
1804 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1805 solv->dontinstallrecommended = value;
1807 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1808 solv->addalreadyrecommended = value;
1810 case SOLVER_FLAG_NO_INFARCHCHECK:
1811 solv->noinfarchcheck = value;
1813 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1814 solv->keepexplicitobsoletes = value;
1816 case SOLVER_FLAG_BEST_OBEY_POLICY:
1817 solv->bestobeypolicy = value;
1819 case SOLVER_FLAG_NO_AUTOTARGET:
1820 solv->noautotarget = value;
1822 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1823 solv->dup_allowdowngrade = value;
1825 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1826 solv->dup_allownamechange = value;
1828 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1829 solv->dup_allowarchchange = value;
1831 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1832 solv->dup_allowvendorchange = value;
1834 case SOLVER_FLAG_KEEP_ORPHANS:
1835 solv->keep_orphans = value;
1837 case SOLVER_FLAG_BREAK_ORPHANS:
1838 solv->break_orphans = value;
1840 case SOLVER_FLAG_FOCUS_INSTALLED:
1841 solv->focus_installed = value;
1843 case SOLVER_FLAG_YUM_OBSOLETES:
1844 solv->do_yum_obsoletes = value;
1846 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1847 solv->needupdateprovide = value;
1856 cleandeps_check_mistakes(Solver *solv)
1858 Pool *pool = solv->pool;
1862 int mademistake = 0;
1864 if (!solv->cleandepsmap.size)
1866 /* check for mistakes */
1867 for (i = solv->installed->start; i < solv->installed->end; i++)
1869 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1871 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1872 /* a mistake is when the featurerule is true but the updaterule is false */
1875 FOR_RULELITERALS(p, pp, r)
1876 if (p > 0 && solv->decisionmap[p] > 0)
1879 continue; /* feature rule is not true */
1880 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1883 FOR_RULELITERALS(p, pp, r)
1884 if (p > 0 && solv->decisionmap[p] > 0)
1887 continue; /* update rule is true */
1888 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1889 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1890 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1891 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1892 if (!solv->cleandeps_mistakes)
1894 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1895 queue_init(solv->cleandeps_mistakes);
1897 queue_push(solv->cleandeps_mistakes, i);
1898 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1899 solver_reenablepolicyrules_cleandeps(solv, i);
1906 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1910 for (i = j = 0; i < q->count; i++)
1913 for (cp2 = cp; *cp2; cp2++)
1916 q->elements[j++] = p;
1920 queue_truncate(q, j);
1923 #ifdef ENABLE_COMPLEX_DEPS
1926 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1928 Pool *pool = solv->pool;
1929 int oldcnt = dq->count;
1935 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1937 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1938 if (i == 0 || i == 1)
1941 for (i = oldcnt; i < cutcnt; i++)
1944 for (; (p = dq->elements[i]) != 0; i++)
1948 if (solv->decisionmap[-p] <= 0)
1952 if (solv->decisionmap[p] > 0)
1954 queue_truncate(dq, blkcnt);
1959 if (!MAPTST(dqmap, p))
1964 if (solv->decisionmap[p] < 0)
1966 if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
1971 while (dq->elements[i])
1974 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1976 if (dq->count != oldcnt)
1978 for (j = oldcnt; j < dq->count; j++)
1980 p = dq->elements[j];
1981 for (i = 0; i < j; i++)
1982 if (dq->elements[i] == p)
1984 dq->elements[j] = 0;
1988 for (i = j = oldcnt; j < dq->count; j++)
1989 if (dq->elements[j])
1990 dq->elements[i++] = dq->elements[j];
1991 queue_truncate(dq, i);
1994 printf("RETURN:\n");
1995 for (i = oldcnt; i < dq->count; i++)
1996 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
2001 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
2003 Pool *pool = solv->pool;
2009 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
2012 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
2013 if (i == 0 || i == 1)
2018 for (i = 0; i < dq.count; i++)
2021 for (; (p = dq.elements[i]) != 0; i++)
2025 if (solv->decisionmap[-p] <= 0)
2029 if (solv->decisionmap[p] > 0)
2034 for (i++; (p = dq.elements[i]) != 0; i++)
2035 if (p > 0 && solv->decisionmap[p] > 0)
2043 for (i = blk; (p = dq.elements[i]) != 0; i++)
2047 while (dq.elements[i])
2055 /*-------------------------------------------------------------------
2059 * all rules have been set up, now actually run the solver
2064 solver_run_sat(Solver *solv, int disablerules, int doweak)
2066 Queue dq; /* local decisionqueue */
2067 Queue dqs; /* local decisionqueue for supplements */
2073 Pool *pool = solv->pool;
2074 Id p, pp, *dp, postponed;
2075 int minimizationsteps;
2076 int installedpos = solv->installed ? solv->installed->start : 0;
2078 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
2080 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2081 for (i = 1; i < solv->nrules; i++)
2082 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
2085 /* start SAT algorithm */
2087 systemlevel = level + 1;
2088 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
2094 * here's the main loop:
2095 * 1) decide assertion rules and propagate
2097 * 3) try to keep installed packages
2098 * 4) fulfill all unresolved rules
2099 * 5) install recommended packages
2100 * 6) minimalize solution if we had choices
2101 * if we encounter a problem, we rewind to a safe level and restart
2105 minimizationsteps = 0;
2109 * initial propagation of the assertions
2115 makeruledecisions(solv);
2117 if (!disablerules && solv->problems.count)
2122 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "initial propagate (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2123 if ((r = propagate(solv, level)) != 0)
2125 level = analyze_unsolvable(solv, r, disablerules);
2128 systemlevel = level + 1;
2132 * resolve jobs first (unless focus_installed is set)
2134 if (level < systemlevel && !solv->focus_installed)
2137 level = resolve_jobrules(solv, level, disablerules, &dq);
2140 systemlevel = level + 1;
2145 * installed packages
2147 if (!solv->decisioncnt_update)
2148 solv->decisioncnt_update = solv->decisionq.count;
2149 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2151 Repo *installed = solv->installed;
2154 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2155 /* we use two passes if we need to update packages
2156 * to create a better user experience */
2157 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2159 int passlevel = level;
2160 Id *specialupdaters = solv->specialupdaters;
2161 if (pass == 1 && !solv->decisioncnt_keep)
2162 solv->decisioncnt_keep = solv->decisionq.count;
2163 /* start with installedpos, the position that gave us problems the last time */
2164 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2169 if (i == installed->end)
2170 i = installed->start;
2171 s = pool->solvables + i;
2172 if (s->repo != installed)
2175 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2176 continue; /* already decided */
2177 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2178 continue; /* updates first */
2179 r = solv->rules + solv->updaterules + (i - installed->start);
2181 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2182 rr -= solv->installed->end - solv->installed->start;
2183 if (!rr->p) /* identical to update rule? */
2185 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2186 continue; /* orpaned package */
2188 /* check if we should update this package to the latest version
2189 * noupdate is set for erase jobs, in that case we want to deinstall
2190 * the installed package and not replace it with a newer version
2191 * rr->p != i is for dup jobs where the installed package cannot be kept */
2193 if (!MAPTST(&solv->noupdate, i - installed->start) && (solv->decisionmap[i] < 0 || solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || (rr->p && rr->p != i)))
2197 /* specialupdater with no update/feature rule */
2198 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2200 if (solv->decisionmap[p] > 0)
2205 if (!solv->decisionmap[p])
2209 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2211 /* special multiversion handling, make sure best version is chosen */
2212 if (rr->p == i && solv->decisionmap[i] >= 0)
2214 while ((p = pool->whatprovidesdata[d++]) != 0)
2215 if (solv->decisionmap[p] >= 0)
2217 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2218 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2221 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2223 if (p != i && solv->decisionmap[p] == 0)
2225 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2226 if (!rr->p) /* update rule == feature rule? */
2227 rr = rr - solv->featurerules + solv->updaterules;
2236 /* update to best package of the update rule */
2237 FOR_RULELITERALS(p, pp, rr)
2239 if (solv->decisionmap[p] > 0)
2241 dq.count = 0; /* already fulfilled */
2244 if (!solv->decisionmap[p])
2249 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2250 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2251 /* install best version */
2255 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2256 if (level <= olevel)
2258 if (level < passlevel)
2259 break; /* trouble */
2261 n = installed->start; /* redo all */
2267 /* if still undecided keep package */
2268 if (solv->decisionmap[i] == 0)
2271 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2274 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2275 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2282 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2283 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2285 if (level <= olevel)
2287 if (level < passlevel)
2288 break; /* trouble */
2290 n = installed->start; /* redo all */
2293 continue; /* retry with learnt rule */
2297 if (n < installed->end)
2299 installedpos = i; /* retry problem solvable next time */
2300 break; /* ran into trouble */
2302 installedpos = installed->start; /* reset installedpos */
2304 systemlevel = level + 1;
2306 continue; /* had trouble, retry */
2308 if (!solv->decisioncnt_keep)
2309 solv->decisioncnt_keep = solv->decisionq.count;
2311 if (level < systemlevel && solv->focus_installed)
2314 level = resolve_jobrules(solv, level, disablerules, &dq);
2317 systemlevel = level + 1;
2320 if (level < systemlevel)
2321 systemlevel = level;
2326 if (!solv->decisioncnt_resolve)
2327 solv->decisioncnt_resolve = solv->decisionq.count;
2328 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2330 for (i = 1, n = 1; ; i++, n++)
2332 if (n >= solv->nrules)
2340 if (i == solv->nrules)
2342 r = solv->rules + i;
2343 if (r->d < 0) /* ignore disabled rules */
2345 if (r->p < 0) /* most common cases first */
2347 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2354 /* binary or unary rule */
2355 /* need two positive undecided literals, r->p already checked above */
2358 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2360 queue_push(&dq, r->p);
2361 queue_push(&dq, r->w2);
2366 * all negative literals are installed
2367 * no positive literal is installed
2368 * i.e. the rule is not fulfilled and we
2369 * just need to decide on the positive literals
2370 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2374 if (solv->decisionmap[r->p] > 0)
2376 if (solv->decisionmap[r->p] == 0)
2377 queue_push(&dq, r->p);
2379 dp = pool->whatprovidesdata + r->d;
2380 while ((p = *dp++) != 0)
2384 if (solv->decisionmap[-p] <= 0)
2389 if (solv->decisionmap[p] > 0)
2391 if (solv->decisionmap[p] == 0)
2398 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2400 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2401 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2403 /* dq.count < 2 cannot happen as this means that
2404 * the rule is unit */
2405 assert(dq.count > 1);
2407 /* prune to cleandeps packages */
2408 if (solv->cleandepsmap.size && solv->installed)
2410 Repo *installed = solv->installed;
2411 for (j = 0; j < dq.count; j++)
2412 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2416 dq.elements[0] = dq.elements[j];
2417 queue_truncate(&dq, 1);
2421 if (dq.count > 1 && postponed >= 0)
2423 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE_NOREORDER);
2433 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2434 if (level < systemlevel)
2435 break; /* trouble */
2436 /* something changed, so look at all rules again */
2440 if (n < solv->nrules) /* ran into trouble? */
2441 continue; /* start over */
2443 /* decide leftover cleandeps packages */
2444 if (solv->cleandepsmap.size && solv->installed)
2446 for (p = solv->installed->start; p < solv->installed->end; p++)
2448 s = pool->solvables + p;
2449 if (s->repo != solv->installed)
2451 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2453 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2455 level = setpropagatelearn(solv, level, -p, 0, 0);
2460 if (p < solv->installed->end)
2464 /* at this point we have a consistent system. now do the extras... */
2466 if (!solv->decisioncnt_weak)
2467 solv->decisioncnt_weak = solv->decisionq.count;
2472 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2473 queue_empty(&dq); /* recommended packages */
2474 queue_empty(&dqs); /* supplemented packages */
2475 for (i = 1; i < pool->nsolvables; i++)
2477 if (solv->decisionmap[i] < 0)
2479 if (solv->decisionmap[i] > 0)
2481 /* installed, check for recommends */
2482 Id *recp, rec, pp, p;
2483 s = pool->solvables + i;
2484 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2486 /* XXX need to special case AND ? */
2489 recp = s->repo->idarraydata + s->recommends;
2490 while ((rec = *recp++) != 0)
2492 #ifdef ENABLE_COMPLEX_DEPS
2493 if (pool_is_complex_dep(pool, rec))
2495 add_complex_recommends(solv, rec, &dq, 0);
2500 FOR_PROVIDES(p, pp, rec)
2502 if (solv->decisionmap[p] > 0)
2507 else if (solv->decisionmap[p] == 0)
2509 if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
2511 queue_pushunique(&dq, p);
2519 s = pool->solvables + i;
2520 if (!s->supplements)
2522 if (!pool_installable(pool, s))
2524 if (!solver_is_supplementing(solv, s))
2526 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2528 queue_push(&dqs, i);
2532 /* filter out all packages obsoleted by installed packages */
2533 /* this is no longer needed if we have reverse obsoletes */
2534 if ((dqs.count || dq.count) && solv->installed)
2537 Id obs, *obsp, po, ppo;
2539 map_init(&obsmap, pool->nsolvables);
2540 for (p = solv->installed->start; p < solv->installed->end; p++)
2542 s = pool->solvables + p;
2543 if (s->repo != solv->installed || !s->obsoletes)
2545 if (solv->decisionmap[p] <= 0)
2547 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
2549 obsp = s->repo->idarraydata + s->obsoletes;
2550 /* foreach obsoletes */
2551 while ((obs = *obsp++) != 0)
2552 FOR_PROVIDES(po, ppo, obs)
2553 MAPSET(&obsmap, po);
2555 for (i = j = 0; i < dqs.count; i++)
2556 if (!MAPTST(&obsmap, dqs.elements[i]))
2557 dqs.elements[j++] = dqs.elements[i];
2559 for (i = j = 0; i < dq.count; i++)
2560 if (!MAPTST(&obsmap, dq.elements[i]))
2561 dq.elements[j++] = dq.elements[i];
2566 /* filter out all already supplemented packages if requested */
2567 if (!solv->addalreadyrecommended && dqs.count)
2569 /* filter out old supplements */
2570 for (i = j = 0; i < dqs.count; i++)
2572 p = dqs.elements[i];
2573 s = pool->solvables + p;
2574 if (s->supplements && solver_is_supplementing_alreadyinstalled(solv, s))
2575 dqs.elements[j++] = p;
2580 /* multiversion doesn't mix well with supplements.
2581 * filter supplemented packages where we already decided
2582 * to install a different version (see bnc#501088) */
2583 if (dqs.count && solv->multiversion.size)
2585 for (i = j = 0; i < dqs.count; i++)
2587 p = dqs.elements[i];
2588 if (MAPTST(&solv->multiversion, p))
2591 s = pool->solvables + p;
2592 FOR_PROVIDES(p2, pp2, s->name)
2593 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2596 continue; /* ignore this package */
2598 dqs.elements[j++] = p;
2603 /* make dq contain both recommended and supplemented pkgs */
2606 for (i = 0; i < dqs.count; i++)
2607 queue_pushunique(&dq, dqs.elements[i]);
2613 int decisioncount = solv->decisionq.count;
2617 /* simple case, just one package. no need to choose to best version */
2620 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2622 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2623 level = setpropagatelearn(solv, level, p, 0, 0);
2624 continue; /* back to main loop */
2627 /* filter packages, this gives us the best versions */
2628 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2630 /* create map of result */
2631 map_init(&dqmap, pool->nsolvables);
2632 for (i = 0; i < dq.count; i++)
2633 MAPSET(&dqmap, dq.elements[i]);
2635 /* install all supplemented packages */
2636 for (i = 0; i < dqs.count; i++)
2638 p = dqs.elements[i];
2639 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2641 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2643 level = setpropagatelearn(solv, level, p, 0, 0);
2644 if (level <= olevel)
2647 if (i < dqs.count || solv->decisionq.count < decisioncount)
2653 /* install all recommended packages */
2654 /* more work as we want to created branches if multiple
2655 * choices are valid */
2656 for (i = 0; i < decisioncount; i++)
2659 p = solv->decisionq.elements[i];
2662 s = pool->solvables + p;
2663 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2667 recp = s->repo->idarraydata + s->recommends;
2668 while ((rec = *recp++) != 0)
2671 #ifdef ENABLE_COMPLEX_DEPS
2672 if (pool_is_complex_dep(pool, rec))
2673 add_complex_recommends(solv, rec, &dq, &dqmap);
2676 FOR_PROVIDES(p, pp, rec)
2678 if (solv->decisionmap[p] > 0)
2683 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2689 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2690 /* if we have multiple candidates we open a branch */
2692 createbranch(solv, level, &dq, s - pool->solvables, rec);
2694 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2696 level = setpropagatelearn(solv, level, p, 0, 0);
2697 if (level <= olevel || solv->decisionq.count < decisioncount)
2698 break; /* we had to revert some decisions */
2701 break; /* had a problem above, quit loop */
2704 continue; /* back to main loop so that all deps are checked */
2708 if (!solv->decisioncnt_orphan)
2709 solv->decisioncnt_orphan = solv->decisionq.count;
2710 if (solv->dupmap_all && solv->installed)
2712 int installedone = 0;
2714 /* let's see if we can install some unsupported package */
2715 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2716 for (i = 0; i < solv->orphaned.count; i++)
2718 p = solv->orphaned.elements[i];
2719 if (solv->decisionmap[p])
2720 continue; /* already decided */
2721 if (solv->droporphanedmap_all)
2723 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2725 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2727 level = setpropagatelearn(solv, level, p, 0, 0);
2732 if (installedone || i < solv->orphaned.count)
2733 continue; /* back to main loop */
2734 for (i = 0; i < solv->orphaned.count; i++)
2736 p = solv->orphaned.elements[i];
2737 if (solv->decisionmap[p])
2738 continue; /* already decided */
2739 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2741 level = setpropagatelearn(solv, level, -p, 0, 0);
2745 if (i < solv->orphaned.count)
2746 continue; /* back to main loop */
2747 if (solv->brokenorphanrules)
2749 solver_check_brokenorphanrules(solv, &dq);
2752 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2753 for (i = 0; i < dq.count; i++)
2756 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
2758 level = setpropagatelearn(solv, level, p, 0, 0);
2767 /* one final pass to make sure we decided all installed packages */
2768 if (solv->installed)
2770 for (p = solv->installed->start; p < solv->installed->end; p++)
2772 if (solv->decisionmap[p])
2773 continue; /* already decided */
2774 s = pool->solvables + p;
2775 if (s->repo != solv->installed)
2777 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2779 level = setpropagatelearn(solv, level, -p, 0, 0);
2783 if (p < solv->installed->end)
2784 continue; /* back to main loop */
2787 if (solv->installed && solv->cleandepsmap.size && cleandeps_check_mistakes(solv))
2790 level = 0; /* restart from scratch */
2794 if (solv->solution_callback)
2796 solv->solution_callback(solv, solv->solution_callback_data);
2797 if (solv->branches.count)
2801 for (i = solv->branches.count - 1; i >= 0; i--)
2803 p = solv->branches.elements[i];
2808 i -= 3; /* skip: p data count */
2817 while (i > 0 && solv->branches.elements[i - 1] > 0)
2819 level = takebranch(solv, i, endi, "branching", disablerules);
2823 /* all branches done, we're finally finished */
2827 /* auto-minimization step */
2828 if (solv->branches.count)
2830 int endi, lasti = -1, lastiend = -1;
2831 if (solv->recommends_index < solv->decisionq.count)
2832 policy_update_recommendsmap(solv);
2833 for (endi = solv->branches.count; endi > 0;)
2835 int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
2836 l = solv->branches.elements[endi - 1];
2837 for (i = starti; i < endi - 4; i++)
2839 p = solv->branches.elements[i];
2842 if (solv->decisionmap[p] > l)
2849 if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2854 /* we have a recommended package that could not be installed */
2855 /* take it if our current selection is not recommended */
2856 for (i = starti; i < endi - 4; i++)
2858 p = -solv->branches.elements[i];
2859 if (p <= 0 || solv->decisionmap[p] != l + 1)
2861 if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2873 minimizationsteps++;
2874 level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
2875 continue; /* back to main loop */
2878 /* no minimization found, we're finally finished! */
2882 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2884 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2890 solv->decisioncnt_jobs = solv->decisionq.count;
2891 solv->decisioncnt_update = solv->decisionq.count;
2892 solv->decisioncnt_keep = solv->decisionq.count;
2893 solv->decisioncnt_resolve = solv->decisionq.count;
2894 solv->decisioncnt_weak = solv->decisionq.count;
2895 solv->decisioncnt_orphan = solv->decisionq.count;
2898 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2903 /*-------------------------------------------------------------------
2905 * remove disabled conflicts
2907 * purpose: update the decisionmap after some rules were disabled.
2908 * this is used to calculate the suggested/recommended package list.
2909 * Also returns a "removed" list to undo the discisionmap changes.
2913 removedisabledconflicts(Solver *solv, Queue *removed)
2915 Pool *pool = solv->pool;
2920 Id *decisionmap = solv->decisionmap;
2922 queue_empty(removed);
2923 for (i = 0; i < solv->decisionq.count; i++)
2925 p = solv->decisionq.elements[i];
2927 continue; /* conflicts only, please */
2928 why = solv->decisionq_why.elements[i];
2931 /* no rule involved, must be a orphan package drop */
2934 /* we never do conflicts on free decisions, so there
2935 * must have been an unit rule */
2937 r = solv->rules + why;
2938 if (r->d < 0 && decisionmap[-p])
2940 /* rule is now disabled, remove from decisionmap */
2941 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2942 queue_push(removed, -p);
2943 queue_push(removed, decisionmap[-p]);
2944 decisionmap[-p] = 0;
2947 if (!removed->count)
2949 /* we removed some confliced packages. some of them might still
2950 * be in conflict, so search for unit rules and re-conflict */
2952 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2954 if (i == solv->nrules)
2957 r = solv->rules + i;
2963 if (r->p < 0 && !decisionmap[-r->p])
2969 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2971 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2976 if (r->p < 0 && decisionmap[-r->p] == 0)
2978 if (new || DECISIONMAP_FALSE(r->p))
2980 dp = pool->whatprovidesdata + r->d;
2981 while ((p = *dp++) != 0)
2983 if (new && p == new)
2985 if (p < 0 && decisionmap[-p] == 0)
2994 else if (!DECISIONMAP_FALSE(p))
3004 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
3005 decisionmap[-new] = -1;
3007 n = 0; /* redo all rules */
3013 undo_removedisabledconflicts(Solver *solv, Queue *removed)
3016 for (i = 0; i < removed->count; i += 2)
3017 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
3021 /*-------------------------------------------------------------------
3023 * weaken solvable dependencies
3027 weaken_solvable_deps(Solver *solv, Id p)
3032 for (i = 1, r = solv->rules + i; i < solv->pkgrules_end; i++, r++)
3036 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3037 continue; /* conflict */
3038 queue_push(&solv->weakruleq, i);
3043 /********************************************************************/
3048 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
3051 Id how, what, select;
3053 for (i = 0; i < job->count; i += 2)
3055 how = job->elements[i];
3056 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
3058 what = job->elements[i + 1];
3059 select = how & SOLVER_SELECTMASK;
3060 if (!multiversionmap->size)
3061 map_grow(multiversionmap, pool->nsolvables);
3062 if (select == SOLVER_SOLVABLE_ALL)
3064 FOR_POOL_SOLVABLES(p)
3065 MAPSET(multiversionmap, p);
3067 else if (select == SOLVER_SOLVABLE_REPO)
3070 Repo *repo = pool_id2repo(pool, what);
3072 FOR_REPO_SOLVABLES(repo, p, s)
3073 MAPSET(multiversionmap, p);
3075 FOR_JOB_SELECT(p, pp, select, what)
3076 MAPSET(multiversionmap, p);
3081 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
3083 solver_calculate_multiversionmap(pool, job, multiversionmap);
3087 * add a rule created by a job, record job number and weak flag
3090 solver_addjobrule(Solver *solv, Id p, Id p2, Id d, Id job, int weak)
3092 solver_addrule(solv, p, p2, d);
3093 queue_push(&solv->ruletojob, job);
3095 queue_push(&solv->weakruleq, solv->nrules - 1);
3099 add_cleandeps_package(Solver *solv, Id p)
3101 if (!solv->cleandeps_updatepkgs)
3103 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3104 queue_init(solv->cleandeps_updatepkgs);
3106 queue_pushunique(solv->cleandeps_updatepkgs, p);
3110 add_update_target(Solver *solv, Id p, Id how)
3112 Pool *pool = solv->pool;
3113 Solvable *s = pool->solvables + p;
3114 Repo *installed = solv->installed;
3116 if (!solv->update_targets)
3118 solv->update_targets = solv_calloc(1, sizeof(Queue));
3119 queue_init(solv->update_targets);
3121 if (s->repo == installed)
3123 queue_push2(solv->update_targets, p, p);
3126 FOR_PROVIDES(pi, pip, s->name)
3128 Solvable *si = pool->solvables + pi;
3129 if (si->repo != installed || si->name != s->name)
3131 if (how & SOLVER_FORCEBEST)
3133 if (!solv->bestupdatemap.size)
3134 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3135 MAPSET(&solv->bestupdatemap, pi - installed->start);
3137 if (how & SOLVER_CLEANDEPS)
3138 add_cleandeps_package(solv, pi);
3139 queue_push2(solv->update_targets, pi, p);
3140 /* check if it's ok to keep the installed package */
3141 if (s->evr == si->evr && solvable_identical(s, si))
3142 queue_push2(solv->update_targets, pi, pi);
3146 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3147 while ((obs = *obsp++) != 0)
3149 FOR_PROVIDES(pi, pip, obs)
3151 Solvable *si = pool->solvables + pi;
3152 if (si->repo != installed)
3154 if (si->name == s->name)
3155 continue; /* already handled above */
3156 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3158 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3160 if (how & SOLVER_FORCEBEST)
3162 if (!solv->bestupdatemap.size)
3163 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3164 MAPSET(&solv->bestupdatemap, pi - installed->start);
3166 if (how & SOLVER_CLEANDEPS)
3167 add_cleandeps_package(solv, pi);
3168 queue_push2(solv->update_targets, pi, p);
3175 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3185 transform_update_targets(Solver *solv)
3187 Repo *installed = solv->installed;
3188 Queue *update_targets = solv->update_targets;
3190 Id p, q, lastp, lastq;
3192 if (!update_targets->count)
3194 queue_free(update_targets);
3195 solv->update_targets = solv_free(update_targets);
3198 if (update_targets->count > 2)
3199 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3200 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3202 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3204 if ((p = update_targets->elements[i]) != lastp)
3206 if (!solv->updatemap.size)
3207 map_grow(&solv->updatemap, installed->end - installed->start);
3208 MAPSET(&solv->updatemap, p - installed->start);
3209 update_targets->elements[j++] = 0; /* finish old set */
3210 update_targets->elements[p - installed->start] = j; /* start new set */
3214 if ((q = update_targets->elements[i + 1]) != lastq)
3216 update_targets->elements[j++] = q;
3220 queue_truncate(update_targets, j);
3221 queue_push(update_targets, 0); /* finish last set */
3226 addedmap2deduceq(Solver *solv, Map *addedmap)
3228 Pool *pool = solv->pool;
3233 queue_empty(&solv->addedmap_deduceq);
3234 for (i = 2, j = solv->pkgrules_end - 1; i < pool->nsolvables && j > 0; j--)
3236 r = solv->rules + j;
3239 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3242 if (!MAPTST(addedmap, p))
3244 /* should never happen, but... */
3245 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3246 queue_push(&solv->addedmap_deduceq, -p);
3250 if (MAPTST(addedmap, i))
3251 queue_push(&solv->addedmap_deduceq, i);
3255 for (; i < pool->nsolvables; i++)
3256 if (MAPTST(addedmap, i))
3257 queue_push(&solv->addedmap_deduceq, i);
3259 for (i = 2; i < pool->nsolvables; i++)
3260 if (MAPTST(addedmap, i))
3265 deduceq2addedmap(Solver *solv, Map *addedmap)
3270 for (j = solv->pkgrules_end - 1; j > 0; j--)
3272 r = solv->rules + j;
3273 if (r->d < 0 && r->p)
3274 solver_enablerule(solv, r);
3277 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3280 MAPSET(addedmap, p);
3282 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3284 p = solv->addedmap_deduceq.elements[j];
3286 MAPSET(addedmap, p);
3288 MAPCLR(addedmap, p);
3292 #ifdef ENABLE_COMPLEX_DEPS
3294 add_complex_jobrules(Solver *solv, Id dep, int flags, int jobidx, int weak)
3296 Pool *pool = solv->pool;
3301 i = pool_normalize_complex_dep(pool, dep, &bq, flags | CPLXDEPS_EXPAND);
3302 if (i == 0 || i == 1)
3306 solver_addjobrule(solv, -SYSTEMSOLVABLE, 0, 0, jobidx, weak);
3309 for (i = 0; i < bq.count; i++)
3311 if (!bq.elements[i])
3313 for (j = 0; bq.elements[i + j + 1]; j++)
3316 solver_addjobrule(solv, bq.elements[i], 0, pool_ids2whatprovides(pool, bq.elements + i + 1, j), jobidx, weak);
3318 solver_addjobrule(solv, bq.elements[i], bq.elements[i + 1], 0, jobidx, weak);
3333 solver_solve(Solver *solv, Queue *job)
3335 Pool *pool = solv->pool;
3336 Repo *installed = solv->installed;
3338 int oldnrules, initialnrules;
3339 Map addedmap; /* '1' == have pkg-rules for solvable */
3340 Map installcandidatemap;
3341 Id how, what, select, name, weak, p, pp, d;
3345 int now, solve_start;
3347 int hasbestinstalljob = 0;
3349 solve_start = solv_timems(0);
3351 /* log solver options */
3352 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3353 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3354 POOL_DEBUG(SOLV_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allownamechange=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allownamechange, solv->allowarchchange, solv->allowvendorchange);
3355 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3356 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3357 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3359 /* create whatprovides if not already there */
3360 if (!pool->whatprovides)
3361 pool_createwhatprovides(pool);
3363 /* create obsolete index */
3364 policy_create_obsolete_index(solv);
3367 queue_free(&solv->job);
3368 queue_init_clone(&solv->job, job);
3369 solv->pooljobcnt = pool->pooljobs.count;
3370 if (pool->pooljobs.count)
3371 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3374 /* free old stuff in jase we re-run a solver */
3375 queuep_free(&solv->update_targets);
3376 queuep_free(&solv->cleandeps_updatepkgs);
3377 queue_empty(&solv->ruleassertions);
3378 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3379 solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
3380 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3381 if (solv->noupdate.size)
3382 map_empty(&solv->noupdate);
3383 map_zerosize(&solv->multiversion);
3384 solv->updatemap_all = 0;
3385 map_zerosize(&solv->updatemap);
3386 solv->bestupdatemap_all = 0;
3387 map_zerosize(&solv->bestupdatemap);
3388 solv->fixmap_all = 0;
3389 map_zerosize(&solv->fixmap);
3390 solv->dupmap_all = 0;
3391 map_zerosize(&solv->dupmap);
3392 map_zerosize(&solv->dupinvolvedmap);
3393 solv->droporphanedmap_all = 0;
3394 map_zerosize(&solv->droporphanedmap);
3395 solv->allowuninstall_all = 0;
3396 map_zerosize(&solv->allowuninstallmap);
3397 map_zerosize(&solv->cleandepsmap);
3398 map_zerosize(&solv->weakrulemap);
3399 queue_empty(&solv->weakruleq);
3400 solv->watches = solv_free(solv->watches);
3401 queue_empty(&solv->ruletojob);
3402 if (solv->decisionq.count)
3403 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3404 queue_empty(&solv->decisionq);
3405 queue_empty(&solv->decisionq_why);
3406 solv->decisioncnt_jobs = solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3407 queue_empty(&solv->learnt_why);
3408 queue_empty(&solv->learnt_pool);
3409 queue_empty(&solv->branches);
3410 solv->propagate_index = 0;
3411 queue_empty(&solv->problems);
3412 queue_empty(&solv->solutions);
3413 queue_empty(&solv->orphaned);
3414 solv->stats_learned = solv->stats_unsolvable = 0;
3415 if (solv->recommends_index)
3417 map_empty(&solv->recommendsmap);
3418 map_empty(&solv->suggestsmap);
3419 queuep_free(&solv->recommendscplxq);
3420 queuep_free(&solv->suggestscplxq);
3421 solv->recommends_index = 0;
3423 queuep_free(&solv->brokenorphanrules);
3424 solv->specialupdaters = solv_free(solv->specialupdaters);
3428 * create basic rule set of all involved packages
3429 * use addedmap bitmap to make sure we don't create rules twice
3432 /* create multiversion map if needed */
3433 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3435 map_init(&addedmap, pool->nsolvables);
3436 MAPSET(&addedmap, SYSTEMSOLVABLE);
3438 map_init(&installcandidatemap, pool->nsolvables);
3441 now = solv_timems(0);
3443 * create rules for all package that could be involved with the solving
3444 * so called: pkg rules
3447 initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
3448 if (initialnrules > 1)
3449 deduceq2addedmap(solv, &addedmap);
3450 if (solv->nrules != initialnrules)
3451 solver_shrinkrules(solv, initialnrules);
3452 solv->nrules = initialnrules;
3453 solv->pkgrules_end = 0;
3457 /* check for update/verify jobs as they need to be known early */
3458 /* also setup the droporphaned map, we need it when creating update rules */
3459 for (i = 0; i < job->count; i += 2)
3461 how = job->elements[i];
3462 what = job->elements[i + 1];
3463 select = how & SOLVER_SELECTMASK;
3464 switch (how & SOLVER_JOBMASK)
3467 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3468 solv->fixmap_all = 1;
3469 FOR_JOB_SELECT(p, pp, select, what)
3471 s = pool->solvables + p;
3472 if (s->repo != installed)
3474 if (!solv->fixmap.size)
3475 map_grow(&solv->fixmap, installed->end - installed->start);
3476 MAPSET(&solv->fixmap, p - installed->start);
3480 if (select == SOLVER_SOLVABLE_ALL)
3482 solv->updatemap_all = 1;
3483 if (how & SOLVER_FORCEBEST)
3484 solv->bestupdatemap_all = 1;
3485 if (how & SOLVER_CLEANDEPS)
3487 FOR_REPO_SOLVABLES(installed, p, s)
3488 add_cleandeps_package(solv, p);
3491 else if (select == SOLVER_SOLVABLE_REPO)
3493 Repo *repo = pool_id2repo(pool, what);
3496 if (repo == installed && !(how & SOLVER_TARGETED))
3498 solv->updatemap_all = 1;
3499 if (how & SOLVER_FORCEBEST)
3500 solv->bestupdatemap_all = 1;
3501 if (how & SOLVER_CLEANDEPS)
3503 FOR_REPO_SOLVABLES(installed, p, s)
3504 add_cleandeps_package(solv, p);
3508 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3510 /* targeted update */
3511 FOR_REPO_SOLVABLES(repo, p, s)
3512 add_update_target(solv, p, how);
3516 if (!(how & SOLVER_TARGETED))
3519 FOR_JOB_SELECT(p, pp, select, what)
3521 s = pool->solvables + p;
3522 if (s->repo != installed)
3524 if (!solv->updatemap.size)
3525 map_grow(&solv->updatemap, installed->end - installed->start);
3526 MAPSET(&solv->updatemap, p - installed->start);
3527 if (how & SOLVER_FORCEBEST)
3529 if (!solv->bestupdatemap.size)
3530 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3531 MAPSET(&solv->bestupdatemap, p - installed->start);
3533 if (how & SOLVER_CLEANDEPS)
3534 add_cleandeps_package(solv, p);
3537 if (!targeted || solv->noautotarget)
3540 FOR_JOB_SELECT(p, pp, select, what)
3541 add_update_target(solv, p, how);
3544 case SOLVER_DROP_ORPHANED:
3545 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3546 solv->droporphanedmap_all = 1;
3547 FOR_JOB_SELECT(p, pp, select, what)
3549 s = pool->solvables + p;
3550 if (s->repo != installed)
3552 if (!solv->droporphanedmap.size)
3553 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3554 MAPSET(&solv->droporphanedmap, p - installed->start);
3562 if (solv->update_targets)
3563 transform_update_targets(solv);
3565 oldnrules = solv->nrules;
3566 FOR_REPO_SOLVABLES(installed, p, s)
3567 solver_addpkgrulesforsolvable(solv, s, &addedmap);
3568 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for installed solvables\n", solv->nrules - oldnrules);
3569 oldnrules = solv->nrules;
3570 FOR_REPO_SOLVABLES(installed, p, s)
3571 solver_addpkgrulesforupdaters(solv, s, &addedmap, 1);
3572 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3576 * create rules for all packages involved in the job
3577 * (to be installed or removed)
3580 oldnrules = solv->nrules;
3581 for (i = 0; i < job->count; i += 2)
3583 how = job->elements[i];
3584 what = job->elements[i + 1];
3585 select = how & SOLVER_SELECTMASK;
3587 switch (how & SOLVER_JOBMASK)
3589 case SOLVER_INSTALL:
3590 FOR_JOB_SELECT(p, pp, select, what)
3592 MAPSET(&installcandidatemap, p);
3593 solver_addpkgrulesforsolvable(solv, pool->solvables + p, &addedmap);
3596 case SOLVER_DISTUPGRADE:
3597 if (select == SOLVER_SOLVABLE_ALL)
3599 solv->dupmap_all = 1;
3600 solv->updatemap_all = 1;
3601 if (how & SOLVER_FORCEBEST)
3602 solv->bestupdatemap_all = 1;
3604 if (!solv->dupmap_all || solv->allowuninstall)
3611 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for packages involved in a job\n", solv->nrules - oldnrules);
3615 * add rules for suggests, enhances
3617 oldnrules = solv->nrules;
3618 solver_addpkgrulesforweak(solv, &addedmap);
3619 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
3621 #ifdef ENABLE_LINKED_PKGS
3622 oldnrules = solv->nrules;
3623 solver_addpkgrulesforlinked(solv, &addedmap);
3624 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of linked packages\n", solv->nrules - oldnrules);
3628 * first pass done, we now have all the pkg rules we need.
3629 * unify existing rules before going over all job rules and
3631 * at this point the system is always solvable,
3632 * as an empty system (remove all packages) is a valid solution
3635 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3637 int possible = 0, installable = 0;
3638 for (i = 1; i < pool->nsolvables; i++)
3640 if (pool_installable(pool, pool->solvables + i))
3642 if (MAPTST(&addedmap, i))
3645 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3648 if (solv->nrules > initialnrules)
3649 solver_unifyrules(solv); /* remove duplicate pkg rules */
3650 solv->pkgrules_end = solv->nrules; /* mark end of pkg rules */
3652 if (solv->nrules > initialnrules)
3653 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3655 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3656 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule creation took %d ms\n", solv_timems(now));
3658 /* create dup maps if needed. We need the maps early to create our
3661 solver_createdupmaps(solv);
3664 * create feature rules
3666 * foreach installed:
3667 * create assertion (keep installed, if no update available)
3669 * create update rule (A|update1(A)|update2(A)|...)
3671 * those are used later on to keep a version of the installed packages in
3675 solv->featurerules = solv->nrules; /* mark start of feature rules */
3678 /* foreach possibly installed solvable */
3679 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3681 if (s->repo != installed)
3683 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3686 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3688 /* make sure we accounted for all rules */
3689 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3691 solv->featurerules_end = solv->nrules;
3694 * Add update rules for installed solvables
3696 * almost identical to feature rules
3697 * except that downgrades/archchanges/vendorchanges are not allowed
3700 solv->updaterules = solv->nrules;
3703 { /* foreach installed solvables */
3704 /* we create all update rules, but disable some later on depending on the job */
3705 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3709 if (s->repo != installed)
3711 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3714 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3716 * check for and remove duplicate
3718 r = solv->rules + solv->nrules - 1; /* r: update rule */
3721 sr = r - (installed->end - installed->start); /* sr: feature rule */
3722 /* it's also orphaned if the feature rule consists just of the installed package */
3723 if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
3724 queue_push(&solv->orphaned, i);
3725 if (!solver_rulecmp(solv, r, sr))
3726 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3728 solver_disablerule(solv, sr); /* disable feature rule for now */
3730 /* consistency check: we added a rule for _every_ installed solvable */
3731 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3733 solv->updaterules_end = solv->nrules;
3737 * now add all job rules
3740 solv->jobrules = solv->nrules;
3741 for (i = 0; i < job->count; i += 2)
3743 oldnrules = solv->nrules;
3745 if (i && i == solv->pooljobcnt)
3746 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3747 how = job->elements[i];
3748 what = job->elements[i + 1];
3749 weak = how & SOLVER_WEAK;
3750 select = how & SOLVER_SELECTMASK;
3751 switch (how & SOLVER_JOBMASK)
3753 case SOLVER_INSTALL:
3754 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3755 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3756 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3757 if (select == SOLVER_SOLVABLE)
3762 #ifdef ENABLE_COMPLEX_DEPS
3763 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3765 if (add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? CPLXDEPS_NAME : 0, i, weak))
3766 if (how & SOLVER_FORCEBEST)
3767 hasbestinstalljob = 1;
3774 FOR_JOB_SELECT(p, pp, select, what)
3778 if (select == SOLVER_SOLVABLE_ONE_OF)
3779 break; /* ignore empty installs */
3780 /* no candidate found or unsupported, make this an impossible rule */
3781 queue_push(&q, -SYSTEMSOLVABLE);
3783 p = queue_shift(&q); /* get first candidate */
3784 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3786 /* force install of namespace supplements hack */
3787 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3789 Reldep *rd = GETRELDEP(pool, what);
3790 if (rd->flags == REL_NAMESPACE)
3793 if (!solv->installsuppdepq)
3795 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3796 queue_init(solv->installsuppdepq);
3798 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3801 solver_addjobrule(solv, p, 0, d, i, weak);
3802 if (how & SOLVER_FORCEBEST)
3803 hasbestinstalljob = 1;
3806 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3807 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3808 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3809 /* specific solvable: by id or by nevra */
3810 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3811 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3813 FOR_POOL_SOLVABLES(p)
3814 solver_addjobrule(solv, -p, 0, 0, i, weak);
3816 else if (select == SOLVER_SOLVABLE_REPO)
3818 Repo *repo = pool_id2repo(pool, what);
3820 FOR_REPO_SOLVABLES(repo, p, s)
3821 solver_addjobrule(solv, -p, 0, 0, i, weak);
3823 #ifdef ENABLE_COMPLEX_DEPS
3824 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3826 /* no special "erase a specific solvable" handling? */
3827 add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? (CPLXDEPS_NAME | CPLXDEPS_TODNF | CPLXDEPS_INVERT) : (CPLXDEPS_TODNF | CPLXDEPS_INVERT), i, weak);
3831 FOR_JOB_SELECT(p, pp, select, what)
3833 s = pool->solvables + p;
3834 if (installed && s->repo == installed)
3835 name = !name ? s->name : -1;
3836 solver_addjobrule(solv, -p, 0, 0, i, weak);
3838 /* special case for "erase a specific solvable": we also
3839 * erase all other solvables with that name, so that they
3840 * don't get picked up as replacement.
3841 * name is > 0 if exactly one installed solvable matched.
3843 /* XXX: look also at packages that obsolete this package? */
3848 FOR_PROVIDES(p, pp, name)
3850 s = pool->solvables + p;
3851 if (s->name != name)
3853 /* keep other versions installed */
3854 if (s->repo == installed)
3856 /* keep installcandidates of other jobs */
3857 if (MAPTST(&installcandidatemap, p))
3859 /* don't add the same rule twice */
3860 for (j = oldnrules; j < k; j++)
3861 if (solv->rules[j].p == -p)
3864 solver_addjobrule(solv, -p, 0, 0, i, weak); /* remove by id */
3870 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3873 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3875 case SOLVER_WEAKENDEPS:
3876 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3877 if (select != SOLVER_SOLVABLE)
3879 s = pool->solvables + what;
3880 weaken_solvable_deps(solv, what);
3882 case SOLVER_MULTIVERSION:
3883 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3886 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3887 if (select == SOLVER_SOLVABLE_ALL)
3889 FOR_POOL_SOLVABLES(p)
3890 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3892 else if (select == SOLVER_SOLVABLE_REPO)
3894 Repo *repo = pool_id2repo(pool, what);
3896 FOR_REPO_SOLVABLES(repo, p, s)
3897 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3899 FOR_JOB_SELECT(p, pp, select, what)
3900 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3902 case SOLVER_DISTUPGRADE:
3903 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3905 case SOLVER_DROP_ORPHANED:
3906 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3908 case SOLVER_USERINSTALLED:
3909 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3911 case SOLVER_ALLOWUNINSTALL:
3912 POOL_DEBUG(SOLV_DEBUG_JOB, "job: allowuninstall %s\n", solver_select2str(pool, select, what));
3913 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3914 solv->allowuninstall_all = 1;
3915 FOR_JOB_SELECT(p, pp, select, what)
3917 s = pool->solvables + p;
3918 if (s->repo != installed)
3920 if (!solv->allowuninstallmap.size)
3921 map_grow(&solv->allowuninstallmap, installed->end - installed->start);
3922 MAPSET(&solv->allowuninstallmap, p - installed->start);
3926 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3930 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3933 if (solv->nrules == oldnrules)
3934 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3935 for (j = oldnrules; j < solv->nrules; j++)
3937 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3938 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3942 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3943 solv->jobrules_end = solv->nrules;
3945 /* now create infarch and dup rules */
3946 if (!solv->noinfarchcheck)
3948 solver_addinfarchrules(solv, &addedmap);
3950 if (pool->implicitobsoleteusescolors)
3952 /* currently doesn't work well with infarch rules, so make
3954 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3955 queue_push(&solv->weakruleq, i);
3960 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3963 solver_addduprules(solv, &addedmap);
3965 solv->duprules = solv->duprules_end = solv->nrules;
3967 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3968 solver_addbestrules(solv, hasbestinstalljob);
3970 solv->bestrules = solv->bestrules_end = solv->nrules;
3973 solver_freedupmaps(solv); /* no longer needed */
3975 if (solv->do_yum_obsoletes)
3976 solver_addyumobsrules(solv);
3978 solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
3981 solver_addchoicerules(solv);
3983 solv->choicerules = solv->choicerules_end = solv->nrules;
3987 for (i = solv->featurerules; i < solv->nrules; i++)
3988 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3990 /* all rules created
3991 * --------------------------------------------------------------
3992 * prepare for solving
3995 /* free unneeded memory */
3996 map_free(&addedmap);
3997 map_free(&installcandidatemap);
4000 POOL_DEBUG(SOLV_DEBUG_STATS, "%d pkg rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->pkgrules_end - 1, solv->updaterules_end - solv->updaterules, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules, solv->choicerules_end - solv->choicerules, solv->bestrules_end - solv->bestrules);
4001 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4003 /* create weak map */
4004 if (solv->weakruleq.count)
4006 map_grow(&solv->weakrulemap, solv->nrules);
4007 for (i = 0; i < solv->weakruleq.count; i++)
4009 p = solv->weakruleq.elements[i];
4010 MAPSET(&solv->weakrulemap, p);
4014 /* enable cleandepsmap creation if we have updatepkgs */
4015 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
4016 map_grow(&solv->cleandepsmap, installed->end - installed->start);
4018 if (solv->cleandeps_mistakes)
4020 queue_free(solv->cleandeps_mistakes);
4021 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
4024 /* all new rules are learnt after this point */
4025 solv->learntrules = solv->nrules;
4027 /* create watches chains */
4030 /* create assertion index. it is only used to speed up
4031 * makeruledecsions() a bit */
4032 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4033 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4034 queue_push(&solv->ruleassertions, i);
4036 /* disable update rules that conflict with our job */
4037 solver_disablepolicyrules(solv);
4039 /* break orphans if requested */
4040 if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
4041 solver_breakorphans(solv);
4044 * ********************************************
4046 * ********************************************
4049 now = solv_timems(0);
4050 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4051 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
4054 * prepare solution queue if there were problems
4056 solver_prepare_solutions(solv);
4058 POOL_DEBUG(SOLV_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
4059 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
4061 /* return number of problems */
4062 return solv->problems.count ? solv->problems.count / 2 : 0;
4066 solver_create_transaction(Solver *solv)
4068 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
4071 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
4073 queue_free(orphanedq);
4074 queue_init_clone(orphanedq, &solv->orphaned);
4077 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
4079 Pool *pool = solv->pool;
4080 Queue redoq, disabledq;
4086 if (!recommendationsq && !suggestionsq)
4089 map_init(&obsmap, pool->nsolvables);
4090 if (solv->installed)
4092 Id obs, *obsp, p, po, ppo;
4093 for (p = solv->installed->start; p < solv->installed->end; p++)
4095 s = pool->solvables + p;
4096 if (s->repo != solv->installed || !s->obsoletes)
4098 if (solv->decisionmap[p] <= 0)
4100 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
4102 obsp = s->repo->idarraydata + s->obsoletes;
4103 /* foreach obsoletes */
4104 while ((obs = *obsp++) != 0)
4105 FOR_PROVIDES(po, ppo, obs)
4106 MAPSET(&obsmap, po);
4111 queue_init(&disabledq);
4113 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4114 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4116 if (r->d < 0) /* disabled ? */
4118 if (r->p >= 0) /* install job? */
4120 queue_push(&disabledq, i);
4121 solver_disablerule(solv, r);
4127 enabledisablelearntrules(solv);
4128 removedisabledconflicts(solv, &redoq);
4132 * find recommended packages
4134 if (recommendationsq)
4136 Id rec, *recp, p, pp;
4138 queue_empty(recommendationsq);
4139 /* create map of all recommened packages */
4140 solv->recommends_index = -1;
4141 MAPZERO(&solv->recommendsmap);
4143 /* put all packages the solver already chose in the map */
4144 if (solv->decisioncnt_weak)
4146 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
4149 why = solv->decisionq_why.elements[i];
4151 continue; /* forced by unit rule or dep resolving */
4152 p = solv->decisionq.elements[i];
4155 MAPSET(&solv->recommendsmap, p);
4159 for (i = 0; i < solv->decisionq.count; i++)
4161 p = solv->decisionq.elements[i];
4164 s = pool->solvables + p;
4167 recp = s->repo->idarraydata + s->recommends;
4168 while ((rec = *recp++) != 0)
4170 #ifdef ENABLE_COMPLEX_DEPS
4171 if (pool_is_complex_dep(pool, rec))
4173 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4177 FOR_PROVIDES(p, pp, rec)
4178 if (solv->decisionmap[p] > 0)
4184 FOR_PROVIDES(p, pp, rec)
4185 if (solv->decisionmap[p] > 0)
4186 MAPSET(&solv->recommendsmap, p);
4188 continue; /* p != 0: already fulfilled */
4190 FOR_PROVIDES(p, pp, rec)
4191 MAPSET(&solv->recommendsmap, p);
4195 for (i = 1; i < pool->nsolvables; i++)
4197 if (solv->decisionmap[i] < 0)
4199 if (solv->decisionmap[i] > 0 && noselected)
4201 if (MAPTST(&obsmap, i))
4203 s = pool->solvables + i;
4204 if (!MAPTST(&solv->recommendsmap, i))
4206 if (!s->supplements)
4208 if (!pool_installable(pool, s))
4210 if (!solver_is_supplementing(solv, s))
4213 queue_push(recommendationsq, i);
4215 /* we use MODE_SUGGEST here so that repo prio is ignored */
4216 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4220 * find suggested packages
4225 Id sug, *sugp, p, pp;
4227 queue_empty(suggestionsq);
4228 /* create map of all suggests that are still open */
4229 solv->recommends_index = -1;
4230 MAPZERO(&solv->suggestsmap);
4231 for (i = 0; i < solv->decisionq.count; i++)
4233 p = solv->decisionq.elements[i];
4236 s = pool->solvables + p;
4239 sugp = s->repo->idarraydata + s->suggests;
4240 while ((sug = *sugp++) != 0)
4242 #ifdef ENABLE_COMPLEX_DEPS
4243 if (pool_is_complex_dep(pool, sug))
4245 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4249 FOR_PROVIDES(p, pp, sug)
4250 if (solv->decisionmap[p] > 0)
4256 FOR_PROVIDES(p, pp, sug)
4257 if (solv->decisionmap[p] > 0)
4258 MAPSET(&solv->suggestsmap, p);
4260 continue; /* already fulfilled */
4262 FOR_PROVIDES(p, pp, sug)
4263 MAPSET(&solv->suggestsmap, p);
4267 for (i = 1; i < pool->nsolvables; i++)
4269 if (solv->decisionmap[i] < 0)
4271 if (solv->decisionmap[i] > 0 && noselected)
4273 if (MAPTST(&obsmap, i))
4275 s = pool->solvables + i;
4276 if (!MAPTST(&solv->suggestsmap, i))
4280 if (!pool_installable(pool, s))
4282 if (!solver_is_enhancing(solv, s))
4285 queue_push(suggestionsq, i);
4287 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4290 /* undo removedisabledconflicts */
4292 undo_removedisabledconflicts(solv, &redoq);
4295 /* undo job rule disabling */
4296 for (i = 0; i < disabledq.count; i++)
4297 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4298 queue_free(&disabledq);
4303 /***********************************************************************/
4304 /* disk usage computations */
4306 /*-------------------------------------------------------------------
4308 * calculate DU changes
4312 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4316 solver_create_state_maps(solv, &installedmap, 0);
4317 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4318 map_free(&installedmap);
4322 /*-------------------------------------------------------------------
4324 * calculate changes in install size
4328 solver_calc_installsizechange(Solver *solv)
4333 solver_create_state_maps(solv, &installedmap, 0);
4334 change = pool_calc_installsizechange(solv->pool, &installedmap);
4335 map_free(&installedmap);
4340 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4342 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4346 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4348 Pool *pool = solv->pool;
4351 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4352 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4353 for (i = 0; i < res->count; i++)
4354 if (res->elements[i] != -1)
4356 Solvable *s = pool->solvables + pkgs->elements[i];
4357 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4358 res->elements[i] = -1;
4360 map_free(&installedmap);
4363 /*-------------------------------------------------------------------
4365 * decision introspection
4369 solver_get_decisionlevel(Solver *solv, Id p)
4371 return solv->decisionmap[p];
4375 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4377 queue_free(decisionq);
4378 queue_init_clone(decisionq, &solv->decisionq);
4382 solver_get_lastdecisionblocklevel(Solver *solv)
4385 if (solv->decisionq.count == 0)
4387 p = solv->decisionq.elements[solv->decisionq.count - 1];
4390 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4394 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4399 queue_empty(decisionq);
4400 for (i = 0; i < solv->decisionq.count; i++)
4402 p = solv->decisionq.elements[i];
4405 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4408 if (i == solv->decisionq.count)
4410 for (i = 0; i < solv->decisionq.count; i++)
4412 p = solv->decisionq.elements[i];
4415 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4416 queue_push(decisionq, p);
4423 solver_describe_decision(Solver *solv, Id p, Id *infop)
4430 if (!solv->decisionmap[p])
4431 return SOLVER_REASON_UNRELATED;
4432 pp = solv->decisionmap[p] < 0 ? -p : p;
4433 for (i = 0; i < solv->decisionq.count; i++)
4434 if (solv->decisionq.elements[i] == pp)
4436 if (i == solv->decisionq.count) /* just in case... */
4437 return SOLVER_REASON_UNRELATED;
4438 why = solv->decisionq_why.elements[i];
4440 *infop = why > 0 ? why : -why;
4442 return SOLVER_REASON_UNIT_RULE;
4445 return SOLVER_REASON_KEEP_INSTALLED; /* the systemsolvable */
4446 if (i < solv->decisioncnt_update)
4447 return SOLVER_REASON_RESOLVE_JOB;
4448 if (i < solv->decisioncnt_keep)
4450 if (why == 0 && pp < 0)
4451 return SOLVER_REASON_CLEANDEPS_ERASE;
4452 return SOLVER_REASON_UPDATE_INSTALLED;
4454 if (i < solv->decisioncnt_resolve)
4456 if (solv->focus_installed && i >= solv->decisioncnt_jobs)
4457 return SOLVER_REASON_RESOLVE_JOB;
4458 if (why == 0 && pp < 0)
4459 return SOLVER_REASON_CLEANDEPS_ERASE;
4460 return SOLVER_REASON_KEEP_INSTALLED;
4463 return SOLVER_REASON_RESOLVE;
4464 /* weak or orphaned */
4465 if (i < solv->decisioncnt_orphan)
4466 return SOLVER_REASON_WEAKDEP;
4467 return SOLVER_REASON_RESOLVE_ORPHAN;
4472 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4474 Pool *pool = solv->pool;
4476 int level = solv->decisionmap[p];
4483 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4484 if (solv->decisionq.elements[decisionno] == p)
4486 if (decisionno == solv->decisionq.count)
4488 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4491 /* 1) list all packages that recommend us */
4492 for (i = 1; i < pool->nsolvables; i++)
4494 Id *recp, rec, pp2, p2;
4495 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4497 s = pool->solvables + i;
4500 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4502 recp = s->repo->idarraydata + s->recommends;
4503 while ((rec = *recp++) != 0)
4506 FOR_PROVIDES(p2, pp2, rec)
4512 /* if p2 is already installed, this recommends is ignored */
4513 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4519 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4520 queue_push2(whyq, i, rec);
4524 /* 2) list all supplements */
4525 s = pool->solvables + p;
4526 if (s->supplements && level > 0)
4528 Id *supp, sup, pp2, p2;
4529 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4530 * everything above our level in the decisionmap */
4531 for (i = decisionno; i < solv->decisionq.count; i++ )
4533 p2 = solv->decisionq.elements[i];
4535 solv->decisionmap[p2] = -solv->decisionmap[p2];
4537 supp = s->repo->idarraydata + s->supplements;
4538 while ((sup = *supp++) != 0)
4539 if (solver_dep_fulfilled(solv, sup))
4542 /* let's see if this is an easy supp */
4543 FOR_PROVIDES(p2, pp2, sup)
4545 if (!solv->addalreadyrecommended && solv->installed)
4547 if (pool->solvables[p2].repo == solv->installed)
4550 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4552 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4553 queue_push2(whyq, p2, sup);
4559 /* hard case, just note dependency with no package */
4560 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4561 queue_push2(whyq, 0, sup);
4564 for (i = decisionno; i < solv->decisionq.count; i++)
4566 p2 = solv->decisionq.elements[i];
4568 solv->decisionmap[p2] = -solv->decisionmap[p2];
4574 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4577 how &= SOLVER_SELECTMASK;
4579 if (how == SOLVER_SOLVABLE_ALL)
4581 FOR_POOL_SOLVABLES(p)
4582 queue_push(pkgs, p);
4584 else if (how == SOLVER_SOLVABLE_REPO)
4586 Repo *repo = pool_id2repo(pool, what);
4589 FOR_REPO_SOLVABLES(repo, p, s)
4590 queue_push(pkgs, p);
4594 FOR_JOB_SELECT(p, pp, how, what)
4595 queue_push(pkgs, p);
4600 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4603 Id select = how & SOLVER_SELECTMASK;
4604 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4606 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4608 if (!pool->installed)
4610 FOR_JOB_SELECT(p, pp, select, what)
4611 if (pool->solvables[p].repo == pool->installed)
4614 FOR_JOB_SELECT(p, pp, select, what)
4616 Solvable *s = pool->solvables + p;
4617 FOR_PROVIDES(pi, pip, s->name)
4619 Solvable *si = pool->solvables + pi;
4620 if (si->repo != pool->installed || si->name != s->name)
4626 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4627 while ((obs = *obsp++) != 0)
4629 FOR_PROVIDES(pi, pip, obs)
4631 Solvable *si = pool->solvables + pi;
4632 if (si->repo != pool->installed)
4634 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4636 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4647 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4649 return *(Id *)ap - *(Id *)bp;
4653 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4656 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4660 get_userinstalled_cmp_namearch(const void *ap, const void *bp, void *dp)
4664 r = strcmp(pool_id2str(pool, ((Id *)ap)[0]), pool_id2str(pool, ((Id *)bp)[0]));
4667 return strcmp(pool_id2str(pool, ((Id *)ap)[1]), pool_id2str(pool, ((Id *)bp)[1]));
4671 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4673 Id lastp = -1, lasta = -1;
4675 if (q->count < ((flags & GET_USERINSTALLED_NAMEARCH) ? 4 : 2))
4677 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4678 solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), get_userinstalled_cmp_namearch, pool);
4679 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4680 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4682 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4683 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4685 for (i = j = 0; i < q->count; i += 2)
4686 if (q->elements[i] != lastp || q->elements[i + 1] != lasta)
4688 q->elements[j++] = lastp = q->elements[i];
4689 q->elements[j++] = lasta = q->elements[i + 1];
4694 for (i = j = 0; i < q->count; i++)
4695 if (q->elements[i] != lastp)
4696 q->elements[j++] = lastp = q->elements[i];
4698 queue_truncate(q, j);
4702 namearch2solvables(Pool *pool, Queue *q, Queue *qout, int job)
4705 if (!pool->installed)
4707 for (i = 0; i < q->count; i += 2)
4709 Id p, pp, name = q->elements[i], arch = q->elements[i + 1];
4710 FOR_PROVIDES(p, pp, name)
4712 Solvable *s = pool->solvables + p;
4713 if (s->repo != pool->installed || s->name != name || (arch && s->arch != arch))
4716 queue_push(qout, job);
4717 queue_push(qout, p);
4723 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4725 Pool *pool = solv->pool;
4728 Repo *installed = solv->installed;
4732 map_init(&userinstalled, 0);
4734 /* first process jobs */
4735 for (i = 0; i < solv->job.count; i += 2)
4737 Id how = solv->job.elements[i];
4739 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4741 if (!userinstalled.size)
4742 map_grow(&userinstalled, installed->end - installed->start);
4743 what = solv->job.elements[i + 1];
4744 select = how & SOLVER_SELECTMASK;
4745 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4746 FOR_REPO_SOLVABLES(installed, p, s)
4747 MAPSET(&userinstalled, p - installed->start);
4748 FOR_JOB_SELECT(p, pp, select, what)
4749 if (pool->solvables[p].repo == installed)
4750 MAPSET(&userinstalled, p - installed->start);
4753 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4755 if ((how & SOLVER_NOTBYUSER) != 0)
4757 what = solv->job.elements[i + 1];
4758 select = how & SOLVER_SELECTMASK;
4759 FOR_JOB_SELECT(p, pp, select, what)
4760 if (solv->decisionmap[p] > 0)
4763 #ifdef ENABLE_LINKED_PKGS
4764 if (has_package_link(pool, pool->solvables + p))
4769 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4770 for (j = 0; j < lq.count; j++)
4771 if (solv->decisionmap[lq.elements[j]] > 0)
4772 queue_push(q, lq.elements[j]);
4777 /* now process updates of userinstalled packages */
4778 if (installed && userinstalled.size)
4780 for (i = 1; i < solv->decisionq.count; i++)
4782 p = solv->decisionq.elements[i];
4785 s = pool->solvables + p;
4788 if (s->repo == installed)
4790 if (MAPTST(&userinstalled, p - installed->start))
4794 /* new package, check if we replace a userinstalled one */
4795 FOR_PROVIDES(p2, pp, s->name)
4797 Solvable *ps = pool->solvables + p2;
4798 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4800 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
4802 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
4807 if (!p2 && s->repo != installed && s->obsoletes)
4809 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4810 while ((obs = *obsp++) != 0)
4812 FOR_PROVIDES(p2, pp, obs)
4814 Solvable *ps = pool->solvables + p2;
4815 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4817 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
4819 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
4830 map_free(&userinstalled);
4832 /* convert to desired output format */
4833 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4835 int qcount = q->count;
4836 queue_insertn(q, 0, qcount, 0);
4837 for (i = j = 0; i < qcount; i++)
4839 s = pool->solvables + q->elements[i + qcount];
4840 q->elements[j++] = s->name;
4841 q->elements[j++] = s->arch;
4844 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4846 for (i = 0; i < q->count; i++)
4848 s = pool->solvables + q->elements[i];
4849 q->elements[i] = s->name;
4852 /* sort and unify */
4853 get_userinstalled_sort_uniq(pool, q, flags);
4855 /* invert if asked for */
4856 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4858 /* first generate queue with all installed packages */
4861 for (i = 1; i < solv->decisionq.count; i++)
4863 p = solv->decisionq.elements[i];
4866 s = pool->solvables + p;
4869 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4870 queue_push2(&invq, s->name, s->arch);
4871 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4872 queue_push(&invq, s->name);
4874 queue_push(&invq, p);
4876 /* push q on invq, just in case... */
4877 queue_insertn(&invq, invq.count, q->count, q->elements);
4878 get_userinstalled_sort_uniq(pool, &invq, flags);
4879 /* subtract queues (easy as they are sorted and invq is a superset of q) */
4880 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4884 for (i = j = 0; i < invq.count; i += 2)
4885 if (invq.elements[i] == q->elements[j] && invq.elements[i + 1] == q->elements[j + 1])
4887 invq.elements[i] = invq.elements[i + 1] = 0;
4894 for (i = 0; i < invq.count; i += 2)
4895 if (invq.elements[i])
4896 queue_push2(q, invq.elements[i], invq.elements[i + 1]);
4902 for (i = j = 0; i < invq.count; i++)
4903 if (invq.elements[i] == q->elements[j])
4905 invq.elements[i] = 0;
4906 if (++j >= q->count)
4911 for (i = 0; i < invq.count; i++)
4912 if (invq.elements[i])
4913 queue_push(q, invq.elements[i]);
4920 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
4924 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4930 if (!pool->installed)
4933 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4934 flags &= ~GET_USERINSTALLED_NAMES; /* just in case */
4935 FOR_REPO_SOLVABLES(pool->installed, p, s)
4936 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
4937 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4939 /* for namearch we convert to packages */
4940 namearch2solvables(pool, q, &invq, 0);
4941 get_userinstalled_sort_uniq(pool, &invq, flags);
4942 namearch2solvables(pool, q, &invq, 0);
4947 queue_insertn(&invq, invq.count, q->count, q->elements);
4948 get_userinstalled_sort_uniq(pool, &invq, flags);
4949 /* now the fun part, add q again, sort, and remove all dups */
4950 queue_insertn(&invq, invq.count, q->count, q->elements);
4954 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4955 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
4957 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
4961 for (i = 0; i < invq.count; i++)
4963 if (invq.elements[i] == lastid)
4969 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4971 lastid = invq.elements[i];
4974 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4979 if (flags & GET_USERINSTALLED_NAMEARCH)
4980 namearch2solvables(pool, q, job, SOLVER_USERINSTALLED | SOLVER_SOLVABLE);
4983 for (i = 0; i < q->count; i++)
4984 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
4990 solver_alternatives_count(Solver *solv)
4992 Id *elements = solv->branches.elements;
4994 for (res = 0, count = solv->branches.count; count; res++)
4995 count -= elements[count - 2];
5000 solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
5002 int cnt = solver_alternatives_count(solv);
5003 int count = solv->branches.count;
5004 Id *elements = solv->branches.elements;
5006 queue_empty(choices);
5007 if (alternative <= 0 || alternative > cnt)
5010 for (; cnt > alternative; cnt--)
5011 elements -= elements[-2];
5013 *levelp = elements[-1];
5015 *fromp = elements[-4];
5017 *idp = elements[-3];
5022 for (i = elements[-2]; i > 4; i--)
5024 Id p = -elements[-i];
5025 if (p > 0 && solv->decisionmap[p] == elements[-1] + 1)
5033 queue_insertn(choices, 0, elements[-2] - 4, elements - elements[-2]);
5034 return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE;
5038 solver_select2str(Pool *pool, Id select, Id what)
5042 select &= SOLVER_SELECTMASK;
5043 if (select == SOLVER_SOLVABLE)
5044 return pool_solvid2str(pool, what);
5045 if (select == SOLVER_SOLVABLE_NAME)
5046 return pool_dep2str(pool, what);
5047 if (select == SOLVER_SOLVABLE_PROVIDES)
5049 s = pool_dep2str(pool, what);
5050 b = pool_alloctmpspace(pool, 11 + strlen(s));
5051 sprintf(b, "providing %s", s);
5054 if (select == SOLVER_SOLVABLE_ONE_OF)
5058 while ((p = pool->whatprovidesdata[what++]) != 0)
5060 s = pool_solvid2str(pool, p);
5062 b = pool_tmpappend(pool, b, ", ", s);
5064 b = pool_tmpjoin(pool, s, 0, 0);
5065 pool_freetmpspace(pool, s);
5067 return b ? b : "nothing";
5069 if (select == SOLVER_SOLVABLE_REPO)
5071 b = pool_alloctmpspace(pool, 20);
5072 sprintf(b, "repo #%d", what);
5075 if (select == SOLVER_SOLVABLE_ALL)
5076 return "all packages";
5077 return "unknown job select";
5081 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
5083 Id select = how & SOLVER_SELECTMASK;
5084 const char *strstart = 0, *strend = 0;
5088 switch (how & SOLVER_JOBMASK)
5091 return "do nothing";
5092 case SOLVER_INSTALL:
5093 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
5094 strstart = "keep ", strend = " installed";
5095 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
5096 strstart = "install ";
5097 else if (select == SOLVER_SOLVABLE_PROVIDES)
5098 strstart = "install a package ";
5100 strstart = "install one of ";
5103 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
5104 strstart = "keep ", strend = " uninstalled";
5105 else if (select == SOLVER_SOLVABLE_PROVIDES)
5106 strstart = "deinstall all packages ";
5108 strstart = "deinstall ";
5111 strstart = "update ";
5113 case SOLVER_WEAKENDEPS:
5114 strstart = "weaken deps of ";
5116 case SOLVER_MULTIVERSION:
5117 strstart = "multi version ";
5122 case SOLVER_DISTUPGRADE:
5123 strstart = "dist upgrade ";
5126 strstart = "verify ";
5128 case SOLVER_DROP_ORPHANED:
5129 strstart = "deinstall ", strend = " if orphaned";
5131 case SOLVER_USERINSTALLED:
5132 strstart = "regard ", strend = " as userinstalled";
5134 case SOLVER_ALLOWUNINSTALL:
5135 strstart = "allow deinstallation of ";
5138 strstart = "unknown job ";
5141 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
5143 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
5146 s = pool_tmpappend(pool, s, " ", 0);
5147 if (how & SOLVER_WEAK)
5148 s = pool_tmpappend(pool, s, ",weak", 0);
5149 if (how & SOLVER_ESSENTIAL)
5150 s = pool_tmpappend(pool, s, ",essential", 0);
5151 if (how & SOLVER_CLEANDEPS)
5152 s = pool_tmpappend(pool, s, ",cleandeps", 0);
5153 if (how & SOLVER_ORUPDATE)
5154 s = pool_tmpappend(pool, s, ",orupdate", 0);
5155 if (how & SOLVER_FORCEBEST)
5156 s = pool_tmpappend(pool, s, ",forcebest", 0);
5157 if (how & SOLVER_TARGETED)
5158 s = pool_tmpappend(pool, s, ",targeted", 0);
5159 if (how & SOLVER_SETEV)
5160 s = pool_tmpappend(pool, s, ",setev", 0);
5161 if (how & SOLVER_SETEVR)
5162 s = pool_tmpappend(pool, s, ",setevr", 0);
5163 if (how & SOLVER_SETARCH)
5164 s = pool_tmpappend(pool, s, ",setarch", 0);
5165 if (how & SOLVER_SETVENDOR)
5166 s = pool_tmpappend(pool, s, ",setvendor", 0);
5167 if (how & SOLVER_SETREPO)
5168 s = pool_tmpappend(pool, s, ",setrepo", 0);
5169 if (how & SOLVER_SETNAME)
5170 s = pool_tmpappend(pool, s, ",setname", 0);
5171 if (how & SOLVER_NOAUTOSET)
5172 s = pool_tmpappend(pool, s, ",noautoset", 0);
5173 if (s[o + 1] != ',')
5174 s = pool_tmpappend(pool, s, ",?", 0);
5176 return pool_tmpappend(pool, s, "]", 0);
5180 solver_alternative2str(Solver *solv, int type, Id id, Id from)
5182 Pool *pool = solv->pool;
5183 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
5185 const char *s = pool_dep2str(pool, id);
5186 return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from));
5188 if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
5191 Id depfrom, depto, dep;
5193 if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
5194 id = solver_rule2pkgrule(solv, id);
5195 rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
5196 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
5198 if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES)
5199 return pool_dep2str(pool, dep);
5200 return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep);
5202 if (rtype == SOLVER_RULE_PKG_REQUIRES)
5204 const char *s = pool_dep2str(pool, dep);
5205 return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom));
5207 sprintf(buf, "Rule #%d", id);
5208 return pool_tmpjoin(pool, buf, 0, 0);
5210 return "unknown alternative type";