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"
30 #define RULES_BLOCK 63
32 /********************************************************************
34 * dependency check helpers
38 /*-------------------------------------------------------------------
39 * handle split provides
41 * a splitprovides dep looks like
42 * namespace:splitprovides(pkg REL_WITH path)
43 * and is only true if pkg is installed and contains the specified path.
44 * we also make sure that pkg is selected for an update, otherwise the
45 * update would always be forced onto the user.
48 solver_splitprovides(Solver *solv, Id dep)
50 Pool *pool = solv->pool;
55 if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
59 rd = GETRELDEP(pool, dep);
60 if (rd->flags != REL_WITH)
63 * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
64 * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
65 * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
66 * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
67 * we filter the package name further down anyway).
69 if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
70 pp = pool_searchlazywhatprovidesq(pool, rd->evr);
72 pp = pool_whatprovides(pool, dep);
73 while ((p = pool->whatprovidesdata[pp++]) != 0)
75 /* here we have packages that provide the correct name and contain the path,
76 * now do extra filtering */
77 s = pool->solvables + p;
78 if (s->repo == solv->installed && s->name == rd->name &&
79 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
86 /*-------------------------------------------------------------------
87 * solver_dep_installed
91 solver_dep_installed(Solver *solv, Id dep)
94 Pool *pool = solv->pool;
99 Reldep *rd = GETRELDEP(pool, dep);
100 if (rd->flags == REL_AND)
102 if (!solver_dep_installed(solv, rd->name))
104 return solver_dep_installed(solv, rd->evr);
106 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
107 return solver_dep_installed(solv, rd->evr);
109 FOR_PROVIDES(p, pp, dep)
111 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
118 /* mirrors solver_dep_installed, but returns 2 if a
119 * dependency listed in solv->installsuppdepq was involved */
121 solver_check_installsuppdepq_dep(Solver *solv, Id dep)
123 Pool *pool = solv->pool;
129 Reldep *rd = GETRELDEP(pool, dep);
130 if (rd->flags == REL_AND)
132 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
135 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
138 return r1 == 2 || r2 == 2 ? 2 : 1;
140 if (rd->flags == REL_OR)
142 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
143 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
146 return r1 == 2 || r2 == 2 ? 2 : 1;
148 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
149 return solver_splitprovides(solv, rd->evr);
150 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
151 return solver_dep_installed(solv, rd->evr);
152 if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
155 for (i = 0; i < q->count; i++)
156 if (q->elements[i] == dep || q->elements[i] == rd->name)
160 FOR_PROVIDES(p, pp, dep)
161 if (solv->decisionmap[p] > 0)
167 solver_check_installsuppdepq(Solver *solv, Solvable *s)
170 supp = s->repo->idarraydata + s->supplements;
171 while ((sup = *supp++) != 0)
172 if (solver_check_installsuppdepq_dep(solv, sup) == 2)
178 autouninstall(Solver *solv, Id *problem)
180 Pool *pool = solv->pool;
182 int lastfeature = 0, lastupdate = 0;
186 for (i = 0; (v = problem[i]) != 0; i++)
189 extraflags &= solv->job.elements[-v - 1];
190 if (v >= solv->featurerules && v < solv->featurerules_end)
193 if (v >= solv->updaterules && v < solv->updaterules_end)
195 /* check if identical to feature rule */
196 Id p = solv->rules[v].p;
200 r = solv->rules + solv->featurerules + (p - solv->installed->start);
203 /* update rule == feature rule */
212 if (!lastupdate && !lastfeature)
214 v = lastupdate ? lastupdate : lastfeature;
215 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
216 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
217 solver_disableproblem(solv, v);
218 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
220 /* add the package to the updatepkgs list, this will automatically turn
221 * on cleandeps mode */
222 Id p = solv->rules[v].p;
223 if (!solv->cleandeps_updatepkgs)
225 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
226 queue_init(solv->cleandeps_updatepkgs);
230 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
231 queue_pushunique(solv->cleandeps_updatepkgs, p);
232 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
233 solver_disablepolicyrules(solv);
239 /************************************************************************/
242 * enable/disable learnt rules
244 * we have enabled or disabled some of our rules. We now reenable all
245 * of our learnt rules except the ones that were learnt from rules that
249 enabledisablelearntrules(Solver *solv)
251 Pool *pool = solv->pool;
256 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
257 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
259 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
260 while ((why = *whyp++) != 0)
262 assert(why > 0 && why < i);
263 if (solv->rules[why].d < 0)
266 /* why != 0: we found a disabled rule, disable the learnt rule */
267 if (why && r->d >= 0)
269 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
271 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
272 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
274 solver_disablerule(solv, r);
276 else if (!why && r->d < 0)
278 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
280 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
281 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
283 solver_enablerule(solv, r);
290 * make assertion rules into decisions
292 * Go through rules and add direct assertions to the decisionqueue.
293 * If we find a conflict, disable rules and add them to problem queue.
297 makeruledecisions(Solver *solv)
299 Pool *pool = solv->pool;
304 int record_proof = 1;
306 int havedisabled = 0;
308 /* The system solvable is always installed first */
309 assert(solv->decisionq.count == 0);
310 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
311 queue_push(&solv->decisionq_why, 0);
312 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
314 decisionstart = solv->decisionq.count;
317 /* if we needed to re-run, back up decisions to decisionstart */
318 while (solv->decisionq.count > decisionstart)
320 v = solv->decisionq.elements[--solv->decisionq.count];
321 --solv->decisionq_why.count;
323 solv->decisionmap[vv] = 0;
326 /* note that the ruleassertions queue is ordered */
327 for (ii = 0; ii < solv->ruleassertions.count; ii++)
329 ri = solv->ruleassertions.elements[ii];
330 r = solv->rules + ri;
332 if (havedisabled && ri >= solv->learntrules)
334 /* just started with learnt rule assertions. If we have disabled
335 * some rules, adapt the learnt rule status */
336 enabledisablelearntrules(solv);
340 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
343 /* do weak rules in phase 2 */
344 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
350 if (!solv->decisionmap[vv]) /* if not yet decided */
352 queue_push(&solv->decisionq, v);
353 queue_push(&solv->decisionq_why, r - solv->rules);
354 solv->decisionmap[vv] = v > 0 ? 1 : -1;
355 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
357 Solvable *s = solv->pool->solvables + vv;
359 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
361 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
366 /* check against previous decision: is there a conflict? */
367 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
369 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
375 * The rule (r) we're currently processing says something
376 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
380 if (ri >= solv->learntrules)
382 /* conflict with a learnt rule */
383 /* can happen when packages cannot be installed for multiple reasons. */
384 /* we disable the learnt rule in this case */
385 /* (XXX: we should really call analyze_unsolvable_rule here!) */
386 solver_disablerule(solv, r);
391 * find the decision which is the "opposite" of the rule
393 for (i = 0; i < solv->decisionq.count; i++)
394 if (solv->decisionq.elements[i] == -v)
396 assert(i < solv->decisionq.count); /* assert that we found it */
397 oldproblemcount = solv->problems.count;
400 * conflict with system solvable ?
402 if (v == -SYSTEMSOLVABLE)
406 queue_push(&solv->problems, solv->learnt_pool.count);
407 queue_push(&solv->learnt_pool, ri);
408 queue_push(&solv->learnt_pool, 0);
411 queue_push(&solv->problems, 0);
412 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
413 if (ri >= solv->jobrules && ri < solv->jobrules_end)
414 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
417 queue_push(&solv->problems, v);
418 queue_push(&solv->problems, 0);
419 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
420 solv->problems.count = oldproblemcount;
421 solver_disableproblem(solv, v);
423 break; /* start over */
426 assert(solv->decisionq_why.elements[i] > 0);
429 * conflict with an rpm rule ?
431 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
435 queue_push(&solv->problems, solv->learnt_pool.count);
436 queue_push(&solv->learnt_pool, ri);
437 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
438 queue_push(&solv->learnt_pool, 0);
441 queue_push(&solv->problems, 0);
442 assert(v > 0 || v == -SYSTEMSOLVABLE);
443 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
444 if (ri >= solv->jobrules && ri < solv->jobrules_end)
445 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
448 queue_push(&solv->problems, v);
449 queue_push(&solv->problems, 0);
450 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
451 solv->problems.count = oldproblemcount;
452 solver_disableproblem(solv, v);
454 break; /* start over */
458 * conflict with another job or update/feature rule
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);
472 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
475 * push all of our rules (can only be feature or job rules)
476 * asserting this literal on the problem stack
478 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
480 if (rr->d < 0 /* disabled */
481 || rr->w2) /* or no assertion */
483 if (rr->p != vv /* not affecting the literal */
486 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
489 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
490 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
493 if (i >= solv->jobrules && i < solv->jobrules_end)
494 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
495 queue_push(&solv->problems, v);
497 queue_push(&solv->problems, 0);
499 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
500 solv->problems.count = oldproblemcount;
502 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
503 solver_disableproblem(solv, solv->problems.elements[i]);
505 break; /* start over */
507 if (ii < solv->ruleassertions.count)
511 * phase 2: now do the weak assertions
513 for (ii = 0; ii < solv->ruleassertions.count; ii++)
515 ri = solv->ruleassertions.elements[ii];
516 r = solv->rules + ri;
517 if (r->d < 0 || r->w2) /* disabled or no assertion */
519 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
524 if (!solv->decisionmap[vv]) /* if not yet decided */
526 queue_push(&solv->decisionq, v);
527 queue_push(&solv->decisionq_why, r - solv->rules);
528 solv->decisionmap[vv] = v > 0 ? 1 : -1;
529 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
531 Solvable *s = solv->pool->solvables + vv;
533 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
535 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
539 /* check against previous decision: is there a conflict? */
540 if (v > 0 && solv->decisionmap[vv] > 0)
542 if (v < 0 && solv->decisionmap[vv] < 0)
545 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
546 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
548 if (ri >= solv->jobrules && ri < solv->jobrules_end)
549 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
552 solver_disableproblem(solv, v);
554 solver_reenablepolicyrules(solv, -v);
556 break; /* start over */
558 if (ii == solv->ruleassertions.count)
559 break; /* finished! */
564 /********************************************************************/
568 /*-------------------------------------------------------------------
571 * initial setup for all watches
575 makewatches(Solver *solv)
579 int nsolvables = solv->pool->nsolvables;
581 solv_free(solv->watches);
582 /* lower half for removals, upper half for installs */
583 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
585 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
586 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
588 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
591 if (!r->w2) /* assertions do not need watches */
594 /* see addwatches_rule(solv, r) */
595 r->n1 = solv->watches[nsolvables + r->w1];
596 solv->watches[nsolvables + r->w1] = r - solv->rules;
598 r->n2 = solv->watches[nsolvables + r->w2];
599 solv->watches[nsolvables + r->w2] = r - solv->rules;
604 /*-------------------------------------------------------------------
606 * add watches (for a new learned rule)
607 * sets up watches for a single rule
609 * see also makewatches() above.
613 addwatches_rule(Solver *solv, Rule *r)
615 int nsolvables = solv->pool->nsolvables;
617 r->n1 = solv->watches[nsolvables + r->w1];
618 solv->watches[nsolvables + r->w1] = r - solv->rules;
620 r->n2 = solv->watches[nsolvables + r->w2];
621 solv->watches[nsolvables + r->w2] = r - solv->rules;
625 /********************************************************************/
631 /* shortcuts to check if a literal (positive or negative) assignment
632 * evaluates to 'true' or 'false'
634 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
635 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
636 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
638 /*-------------------------------------------------------------------
642 * make decision and propagate to all rules
644 * Evaluate each term affected by the decision (linked through watches).
645 * If we find unit rules we make new decisions based on them.
647 * return : 0 = everything is OK
648 * rule = conflict found in this rule
652 propagate(Solver *solv, int level)
654 Pool *pool = solv->pool;
655 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
657 Id p, pkg, other_watch;
659 Id *decisionmap = solv->decisionmap;
661 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
663 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
665 /* foreach non-propagated decision */
666 while (solv->propagate_index < solv->decisionq.count)
669 * 'pkg' was just decided
670 * negate because our watches trigger if literal goes FALSE
672 pkg = -solv->decisionq.elements[solv->propagate_index++];
674 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
676 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
677 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
680 /* foreach rule where 'pkg' is now FALSE */
681 for (rp = watches + pkg; *rp; rp = next_rp)
683 r = solv->rules + *rp;
686 /* rule is disabled, goto next */
694 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
696 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
697 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
700 /* 'pkg' was just decided (was set to FALSE)
702 * now find other literal watch, check clause
703 * and advance on linked list
717 * This term is already true (through the other literal)
718 * so we have nothing to do
720 if (DECISIONMAP_TRUE(other_watch))
724 * The other literal is FALSE or UNDEF
730 /* Not a binary clause, try to move our watch.
732 * Go over all literals and find one that is
736 * (TRUE is also ok, in that case the rule is fulfilled)
738 if (r->p /* we have a 'p' */
739 && r->p != other_watch /* which is not watched */
740 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
744 else /* go find a 'd' to make 'true' */
747 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
749 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
751 if (p != other_watch /* which is not watched */
752 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
760 * if we found some p that is UNDEF or TRUE, move
763 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
766 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
768 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
784 watches[p] = r - solv->rules;
787 /* search failed, thus all unwatched literals are FALSE */
792 * unit clause found, set literal other_watch to TRUE
795 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
796 return r; /* eek, a conflict! */
798 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
800 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
801 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
805 decisionmap[other_watch] = level; /* install! */
807 decisionmap[-other_watch] = -level; /* remove! */
809 queue_push(&solv->decisionq, other_watch);
810 queue_push(&solv->decisionq_why, r - solv->rules);
812 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
815 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
817 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
820 } /* foreach rule involving 'pkg' */
822 } /* while we have non-decided decisions */
824 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
826 return 0; /* all is well */
830 /********************************************************************/
833 /*-------------------------------------------------------------------
840 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
842 Pool *pool = solv->pool;
846 Map seen; /* global? */
847 Id d, v, vv, *dp, why;
849 int num = 0, l1num = 0;
850 int learnt_why = solv->learnt_pool.count;
851 Id *decisionmap = solv->decisionmap;
853 queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
855 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
856 map_init(&seen, pool->nsolvables);
857 idx = solv->decisionq.count;
860 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
861 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
862 queue_push(&solv->learnt_pool, c - solv->rules);
863 d = c->d < 0 ? -c->d - 1 : c->d;
864 dp = d ? pool->whatprovidesdata + d : 0;
865 /* go through all literals of the rule */
877 if (DECISIONMAP_TRUE(v)) /* the one true literal */
880 if (MAPTST(&seen, vv))
882 l = solv->decisionmap[vv];
885 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
887 l1num++; /* need to do this one in level1 pass */
889 num++; /* need to do this one as well */
892 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
898 if (!num && !--l1num)
899 break; /* all level 1 literals done */
901 /* find the next literal to investigate */
902 /* (as num + l1num > 0, we know that we'll always find one) */
906 v = solv->decisionq.elements[--idx];
908 if (MAPTST(&seen, vv))
913 if (num && --num == 0)
915 *pr = -v; /* so that v doesn't get lost */
918 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
919 /* clear non-l1 bits from seen map */
920 for (i = 0; i < r.count; i++)
923 MAPCLR(&seen, v > 0 ? v : -v);
925 /* only level 1 marks left in seen map */
926 l1num++; /* as l1retry decrements it */
930 why = solv->decisionq_why.elements[idx];
931 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
933 c = solv->rules + why;
939 else if (r.count == 1 && r.elements[0] < 0)
942 *dr = pool_queuetowhatprovides(pool, &r);
943 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
945 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
946 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
947 for (i = 0; i < r.count; i++)
948 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
950 /* push end marker on learnt reasons stack */
951 queue_push(&solv->learnt_pool, 0);
955 solv->stats_learned++;
960 /*-------------------------------------------------------------------
964 * reset all solver decisions
965 * called after rules have been enabled/disabled
969 solver_reset(Solver *solv)
971 Pool *pool = solv->pool;
975 /* rewind all decisions */
976 for (i = solv->decisionq.count - 1; i >= 0; i--)
978 v = solv->decisionq.elements[i];
979 solv->decisionmap[v > 0 ? v : -v] = 0;
981 queue_empty(&solv->decisionq_why);
982 queue_empty(&solv->decisionq);
983 solv->recommends_index = -1;
984 solv->propagate_index = 0;
985 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
986 queue_empty(&solv->branches);
988 /* adapt learnt rule status to new set of enabled/disabled rules */
989 enabledisablelearntrules(solv);
991 /* redo all assertion rule decisions */
992 makeruledecisions(solv);
993 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
997 /*-------------------------------------------------------------------
999 * analyze_unsolvable_rule
1001 * recursion helper used by analyze_unsolvable
1005 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1007 Pool *pool = solv->pool;
1009 Id why = r - solv->rules;
1011 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1012 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1013 if (solv->learntrules && why >= solv->learntrules)
1015 if (MAPTST(rseen, why - solv->learntrules))
1017 MAPSET(rseen, why - solv->learntrules);
1018 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1019 if (solv->learnt_pool.elements[i] > 0)
1020 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1023 if (MAPTST(&solv->weakrulemap, why))
1024 if (!*lastweakp || why > *lastweakp)
1026 /* do not add rpm rules to problem */
1027 if (why < solv->rpmrules_end)
1029 /* turn rule into problem */
1030 if (why >= solv->jobrules && why < solv->jobrules_end)
1031 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1032 /* normalize dup/infarch rules */
1033 if (why > solv->infarchrules && why < solv->infarchrules_end)
1035 Id name = pool->solvables[-solv->rules[why].p].name;
1036 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1039 if (why > solv->duprules && why < solv->duprules_end)
1041 Id name = pool->solvables[-solv->rules[why].p].name;
1042 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1046 /* return if problem already countains our rule */
1047 if (solv->problems.count)
1049 for (i = solv->problems.count - 1; i >= 0; i--)
1050 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1052 else if (solv->problems.elements[i] == why)
1055 queue_push(&solv->problems, why);
1059 /*-------------------------------------------------------------------
1061 * analyze_unsolvable
1063 * We know that the problem is not solvable. Record all involved
1064 * rules (i.e. the "proof") into solv->learnt_pool.
1065 * Record the learnt pool index and all non-rpm rules into
1066 * solv->problems. (Our solutions to fix the problems are to
1067 * disable those rules.)
1069 * If the proof contains at least one weak rule, we disable the
1072 * Otherwise we return 0 if disablerules is not set or disable
1073 * _all_ of the problem rules and return 1.
1075 * return: 1 - disabled some rules, try again
1080 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1082 Pool *pool = solv->pool;
1084 Map seen; /* global to speed things up? */
1086 Id d, v, vv, *dp, why;
1088 Id *decisionmap = solv->decisionmap;
1089 int oldproblemcount;
1090 int oldlearntpoolcount;
1092 int record_proof = 1;
1094 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1095 solv->stats_unsolvable++;
1096 oldproblemcount = solv->problems.count;
1097 oldlearntpoolcount = solv->learnt_pool.count;
1099 /* make room for proof index */
1100 /* must update it later, as analyze_unsolvable_rule would confuse
1101 * it with a rule index if we put the real value in already */
1102 queue_push(&solv->problems, 0);
1105 map_init(&seen, pool->nsolvables);
1106 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1108 queue_push(&solv->learnt_pool, r - solv->rules);
1110 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1111 d = r->d < 0 ? -r->d - 1 : r->d;
1112 dp = d ? pool->whatprovidesdata + d : 0;
1123 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1125 vv = v > 0 ? v : -v;
1126 l = solv->decisionmap[vv];
1131 idx = solv->decisionq.count;
1134 v = solv->decisionq.elements[--idx];
1135 vv = v > 0 ? v : -v;
1136 if (!MAPTST(&seen, vv) || vv == SYSTEMSOLVABLE)
1138 why = solv->decisionq_why.elements[idx];
1141 queue_push(&solv->learnt_pool, why);
1142 r = solv->rules + why;
1143 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1144 d = r->d < 0 ? -r->d - 1 : r->d;
1145 dp = d ? pool->whatprovidesdata + d : 0;
1156 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1158 vv = v > 0 ? v : -v;
1159 l = solv->decisionmap[vv];
1167 queue_push(&solv->problems, 0); /* mark end of this problem */
1171 /* disable last weak rule */
1172 solv->problems.count = oldproblemcount;
1173 solv->learnt_pool.count = oldlearntpoolcount;
1174 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1175 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1178 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1179 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1180 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1181 solver_disablechoicerules(solv, solv->rules + lastweak);
1182 solver_disableproblem(solv, v);
1184 solver_reenablepolicyrules(solv, -v);
1189 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
1191 solv->problems.count = oldproblemcount;
1192 solv->learnt_pool.count = oldlearntpoolcount;
1200 queue_push(&solv->learnt_pool, 0);
1201 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1204 /* + 2: index + trailing zero */
1205 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1207 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1208 solver_disableproblem(solv, solv->problems.elements[i]);
1209 /* XXX: might want to enable all weak rules again */
1213 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1218 /********************************************************************/
1219 /* Decision revert */
1221 /*-------------------------------------------------------------------
1224 * revert decisionq to a level
1228 revert(Solver *solv, int level)
1230 Pool *pool = solv->pool;
1232 while (solv->decisionq.count)
1234 v = solv->decisionq.elements[solv->decisionq.count - 1];
1235 vv = v > 0 ? v : -v;
1236 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1238 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1239 solv->decisionmap[vv] = 0;
1240 solv->decisionq.count--;
1241 solv->decisionq_why.count--;
1242 solv->propagate_index = solv->decisionq.count;
1244 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1246 solv->branches.count--;
1247 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1248 solv->branches.count--;
1250 if (solv->recommends_index > solv->decisionq.count)
1251 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
1252 if (solv->decisionq.count < solv->decisioncnt_update)
1253 solv->decisioncnt_update = 0;
1254 if (solv->decisionq.count < solv->decisioncnt_keep)
1255 solv->decisioncnt_keep = 0;
1256 if (solv->decisionq.count < solv->decisioncnt_resolve)
1257 solv->decisioncnt_resolve = 0;
1258 if (solv->decisionq.count < solv->decisioncnt_weak)
1259 solv->decisioncnt_weak= 0;
1260 if (solv->decisionq.count < solv->decisioncnt_orphan)
1261 solv->decisioncnt_orphan = 0;
1265 /*-------------------------------------------------------------------
1267 * watch2onhighest - put watch2 on literal with highest level
1271 watch2onhighest(Solver *solv, Rule *r)
1276 d = r->d < 0 ? -r->d - 1 : r->d;
1278 return; /* binary rule, both watches are set */
1279 dp = solv->pool->whatprovidesdata + d;
1280 while ((v = *dp++) != 0)
1282 l = solv->decisionmap[v < 0 ? -v : v];
1294 /*-------------------------------------------------------------------
1298 * add free decision (solvable to install) to decisionq
1299 * increase level and propagate decision
1300 * return if no conflict.
1302 * in conflict case, analyze conflict rule, add resulting
1303 * rule to learnt rule set, make decision from learnt
1304 * rule (always unit) and re-propagate.
1306 * returns the new solver level or 0 if unsolvable
1311 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1313 Pool *pool = solv->pool;
1318 assert(ruleid >= 0);
1323 solv->decisionmap[decision] = level;
1325 solv->decisionmap[-decision] = -level;
1326 queue_push(&solv->decisionq, decision);
1327 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1331 r = propagate(solv, level);
1335 return analyze_unsolvable(solv, r, disablerules);
1336 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1337 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1338 assert(l > 0 && l < level);
1339 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1341 revert(solv, level);
1342 r = solver_addrule(solv, p, d);
1344 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1345 queue_push(&solv->learnt_why, why);
1348 /* at least 2 literals, needs watches */
1349 watch2onhighest(solv, r);
1350 addwatches_rule(solv, r);
1354 /* learnt rule is an assertion */
1355 queue_push(&solv->ruleassertions, r - solv->rules);
1357 /* the new rule is unit by design */
1358 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1359 queue_push(&solv->decisionq, p);
1360 queue_push(&solv->decisionq_why, r - solv->rules);
1361 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1363 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1364 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1365 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1366 solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
1373 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1375 Pool *pool = solv->pool;
1376 int i, j, haveone = 0, dqcount = dq->count;
1380 /* at the time we process jobrules the installed packages are not kept yet */
1381 /* reorder so that "future-supplemented" packages come first */
1382 FOR_REPO_SOLVABLES(solv->installed, p, s)
1384 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1386 if (solv->decisionmap[p] == 0)
1388 solv->decisionmap[p] = level;
1394 for (i = 0; i < dqcount; i++)
1395 if (!solver_is_enhancing(solv, pool->solvables + dq->elements[i]))
1397 queue_push(dq, dq->elements[i]);
1398 dq->elements[i] = 0;
1400 dqcount = dq->count;
1401 for (i = 0; i < dqcount; i++)
1402 if (dq->elements[i] && !solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1404 queue_push(dq, dq->elements[i]);
1405 dq->elements[i] = 0;
1407 for (i = j = 0; i < dq->count; i++)
1408 if (dq->elements[i])
1409 dq->elements[j++] = dq->elements[i];
1410 queue_truncate(dq, j);
1411 FOR_REPO_SOLVABLES(solv->installed, p, s)
1412 if (solv->decisionmap[p] == level)
1413 solv->decisionmap[p] = 0;
1416 /*-------------------------------------------------------------------
1418 * select and install
1420 * install best package from the queue. We add an extra package, inst, if
1421 * provided. See comment in weak install section.
1423 * returns the new solver level or 0 if unsolvable
1428 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1430 Pool *pool = solv->pool;
1435 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1438 /* XXX: didn't we already do that? */
1439 /* XXX: shouldn't we prefer installed packages? */
1440 /* XXX: move to policy.c? */
1441 /* choose the supplemented one */
1442 for (i = 0; i < dq->count; i++)
1443 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1445 dq->elements[0] = dq->elements[i];
1450 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed)
1451 reorder_dq_for_jobrules(solv, level, dq);
1454 /* multiple candidates, open a branch */
1455 for (i = 1; i < dq->count; i++)
1456 queue_push(&solv->branches, dq->elements[i]);
1457 queue_push(&solv->branches, -level);
1459 p = dq->elements[0];
1461 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1463 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1467 /********************************************************************/
1468 /* Main solver interface */
1471 /*-------------------------------------------------------------------
1474 * create solver structure
1476 * pool: all available solvables
1477 * installed: installed Solvables
1480 * Upon solving, rules are created to flag the Solvables
1481 * of the 'installed' Repo as installed.
1485 solver_create(Pool *pool)
1488 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1490 solv->installed = pool->installed;
1492 solv->allownamechange = 1;
1494 solv->dup_allowdowngrade = 1;
1495 solv->dup_allownamechange = 1;
1496 solv->dup_allowarchchange = 1;
1497 solv->dup_allowvendorchange = 1;
1499 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1501 queue_init(&solv->ruletojob);
1502 queue_init(&solv->decisionq);
1503 queue_init(&solv->decisionq_why);
1504 queue_init(&solv->problems);
1505 queue_init(&solv->orphaned);
1506 queue_init(&solv->learnt_why);
1507 queue_init(&solv->learnt_pool);
1508 queue_init(&solv->branches);
1509 queue_init(&solv->weakruleq);
1510 queue_init(&solv->ruleassertions);
1511 queue_init(&solv->addedmap_deduceq);
1513 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1515 map_init(&solv->recommendsmap, pool->nsolvables);
1516 map_init(&solv->suggestsmap, pool->nsolvables);
1517 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1518 solv->recommends_index = 0;
1520 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1522 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1523 memset(solv->rules, 0, sizeof(Rule));
1529 /*-------------------------------------------------------------------
1535 queuep_free(Queue **qp)
1540 *qp = solv_free(*qp);
1544 map_zerosize(Map *m)
1554 solver_free(Solver *solv)
1556 queue_free(&solv->job);
1557 queue_free(&solv->ruletojob);
1558 queue_free(&solv->decisionq);
1559 queue_free(&solv->decisionq_why);
1560 queue_free(&solv->learnt_why);
1561 queue_free(&solv->learnt_pool);
1562 queue_free(&solv->problems);
1563 queue_free(&solv->solutions);
1564 queue_free(&solv->orphaned);
1565 queue_free(&solv->branches);
1566 queue_free(&solv->weakruleq);
1567 queue_free(&solv->ruleassertions);
1568 queue_free(&solv->addedmap_deduceq);
1569 queuep_free(&solv->cleandeps_updatepkgs);
1570 queuep_free(&solv->cleandeps_mistakes);
1571 queuep_free(&solv->update_targets);
1572 queuep_free(&solv->installsuppdepq);
1573 queuep_free(&solv->recommendscplxq);
1574 queuep_free(&solv->suggestscplxq);
1576 map_free(&solv->recommendsmap);
1577 map_free(&solv->suggestsmap);
1578 map_free(&solv->noupdate);
1579 map_free(&solv->weakrulemap);
1580 map_free(&solv->multiversion);
1582 map_free(&solv->updatemap);
1583 map_free(&solv->bestupdatemap);
1584 map_free(&solv->fixmap);
1585 map_free(&solv->dupmap);
1586 map_free(&solv->dupinvolvedmap);
1587 map_free(&solv->droporphanedmap);
1588 map_free(&solv->cleandepsmap);
1590 solv_free(solv->decisionmap);
1591 solv_free(solv->rules);
1592 solv_free(solv->watches);
1593 solv_free(solv->obsoletes);
1594 solv_free(solv->obsoletes_data);
1595 solv_free(solv->specialupdaters);
1596 solv_free(solv->choicerules_ref);
1597 solv_free(solv->bestrules_pkg);
1598 solv_free(solv->instbuddy);
1603 solver_get_flag(Solver *solv, int flag)
1607 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1608 return solv->allowdowngrade;
1609 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1610 return solv->allownamechange;
1611 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1612 return solv->allowarchchange;
1613 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1614 return solv->allowvendorchange;
1615 case SOLVER_FLAG_ALLOW_UNINSTALL:
1616 return solv->allowuninstall;
1617 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1618 return solv->noupdateprovide;
1619 case SOLVER_FLAG_SPLITPROVIDES:
1620 return solv->dosplitprovides;
1621 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1622 return solv->dontinstallrecommended;
1623 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1624 return solv->addalreadyrecommended;
1625 case SOLVER_FLAG_NO_INFARCHCHECK:
1626 return solv->noinfarchcheck;
1627 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1628 return solv->keepexplicitobsoletes;
1629 case SOLVER_FLAG_BEST_OBEY_POLICY:
1630 return solv->bestobeypolicy;
1631 case SOLVER_FLAG_NO_AUTOTARGET:
1632 return solv->noautotarget;
1633 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1634 return solv->dup_allowdowngrade;
1635 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1636 return solv->dup_allownamechange;
1637 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1638 return solv->dup_allowarchchange;
1639 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1640 return solv->dup_allowvendorchange;
1648 solver_set_flag(Solver *solv, int flag, int value)
1650 int old = solver_get_flag(solv, flag);
1653 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1654 solv->allowdowngrade = value;
1656 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1657 solv->allownamechange = value;
1659 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1660 solv->allowarchchange = value;
1662 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1663 solv->allowvendorchange = value;
1665 case SOLVER_FLAG_ALLOW_UNINSTALL:
1666 solv->allowuninstall = value;
1668 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1669 solv->noupdateprovide = value;
1671 case SOLVER_FLAG_SPLITPROVIDES:
1672 solv->dosplitprovides = value;
1674 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1675 solv->dontinstallrecommended = value;
1677 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1678 solv->addalreadyrecommended = value;
1680 case SOLVER_FLAG_NO_INFARCHCHECK:
1681 solv->noinfarchcheck = value;
1683 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1684 solv->keepexplicitobsoletes = value;
1686 case SOLVER_FLAG_BEST_OBEY_POLICY:
1687 solv->bestobeypolicy = value;
1689 case SOLVER_FLAG_NO_AUTOTARGET:
1690 solv->noautotarget = value;
1692 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1693 solv->dup_allowdowngrade = value;
1695 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1696 solv->dup_allownamechange = value;
1698 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1699 solv->dup_allowarchchange = value;
1701 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1702 solv->dup_allowvendorchange = value;
1711 cleandeps_check_mistakes(Solver *solv, int level)
1713 Pool *pool = solv->pool;
1717 int mademistake = 0;
1719 if (!solv->cleandepsmap.size)
1721 /* check for mistakes */
1722 for (i = solv->installed->start; i < solv->installed->end; i++)
1724 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1726 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1727 /* a mistake is when the featurerule is true but the updaterule is false */
1730 FOR_RULELITERALS(p, pp, r)
1731 if (p > 0 && solv->decisionmap[p] > 0)
1734 continue; /* feature rule is not true */
1735 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1738 FOR_RULELITERALS(p, pp, r)
1739 if (p > 0 && solv->decisionmap[p] > 0)
1742 continue; /* update rule is true */
1743 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1744 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1745 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1746 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1747 if (!solv->cleandeps_mistakes)
1749 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1750 queue_init(solv->cleandeps_mistakes);
1752 queue_push(solv->cleandeps_mistakes, i);
1753 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1754 solver_reenablepolicyrules_cleandeps(solv, i);
1763 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1767 for (i = j = 0; i < q->count; i++)
1770 for (cp2 = cp; *cp2; cp2++)
1773 q->elements[j++] = p;
1777 queue_truncate(q, j);
1780 #ifdef ENABLE_COMPLEX_DEPS
1783 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1785 Pool *pool = solv->pool;
1786 int oldcnt = dq->count;
1792 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1794 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1795 if (i == 0 || i == 1)
1798 for (i = oldcnt; i < cutcnt; i++)
1801 for (; (p = dq->elements[i]) != 0; i++)
1805 if (solv->decisionmap[-p] <= 0)
1809 if (solv->decisionmap[p] > 0)
1811 queue_truncate(dq, blkcnt);
1816 if (!MAPTST(dqmap, p))
1821 if (solv->decisionmap[p] < 0)
1823 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))))
1828 while (dq->elements[i])
1831 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1833 if (dq->count != oldcnt)
1835 for (j = oldcnt; j < dq->count; j++)
1837 p = dq->elements[j];
1838 for (i = 0; i < j; i++)
1839 if (dq->elements[i] == p)
1841 dq->elements[j] = 0;
1845 for (i = j = oldcnt; j < dq->count; j++)
1846 if (dq->elements[j])
1847 dq->elements[i++] = dq->elements[j];
1848 queue_truncate(dq, i);
1851 printf("RETURN:\n");
1852 for (i = oldcnt; i < dq->count; i++)
1853 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
1858 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
1860 Pool *pool = solv->pool;
1866 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
1869 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
1870 if (i == 0 || i == 1)
1875 for (i = 0; i < dq.count; i++)
1878 for (; (p = dq.elements[i]) != 0; i++)
1882 if (solv->decisionmap[-p] <= 0)
1886 if (solv->decisionmap[p] > 0)
1891 for (i++; (p = dq.elements[i]) != 0; i++)
1892 if (p > 0 && solv->decisionmap[p] > 0)
1900 for (i = blk; (p = dq.elements[i]) != 0; i++)
1904 while (dq.elements[i])
1912 /*-------------------------------------------------------------------
1916 * all rules have been set up, now actually run the solver
1921 solver_run_sat(Solver *solv, int disablerules, int doweak)
1923 Queue dq; /* local decisionqueue */
1924 Queue dqs; /* local decisionqueue for supplements */
1930 Pool *pool = solv->pool;
1932 int minimizationsteps;
1933 int installedpos = solv->installed ? solv->installed->start : 0;
1935 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
1937 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
1938 for (i = 1; i < solv->nrules; i++)
1939 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
1942 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
1944 /* start SAT algorithm */
1946 systemlevel = level + 1;
1947 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
1953 * here's the main loop:
1954 * 1) propagate new decisions (only needed once)
1956 * 3) try to keep installed packages
1957 * 4) fulfill all unresolved rules
1958 * 5) install recommended packages
1959 * 6) minimalize solution if we had choices
1960 * if we encounter a problem, we rewind to a safe level and restart
1964 minimizationsteps = 0;
1968 * initial propagation of the assertions
1972 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
1973 if ((r = propagate(solv, level)) != 0)
1975 if (analyze_unsolvable(solv, r, disablerules))
1978 break; /* unsolvable */
1983 * resolve jobs first
1985 if (level < systemlevel)
1987 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1988 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1991 if (r->d < 0) /* ignore disabled rules */
1994 FOR_RULELITERALS(l, pp, r)
1998 if (solv->decisionmap[-l] <= 0)
2003 if (solv->decisionmap[l] > 0)
2005 if (solv->decisionmap[l] == 0)
2011 /* prune to installed if not updating */
2012 if (dq.count > 1 && solv->installed && !solv->updatemap_all &&
2013 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
2016 for (j = k = 0; j < dq.count; j++)
2018 Solvable *s = pool->solvables + dq.elements[j];
2019 if (s->repo == solv->installed)
2021 dq.elements[k++] = dq.elements[j];
2022 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq.elements[j] - solv->installed->start))
2024 k = 0; /* package wants to be updated, do not prune */
2033 level = selectandinstall(solv, level, &dq, disablerules, i);
2036 if (level <= olevel)
2040 break; /* unsolvable */
2041 systemlevel = level + 1;
2042 if (i < solv->jobrules_end)
2044 if (!solv->decisioncnt_update)
2045 solv->decisioncnt_update = solv->decisionq.count;
2049 * installed packages
2051 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2053 Repo *installed = solv->installed;
2056 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2057 /* we use two passes if we need to update packages
2058 * to create a better user experience */
2059 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2061 int passlevel = level;
2062 Id *specialupdaters = solv->specialupdaters;
2063 if (pass == 1 && !solv->decisioncnt_keep)
2064 solv->decisioncnt_keep = solv->decisionq.count;
2065 /* start with installedpos, the position that gave us problems the last time */
2066 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2071 if (i == installed->end)
2072 i = installed->start;
2073 s = pool->solvables + i;
2074 if (s->repo != installed)
2077 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2078 continue; /* already decided */
2079 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2080 continue; /* updates first */
2081 r = solv->rules + solv->updaterules + (i - installed->start);
2083 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2084 rr -= solv->installed->end - solv->installed->start;
2085 if (!rr->p) /* identical to update rule? */
2087 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2088 continue; /* orpaned package */
2090 /* check if we should update this package to the latest version
2091 * noupdate is set for erase jobs, in that case we want to deinstall
2092 * the installed package and not replace it with a newer version
2093 * rr->p != i is for dup jobs where the installed package cannot be kept */
2095 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)))
2099 /* specialupdater with no update/feature rule */
2100 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2102 if (solv->decisionmap[p] > 0)
2107 if (!solv->decisionmap[p])
2111 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2113 /* special multiversion handling, make sure best version is chosen */
2114 if (rr->p == i && solv->decisionmap[i] >= 0)
2116 while ((p = pool->whatprovidesdata[d++]) != 0)
2117 if (solv->decisionmap[p] >= 0)
2119 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2120 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2123 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2125 if (p != i && solv->decisionmap[p] == 0)
2127 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2128 if (!rr->p) /* update rule == feature rule? */
2129 rr = rr - solv->featurerules + solv->updaterules;
2138 /* update to best package of the update rule */
2139 FOR_RULELITERALS(p, pp, rr)
2141 if (solv->decisionmap[p] > 0)
2143 dq.count = 0; /* already fulfilled */
2146 if (!solv->decisionmap[p])
2151 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2152 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2153 /* install best version */
2157 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2164 if (level <= olevel)
2166 if (level == 1 || level < passlevel)
2167 break; /* trouble */
2169 n = installed->start; /* redo all */
2175 /* if still undecided keep package */
2176 if (solv->decisionmap[i] == 0)
2179 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2182 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2183 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2190 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2191 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2195 if (level <= olevel)
2197 if (level == 1 || level < passlevel)
2198 break; /* trouble */
2200 n = installed->start; /* redo all */
2203 continue; /* retry with learnt rule */
2207 if (n < installed->end)
2209 installedpos = i; /* retry problem solvable next time */
2210 break; /* ran into trouble */
2212 installedpos = installed->start; /* reset installedpos */
2215 break; /* unsolvable */
2216 systemlevel = level + 1;
2218 continue; /* had trouble, retry */
2220 if (!solv->decisioncnt_keep)
2221 solv->decisioncnt_keep = solv->decisionq.count;
2223 if (level < systemlevel)
2224 systemlevel = level;
2229 if (!solv->decisioncnt_resolve)
2230 solv->decisioncnt_resolve = solv->decisionq.count;
2231 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2232 for (i = 1, n = 1; n < solv->nrules; i++, n++)
2234 if (i == solv->nrules)
2236 r = solv->rules + i;
2237 if (r->d < 0) /* ignore disabled rules */
2239 if (r->p < 0) /* most common cases first */
2241 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2248 /* binary or unary rule */
2249 /* need two positive undecided literals, r->p already checked above */
2252 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2254 queue_push(&dq, r->p);
2255 queue_push(&dq, r->w2);
2260 * all negative literals are installed
2261 * no positive literal is installed
2262 * i.e. the rule is not fulfilled and we
2263 * just need to decide on the positive literals
2264 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2268 if (solv->decisionmap[r->p] > 0)
2270 if (solv->decisionmap[r->p] == 0)
2271 queue_push(&dq, r->p);
2273 dp = pool->whatprovidesdata + r->d;
2274 while ((p = *dp++) != 0)
2278 if (solv->decisionmap[-p] <= 0)
2283 if (solv->decisionmap[p] > 0)
2285 if (solv->decisionmap[p] == 0)
2292 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2294 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2295 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2297 /* dq.count < 2 cannot happen as this means that
2298 * the rule is unit */
2299 assert(dq.count > 1);
2301 /* prune to cleandeps packages */
2302 if (solv->cleandepsmap.size && solv->installed)
2304 Repo *installed = solv->installed;
2305 for (j = 0; j < dq.count; j++)
2306 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2310 dq.elements[0] = dq.elements[j];
2311 queue_truncate(&dq, 1);
2316 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2318 break; /* unsolvable */
2319 if (level < systemlevel || level == 1)
2320 break; /* trouble */
2321 /* something changed, so look at all rules again */
2325 if (n != solv->nrules) /* ran into trouble? */
2328 break; /* unsolvable */
2329 continue; /* start over */
2332 /* decide leftover cleandeps packages */
2333 if (solv->cleandepsmap.size && solv->installed)
2335 for (p = solv->installed->start; p < solv->installed->end; p++)
2337 s = pool->solvables + p;
2338 if (s->repo != solv->installed)
2340 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2342 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2344 level = setpropagatelearn(solv, level, -p, 0, 0);
2349 if (p < solv->installed->end)
2353 /* at this point we have a consistent system. now do the extras... */
2355 if (!solv->decisioncnt_weak)
2356 solv->decisioncnt_weak = solv->decisionq.count;
2361 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2362 queue_empty(&dq); /* recommended packages */
2363 queue_empty(&dqs); /* supplemented packages */
2364 for (i = 1; i < pool->nsolvables; i++)
2366 if (solv->decisionmap[i] < 0)
2368 if (solv->decisionmap[i] > 0)
2370 /* installed, check for recommends */
2371 Id *recp, rec, pp, p;
2372 s = pool->solvables + i;
2373 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2375 /* XXX need to special case AND ? */
2378 recp = s->repo->idarraydata + s->recommends;
2379 while ((rec = *recp++) != 0)
2381 #ifdef ENABLE_COMPLEX_DEPS
2382 if (pool_is_complex_dep(pool, rec))
2384 add_complex_recommends(solv, rec, &dq, 0);
2389 FOR_PROVIDES(p, pp, rec)
2391 if (solv->decisionmap[p] > 0)
2396 else if (solv->decisionmap[p] == 0)
2398 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))))
2400 queue_pushunique(&dq, p);
2408 s = pool->solvables + i;
2409 if (!s->supplements)
2411 if (!pool_installable(pool, s))
2413 if (!solver_is_supplementing(solv, s))
2415 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2417 queue_push(&dqs, i);
2421 /* filter out all packages obsoleted by installed packages */
2422 /* this is no longer needed if we have reverse obsoletes */
2423 if ((dqs.count || dq.count) && solv->installed)
2426 Id obs, *obsp, po, ppo;
2428 map_init(&obsmap, pool->nsolvables);
2429 for (p = solv->installed->start; p < solv->installed->end; p++)
2431 s = pool->solvables + p;
2432 if (s->repo != solv->installed || !s->obsoletes)
2434 if (solv->decisionmap[p] <= 0)
2436 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
2438 obsp = s->repo->idarraydata + s->obsoletes;
2439 /* foreach obsoletes */
2440 while ((obs = *obsp++) != 0)
2441 FOR_PROVIDES(po, ppo, obs)
2442 MAPSET(&obsmap, po);
2444 for (i = j = 0; i < dqs.count; i++)
2445 if (!MAPTST(&obsmap, dqs.elements[i]))
2446 dqs.elements[j++] = dqs.elements[i];
2448 for (i = j = 0; i < dq.count; i++)
2449 if (!MAPTST(&obsmap, dq.elements[i]))
2450 dq.elements[j++] = dq.elements[i];
2455 /* filter out all already supplemented packages if requested */
2456 if (!solv->addalreadyrecommended && dqs.count)
2458 int dosplitprovides_old = solv->dosplitprovides;
2459 /* turn off all new packages */
2460 for (i = 0; i < solv->decisionq.count; i++)
2462 p = solv->decisionq.elements[i];
2465 s = pool->solvables + p;
2466 if (s->repo && s->repo != solv->installed)
2467 solv->decisionmap[p] = -solv->decisionmap[p];
2469 solv->dosplitprovides = 0;
2470 /* filter out old supplements */
2471 for (i = j = 0; i < dqs.count; i++)
2473 p = dqs.elements[i];
2474 s = pool->solvables + p;
2475 if (!s->supplements)
2477 if (!solver_is_supplementing(solv, s))
2478 dqs.elements[j++] = p;
2479 else if (solv->installsuppdepq && solver_check_installsuppdepq(solv, s))
2480 dqs.elements[j++] = p;
2483 /* undo turning off */
2484 for (i = 0; i < solv->decisionq.count; i++)
2486 p = solv->decisionq.elements[i];
2489 s = pool->solvables + p;
2490 if (s->repo && s->repo != solv->installed)
2491 solv->decisionmap[p] = -solv->decisionmap[p];
2493 solv->dosplitprovides = dosplitprovides_old;
2496 /* multiversion doesn't mix well with supplements.
2497 * filter supplemented packages where we already decided
2498 * to install a different version (see bnc#501088) */
2499 if (dqs.count && solv->multiversion.size)
2501 for (i = j = 0; i < dqs.count; i++)
2503 p = dqs.elements[i];
2504 if (MAPTST(&solv->multiversion, p))
2507 s = pool->solvables + p;
2508 FOR_PROVIDES(p2, pp2, s->name)
2509 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2512 continue; /* ignore this package */
2514 dqs.elements[j++] = p;
2519 /* make dq contain both recommended and supplemented pkgs */
2522 for (i = 0; i < dqs.count; i++)
2523 queue_pushunique(&dq, dqs.elements[i]);
2529 int decisioncount = solv->decisionq.count;
2533 /* simple case, just one package. no need to choose to best version */
2536 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2538 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2539 level = setpropagatelearn(solv, level, p, 0, 0);
2542 continue; /* back to main loop */
2545 /* filter packages, this gives us the best versions */
2546 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2548 /* create map of result */
2549 map_init(&dqmap, pool->nsolvables);
2550 for (i = 0; i < dq.count; i++)
2551 MAPSET(&dqmap, dq.elements[i]);
2553 /* install all supplemented packages */
2554 for (i = 0; i < dqs.count; i++)
2556 p = dqs.elements[i];
2557 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2559 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2561 level = setpropagatelearn(solv, level, p, 0, 0);
2562 if (level <= olevel)
2565 if (i < dqs.count || solv->decisionq.count < decisioncount)
2573 /* install all recommended packages */
2574 /* more work as we want to created branches if multiple
2575 * choices are valid */
2576 for (i = 0; i < decisioncount; i++)
2579 p = solv->decisionq.elements[i];
2582 s = pool->solvables + p;
2583 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2587 recp = s->repo->idarraydata + s->recommends;
2588 while ((rec = *recp++) != 0)
2591 #ifdef ENABLE_COMPLEX_DEPS
2592 if (pool_is_complex_dep(pool, rec))
2593 add_complex_recommends(solv, rec, &dq, &dqmap);
2596 FOR_PROVIDES(p, pp, rec)
2598 if (solv->decisionmap[p] > 0)
2603 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2610 /* multiple candidates, open a branch */
2611 for (i = 1; i < dq.count; i++)
2612 queue_push(&solv->branches, dq.elements[i]);
2613 queue_push(&solv->branches, -level);
2616 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2618 level = setpropagatelearn(solv, level, p, 0, 0);
2619 if (level <= olevel || solv->decisionq.count < decisioncount)
2620 break; /* we had to revert some decisions */
2623 break; /* had a problem above, quit loop */
2628 continue; /* back to main loop so that all deps are checked */
2632 if (!solv->decisioncnt_orphan)
2633 solv->decisioncnt_orphan = solv->decisionq.count;
2634 if (solv->dupmap_all && solv->installed)
2636 int installedone = 0;
2638 /* let's see if we can install some unsupported package */
2639 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2640 for (i = 0; i < solv->orphaned.count; i++)
2642 p = solv->orphaned.elements[i];
2643 if (solv->decisionmap[p])
2644 continue; /* already decided */
2645 if (solv->droporphanedmap_all)
2647 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2649 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2651 level = setpropagatelearn(solv, level, p, 0, 0);
2656 if (installedone || i < solv->orphaned.count)
2660 continue; /* back to main loop */
2662 for (i = 0; i < solv->orphaned.count; i++)
2664 p = solv->orphaned.elements[i];
2665 if (solv->decisionmap[p])
2666 continue; /* already decided */
2667 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2669 level = setpropagatelearn(solv, level, -p, 0, 0);
2673 if (i < solv->orphaned.count)
2677 continue; /* back to main loop */
2681 /* one final pass to make sure we decided all installed packages */
2682 if (solv->installed)
2684 for (p = solv->installed->start; p < solv->installed->end; p++)
2686 if (solv->decisionmap[p])
2687 continue; /* already decided */
2688 s = pool->solvables + p;
2689 if (s->repo != solv->installed)
2691 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2693 level = setpropagatelearn(solv, level, -p, 0, 0);
2697 if (p < solv->installed->end)
2701 continue; /* back to main loop */
2705 if (solv->installed && solv->cleandepsmap.size)
2707 if (cleandeps_check_mistakes(solv, level))
2709 level = 1; /* restart from scratch */
2710 systemlevel = level + 1;
2715 if (solv->solution_callback)
2717 solv->solution_callback(solv, solv->solution_callback_data);
2718 if (solv->branches.count)
2720 int i = solv->branches.count - 1;
2721 int l = -solv->branches.elements[i];
2725 if (solv->branches.elements[i - 1] < 0)
2727 p = solv->branches.elements[i];
2728 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2730 for (j = i + 1; j < solv->branches.count; j++)
2731 queue_push(&dq, solv->branches.elements[j]);
2732 solv->branches.count = i;
2734 revert(solv, level);
2736 for (j = 0; j < dq.count; j++)
2737 queue_push(&solv->branches, dq.elements[j]);
2739 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2741 level = setpropagatelearn(solv, level, p, disablerules, why);
2746 /* all branches done, we're finally finished */
2750 /* auto-minimization step */
2751 if (solv->branches.count)
2753 int l = 0, lasti = -1, lastl = -1;
2757 for (i = solv->branches.count - 1; i >= 0; i--)
2759 p = solv->branches.elements[i];
2762 else if (p > 0 && solv->decisionmap[p] > l + 1)
2770 /* kill old solvable so that we do not loop */
2771 p = solv->branches.elements[lasti];
2772 solv->branches.elements[lasti] = 0;
2773 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2774 minimizationsteps++;
2777 revert(solv, level);
2778 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2781 level = setpropagatelearn(solv, level, p, disablerules, why);
2784 continue; /* back to main loop */
2787 /* no minimization found, we're finally finished! */
2791 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2793 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2799 solv->decisioncnt_update = solv->decisionq.count;
2800 solv->decisioncnt_keep = solv->decisionq.count;
2801 solv->decisioncnt_resolve = solv->decisionq.count;
2802 solv->decisioncnt_weak = solv->decisionq.count;
2803 solv->decisioncnt_orphan = solv->decisionq.count;
2806 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2811 /*-------------------------------------------------------------------
2813 * remove disabled conflicts
2815 * purpose: update the decisionmap after some rules were disabled.
2816 * this is used to calculate the suggested/recommended package list.
2817 * Also returns a "removed" list to undo the discisionmap changes.
2821 removedisabledconflicts(Solver *solv, Queue *removed)
2823 Pool *pool = solv->pool;
2828 Id *decisionmap = solv->decisionmap;
2830 queue_empty(removed);
2831 for (i = 0; i < solv->decisionq.count; i++)
2833 p = solv->decisionq.elements[i];
2835 continue; /* conflicts only, please */
2836 why = solv->decisionq_why.elements[i];
2839 /* no rule involved, must be a orphan package drop */
2842 /* we never do conflicts on free decisions, so there
2843 * must have been an unit rule */
2845 r = solv->rules + why;
2846 if (r->d < 0 && decisionmap[-p])
2848 /* rule is now disabled, remove from decisionmap */
2849 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2850 queue_push(removed, -p);
2851 queue_push(removed, decisionmap[-p]);
2852 decisionmap[-p] = 0;
2855 if (!removed->count)
2857 /* we removed some confliced packages. some of them might still
2858 * be in conflict, so search for unit rules and re-conflict */
2860 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2862 if (i == solv->nrules)
2865 r = solv->rules + i;
2871 if (r->p < 0 && !decisionmap[-r->p])
2877 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2879 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2884 if (r->p < 0 && decisionmap[-r->p] == 0)
2886 if (new || DECISIONMAP_FALSE(r->p))
2888 dp = pool->whatprovidesdata + r->d;
2889 while ((p = *dp++) != 0)
2891 if (new && p == new)
2893 if (p < 0 && decisionmap[-p] == 0)
2902 else if (!DECISIONMAP_FALSE(p))
2912 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2913 decisionmap[-new] = -1;
2915 n = 0; /* redo all rules */
2921 undo_removedisabledconflicts(Solver *solv, Queue *removed)
2924 for (i = 0; i < removed->count; i += 2)
2925 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
2929 /*-------------------------------------------------------------------
2931 * weaken solvable dependencies
2935 weaken_solvable_deps(Solver *solv, Id p)
2940 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
2944 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2945 continue; /* conflict */
2946 queue_push(&solv->weakruleq, i);
2951 /********************************************************************/
2956 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
2959 Id how, what, select;
2961 for (i = 0; i < job->count; i += 2)
2963 how = job->elements[i];
2964 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
2966 what = job->elements[i + 1];
2967 select = how & SOLVER_SELECTMASK;
2968 if (!multiversionmap->size)
2969 map_grow(multiversionmap, pool->nsolvables);
2970 if (select == SOLVER_SOLVABLE_ALL)
2972 FOR_POOL_SOLVABLES(p)
2973 MAPSET(multiversionmap, p);
2975 else if (select == SOLVER_SOLVABLE_REPO)
2978 Repo *repo = pool_id2repo(pool, what);
2980 FOR_REPO_SOLVABLES(repo, p, s)
2981 MAPSET(multiversionmap, p);
2983 FOR_JOB_SELECT(p, pp, select, what)
2984 MAPSET(multiversionmap, p);
2989 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
2991 solver_calculate_multiversionmap(pool, job, multiversionmap);
2995 * add a rule created by a job, record job number and weak flag
2998 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
3000 solver_addrule(solv, p, d);
3001 queue_push(&solv->ruletojob, job);
3003 queue_push(&solv->weakruleq, solv->nrules - 1);
3007 add_cleandeps_package(Solver *solv, Id p)
3009 if (!solv->cleandeps_updatepkgs)
3011 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3012 queue_init(solv->cleandeps_updatepkgs);
3014 queue_pushunique(solv->cleandeps_updatepkgs, p);
3018 add_update_target(Solver *solv, Id p, Id how)
3020 Pool *pool = solv->pool;
3021 Solvable *s = pool->solvables + p;
3022 Repo *installed = solv->installed;
3024 if (!solv->update_targets)
3026 solv->update_targets = solv_calloc(1, sizeof(Queue));
3027 queue_init(solv->update_targets);
3029 if (s->repo == installed)
3031 queue_push2(solv->update_targets, p, p);
3034 FOR_PROVIDES(pi, pip, s->name)
3036 Solvable *si = pool->solvables + pi;
3037 if (si->repo != installed || si->name != s->name)
3039 if (how & SOLVER_FORCEBEST)
3041 if (!solv->bestupdatemap.size)
3042 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3043 MAPSET(&solv->bestupdatemap, pi - installed->start);
3045 if (how & SOLVER_CLEANDEPS)
3046 add_cleandeps_package(solv, pi);
3047 queue_push2(solv->update_targets, pi, p);
3048 /* check if it's ok to keep the installed package */
3049 if (s->evr == si->evr && solvable_identical(s, si))
3050 queue_push2(solv->update_targets, pi, pi);
3054 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3055 while ((obs = *obsp++) != 0)
3057 FOR_PROVIDES(pi, pip, obs)
3059 Solvable *si = pool->solvables + pi;
3060 if (si->repo != installed)
3062 if (si->name == s->name)
3063 continue; /* already handled above */
3064 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3066 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3068 if (how & SOLVER_FORCEBEST)
3070 if (!solv->bestupdatemap.size)
3071 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3072 MAPSET(&solv->bestupdatemap, pi - installed->start);
3074 if (how & SOLVER_CLEANDEPS)
3075 add_cleandeps_package(solv, pi);
3076 queue_push2(solv->update_targets, pi, p);
3083 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3093 transform_update_targets(Solver *solv)
3095 Repo *installed = solv->installed;
3096 Queue *update_targets = solv->update_targets;
3098 Id p, q, lastp, lastq;
3100 if (!update_targets->count)
3102 queue_free(update_targets);
3103 solv->update_targets = solv_free(update_targets);
3106 if (update_targets->count > 2)
3107 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3108 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3110 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3112 if ((p = update_targets->elements[i]) != lastp)
3114 if (!solv->updatemap.size)
3115 map_grow(&solv->updatemap, installed->end - installed->start);
3116 MAPSET(&solv->updatemap, p - installed->start);
3117 update_targets->elements[j++] = 0; /* finish old set */
3118 update_targets->elements[p - installed->start] = j; /* start new set */
3122 if ((q = update_targets->elements[i + 1]) != lastq)
3124 update_targets->elements[j++] = q;
3128 queue_truncate(update_targets, j);
3129 queue_push(update_targets, 0); /* finish last set */
3134 addedmap2deduceq(Solver *solv, Map *addedmap)
3136 Pool *pool = solv->pool;
3141 queue_empty(&solv->addedmap_deduceq);
3142 for (i = 2, j = solv->rpmrules_end - 1; i < pool->nsolvables && j > 0; j--)
3144 r = solv->rules + j;
3147 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3150 if (!MAPTST(addedmap, p))
3152 /* should never happen, but... */
3153 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3154 queue_push(&solv->addedmap_deduceq, -p);
3158 if (MAPTST(addedmap, i))
3159 queue_push(&solv->addedmap_deduceq, i);
3163 for (; i < pool->nsolvables; i++)
3164 if (MAPTST(addedmap, i))
3165 queue_push(&solv->addedmap_deduceq, i);
3167 for (i = 2; i < pool->nsolvables; i++)
3168 if (MAPTST(addedmap, i))
3173 deduceq2addedmap(Solver *solv, Map *addedmap)
3178 for (j = solv->rpmrules_end - 1; j > 0; j--)
3180 r = solv->rules + j;
3181 if (r->d < 0 && r->p)
3182 solver_enablerule(solv, r);
3185 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3188 MAPSET(addedmap, p);
3190 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3192 p = solv->addedmap_deduceq.elements[j];
3194 MAPSET(addedmap, p);
3196 MAPCLR(addedmap, p);
3208 solver_solve(Solver *solv, Queue *job)
3210 Pool *pool = solv->pool;
3211 Repo *installed = solv->installed;
3213 int oldnrules, initialnrules;
3214 Map addedmap; /* '1' == have rpm-rules for solvable */
3215 Map installcandidatemap;
3216 Id how, what, select, name, weak, p, pp, d;
3220 int now, solve_start;
3222 int hasbestinstalljob = 0;
3224 solve_start = solv_timems(0);
3226 /* log solver options */
3227 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3228 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3229 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);
3230 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3231 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3232 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3234 /* create whatprovides if not already there */
3235 if (!pool->whatprovides)
3236 pool_createwhatprovides(pool);
3238 /* create obsolete index */
3239 policy_create_obsolete_index(solv);
3242 queue_free(&solv->job);
3243 queue_init_clone(&solv->job, job);
3244 solv->pooljobcnt = pool->pooljobs.count;
3245 if (pool->pooljobs.count)
3246 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3249 /* free old stuff in jase we re-run a solver */
3250 queuep_free(&solv->update_targets);
3251 queuep_free(&solv->cleandeps_updatepkgs);
3252 queue_empty(&solv->ruleassertions);
3253 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3254 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3255 if (solv->noupdate.size)
3256 map_empty(&solv->noupdate);
3257 map_zerosize(&solv->multiversion);
3258 solv->updatemap_all = 0;
3259 map_zerosize(&solv->updatemap);
3260 solv->bestupdatemap_all = 0;
3261 map_zerosize(&solv->bestupdatemap);
3262 solv->fixmap_all = 0;
3263 map_zerosize(&solv->fixmap);
3264 solv->dupmap_all = 0;
3265 map_zerosize(&solv->dupmap);
3266 map_zerosize(&solv->dupinvolvedmap);
3267 solv->droporphanedmap_all = 0;
3268 map_zerosize(&solv->droporphanedmap);
3269 map_zerosize(&solv->cleandepsmap);
3270 map_zerosize(&solv->weakrulemap);
3271 queue_empty(&solv->weakruleq);
3272 solv->watches = solv_free(solv->watches);
3273 queue_empty(&solv->ruletojob);
3274 if (solv->decisionq.count)
3275 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3276 queue_empty(&solv->decisionq);
3277 queue_empty(&solv->decisionq_why);
3278 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3279 queue_empty(&solv->learnt_why);
3280 queue_empty(&solv->learnt_pool);
3281 queue_empty(&solv->branches);
3282 solv->propagate_index = 0;
3283 queue_empty(&solv->problems);
3284 queue_empty(&solv->solutions);
3285 queue_empty(&solv->orphaned);
3286 solv->stats_learned = solv->stats_unsolvable = 0;
3287 if (solv->recommends_index)
3289 map_empty(&solv->recommendsmap);
3290 map_empty(&solv->suggestsmap);
3291 queuep_free(&solv->recommendscplxq);
3292 queuep_free(&solv->suggestscplxq);
3293 solv->recommends_index = 0;
3295 solv->specialupdaters = solv_free(solv->specialupdaters);
3299 * create basic rule set of all involved packages
3300 * use addedmap bitmap to make sure we don't create rules twice
3303 /* create multiversion map if needed */
3304 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3306 map_init(&addedmap, pool->nsolvables);
3307 MAPSET(&addedmap, SYSTEMSOLVABLE);
3309 map_init(&installcandidatemap, pool->nsolvables);
3312 now = solv_timems(0);
3314 * create rules for all package that could be involved with the solving
3315 * so called: rpm rules
3318 initialnrules = solv->rpmrules_end ? solv->rpmrules_end : 1;
3319 if (initialnrules > 1)
3320 deduceq2addedmap(solv, &addedmap);
3321 if (solv->nrules != initialnrules)
3322 solver_shrinkrules(solv, initialnrules);
3323 solv->nrules = initialnrules;
3324 solv->rpmrules_end = 0;
3328 /* check for update/verify jobs as they need to be known early */
3329 for (i = 0; i < job->count; i += 2)
3331 how = job->elements[i];
3332 what = job->elements[i + 1];
3333 select = how & SOLVER_SELECTMASK;
3334 switch (how & SOLVER_JOBMASK)
3337 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3338 solv->fixmap_all = 1;
3339 FOR_JOB_SELECT(p, pp, select, what)
3341 s = pool->solvables + p;
3342 if (s->repo != installed)
3344 if (!solv->fixmap.size)
3345 map_grow(&solv->fixmap, installed->end - installed->start);
3346 MAPSET(&solv->fixmap, p - installed->start);
3350 if (select == SOLVER_SOLVABLE_ALL)
3352 solv->updatemap_all = 1;
3353 if (how & SOLVER_FORCEBEST)
3354 solv->bestupdatemap_all = 1;
3355 if (how & SOLVER_CLEANDEPS)
3357 FOR_REPO_SOLVABLES(installed, p, s)
3358 add_cleandeps_package(solv, p);
3361 else if (select == SOLVER_SOLVABLE_REPO)
3363 Repo *repo = pool_id2repo(pool, what);
3366 if (repo == installed && !(how & SOLVER_TARGETED))
3368 solv->updatemap_all = 1;
3369 if (how & SOLVER_FORCEBEST)
3370 solv->bestupdatemap_all = 1;
3371 if (how & SOLVER_CLEANDEPS)
3373 FOR_REPO_SOLVABLES(installed, p, s)
3374 add_cleandeps_package(solv, p);
3378 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3380 /* targeted update */
3381 FOR_REPO_SOLVABLES(repo, p, s)
3382 add_update_target(solv, p, how);
3386 if (!(how & SOLVER_TARGETED))
3389 FOR_JOB_SELECT(p, pp, select, what)
3391 s = pool->solvables + p;
3392 if (s->repo != installed)
3394 if (!solv->updatemap.size)
3395 map_grow(&solv->updatemap, installed->end - installed->start);
3396 MAPSET(&solv->updatemap, p - installed->start);
3397 if (how & SOLVER_FORCEBEST)
3399 if (!solv->bestupdatemap.size)
3400 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3401 MAPSET(&solv->bestupdatemap, p - installed->start);
3403 if (how & SOLVER_CLEANDEPS)
3404 add_cleandeps_package(solv, p);
3407 if (!targeted || solv->noautotarget)
3410 FOR_JOB_SELECT(p, pp, select, what)
3411 add_update_target(solv, p, how);
3419 if (solv->update_targets)
3420 transform_update_targets(solv);
3422 oldnrules = solv->nrules;
3423 FOR_REPO_SOLVABLES(installed, p, s)
3424 solver_addrpmrulesforsolvable(solv, s, &addedmap);
3425 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3426 oldnrules = solv->nrules;
3427 FOR_REPO_SOLVABLES(installed, p, s)
3428 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
3429 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3433 * create rules for all packages involved in the job
3434 * (to be installed or removed)
3437 oldnrules = solv->nrules;
3438 for (i = 0; i < job->count; i += 2)
3440 how = job->elements[i];
3441 what = job->elements[i + 1];
3442 select = how & SOLVER_SELECTMASK;
3444 switch (how & SOLVER_JOBMASK)
3446 case SOLVER_INSTALL:
3447 FOR_JOB_SELECT(p, pp, select, what)
3449 MAPSET(&installcandidatemap, p);
3450 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3453 case SOLVER_DISTUPGRADE:
3454 if (select == SOLVER_SOLVABLE_ALL)
3456 solv->dupmap_all = 1;
3457 solv->updatemap_all = 1;
3458 if (how & SOLVER_FORCEBEST)
3459 solv->bestupdatemap_all = 1;
3461 if (!solv->dupmap_all)
3468 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3472 * add rules for suggests, enhances
3474 oldnrules = solv->nrules;
3475 solver_addrpmrulesforweak(solv, &addedmap);
3476 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3478 #ifdef ENABLE_LINKED_PKGS
3479 oldnrules = solv->nrules;
3480 solver_addrpmrulesforlinked(solv, &addedmap);
3481 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of linked packages\n", solv->nrules - oldnrules);
3485 * first pass done, we now have all the rpm rules we need.
3486 * unify existing rules before going over all job rules and
3488 * at this point the system is always solvable,
3489 * as an empty system (remove all packages) is a valid solution
3492 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3494 int possible = 0, installable = 0;
3495 for (i = 1; i < pool->nsolvables; i++)
3497 if (pool_installable(pool, pool->solvables + i))
3499 if (MAPTST(&addedmap, i))
3502 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3505 if (solv->nrules > initialnrules)
3506 solver_unifyrules(solv); /* remove duplicate rpm rules */
3507 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
3509 if (solv->nrules > initialnrules)
3510 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3512 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3513 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
3515 /* create dup maps if needed. We need the maps early to create our
3518 solver_createdupmaps(solv);
3521 * create feature rules
3523 * foreach installed:
3524 * create assertion (keep installed, if no update available)
3526 * create update rule (A|update1(A)|update2(A)|...)
3528 * those are used later on to keep a version of the installed packages in
3532 solv->featurerules = solv->nrules; /* mark start of feature rules */
3535 /* foreach possibly installed solvable */
3536 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3538 if (s->repo != installed)
3540 solver_addrule(solv, 0, 0); /* create dummy rule */
3543 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3545 /* make sure we accounted for all rules */
3546 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3548 solv->featurerules_end = solv->nrules;
3551 * Add update rules for installed solvables
3553 * almost identical to feature rules
3554 * except that downgrades/archchanges/vendorchanges are not allowed
3557 solv->updaterules = solv->nrules;
3560 { /* foreach installed solvables */
3561 /* we create all update rules, but disable some later on depending on the job */
3562 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3566 if (s->repo != installed)
3568 solver_addrule(solv, 0, 0); /* create dummy rule */
3571 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3573 * check for and remove duplicate
3575 r = solv->rules + solv->nrules - 1; /* r: update rule */
3576 sr = r - (installed->end - installed->start); /* sr: feature rule */
3577 /* it's orphaned if there is no feature rule or the feature rule
3578 * consists just of the installed package */
3579 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
3580 queue_push(&solv->orphaned, i);
3583 /* assert(solv->dupmap_all && !sr->p); */
3586 if (!solver_rulecmp(solv, r, sr))
3587 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3589 solver_disablerule(solv, sr); /* disable feature rule */
3591 /* consistency check: we added a rule for _every_ installed solvable */
3592 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3594 solv->updaterules_end = solv->nrules;
3598 * now add all job rules
3601 solv->jobrules = solv->nrules;
3602 for (i = 0; i < job->count; i += 2)
3604 oldnrules = solv->nrules;
3606 if (i && i == solv->pooljobcnt)
3607 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3608 how = job->elements[i];
3609 what = job->elements[i + 1];
3610 weak = how & SOLVER_WEAK;
3611 select = how & SOLVER_SELECTMASK;
3612 switch (how & SOLVER_JOBMASK)
3614 case SOLVER_INSTALL:
3615 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3616 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3617 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3618 if (select == SOLVER_SOLVABLE)
3626 FOR_JOB_SELECT(p, pp, select, what)
3630 if (select == SOLVER_SOLVABLE_ONE_OF)
3631 break; /* ignore empty installs */
3632 /* no candidate found or unsupported, make this an impossible rule */
3633 queue_push(&q, -SYSTEMSOLVABLE);
3635 p = queue_shift(&q); /* get first candidate */
3636 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3638 /* force install of namespace supplements hack */
3639 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3641 Reldep *rd = GETRELDEP(pool, what);
3642 if (rd->flags == REL_NAMESPACE)
3645 if (!solv->installsuppdepq)
3647 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3648 queue_init(solv->installsuppdepq);
3650 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3653 solver_addjobrule(solv, p, d, i, weak);
3654 if (how & SOLVER_FORCEBEST)
3655 hasbestinstalljob = 1;
3658 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3659 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3660 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3661 /* specific solvable: by id or by nevra */
3662 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3663 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3665 FOR_POOL_SOLVABLES(p)
3666 solver_addjobrule(solv, -p, 0, i, weak);
3668 else if (select == SOLVER_SOLVABLE_REPO)
3670 Repo *repo = pool_id2repo(pool, what);
3672 FOR_REPO_SOLVABLES(repo, p, s)
3673 solver_addjobrule(solv, -p, 0, i, weak);
3675 FOR_JOB_SELECT(p, pp, select, what)
3677 s = pool->solvables + p;
3678 if (installed && s->repo == installed)
3679 name = !name ? s->name : -1;
3680 solver_addjobrule(solv, -p, 0, i, weak);
3682 /* special case for "erase a specific solvable": we also
3683 * erase all other solvables with that name, so that they
3684 * don't get picked up as replacement.
3685 * name is > 0 if exactly one installed solvable matched.
3687 /* XXX: look also at packages that obsolete this package? */
3692 FOR_PROVIDES(p, pp, name)
3694 s = pool->solvables + p;
3695 if (s->name != name)
3697 /* keep other versions installed */
3698 if (s->repo == installed)
3700 /* keep installcandidates of other jobs */
3701 if (MAPTST(&installcandidatemap, p))
3703 /* don't add the same rule twice */
3704 for (j = oldnrules; j < k; j++)
3705 if (solv->rules[j].p == -p)
3708 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
3714 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3717 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3719 case SOLVER_WEAKENDEPS:
3720 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3721 if (select != SOLVER_SOLVABLE)
3723 s = pool->solvables + what;
3724 weaken_solvable_deps(solv, what);
3726 case SOLVER_MULTIVERSION:
3727 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3730 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3731 if (select == SOLVER_SOLVABLE_ALL)
3733 FOR_POOL_SOLVABLES(p)
3734 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3736 else if (select == SOLVER_SOLVABLE_REPO)
3738 Repo *repo = pool_id2repo(pool, what);
3740 FOR_REPO_SOLVABLES(repo, p, s)
3741 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3743 FOR_JOB_SELECT(p, pp, select, what)
3744 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3746 case SOLVER_DISTUPGRADE:
3747 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3749 case SOLVER_DROP_ORPHANED:
3750 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3751 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3752 solv->droporphanedmap_all = 1;
3753 FOR_JOB_SELECT(p, pp, select, what)
3755 s = pool->solvables + p;
3756 if (!installed || s->repo != installed)
3758 if (!solv->droporphanedmap.size)
3759 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3760 MAPSET(&solv->droporphanedmap, p - installed->start);
3763 case SOLVER_USERINSTALLED:
3764 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3767 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3775 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3778 if (solv->nrules == oldnrules)
3779 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3780 for (j = oldnrules; j < solv->nrules; j++)
3782 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3783 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3787 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3788 solv->jobrules_end = solv->nrules;
3790 /* now create infarch and dup rules */
3791 if (!solv->noinfarchcheck)
3793 solver_addinfarchrules(solv, &addedmap);
3795 if (pool->implicitobsoleteusescolors)
3797 /* currently doesn't work well with infarch rules, so make
3799 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3800 queue_push(&solv->weakruleq, i);
3805 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3808 solver_addduprules(solv, &addedmap);
3810 solv->duprules = solv->duprules_end = solv->nrules;
3812 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3813 solver_addbestrules(solv, hasbestinstalljob);
3815 solv->bestrules = solv->bestrules_end = solv->nrules;
3818 solver_freedupmaps(solv); /* no longer needed */
3821 solver_addchoicerules(solv);
3823 solv->choicerules = solv->choicerules_end = solv->nrules;
3827 for (i = solv->featurerules; i < solv->nrules; i++)
3828 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3830 /* all rules created
3831 * --------------------------------------------------------------
3832 * prepare for solving
3835 /* free unneeded memory */
3836 map_free(&addedmap);
3837 map_free(&installcandidatemap);
3840 POOL_DEBUG(SOLV_DEBUG_STATS, "%d rpm rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->rpmrules_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);
3841 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3843 /* create weak map */
3844 map_init(&solv->weakrulemap, solv->nrules);
3845 for (i = 0; i < solv->weakruleq.count; i++)
3847 p = solv->weakruleq.elements[i];
3848 MAPSET(&solv->weakrulemap, p);
3851 /* enable cleandepsmap creation if we have updatepkgs */
3852 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
3853 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3855 if (solv->cleandeps_mistakes)
3857 queue_free(solv->cleandeps_mistakes);
3858 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3861 /* all new rules are learnt after this point */
3862 solv->learntrules = solv->nrules;
3864 /* create watches chains */
3867 /* create assertion index. it is only used to speed up
3868 * makeruledecsions() a bit */
3869 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3870 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3871 queue_push(&solv->ruleassertions, i);
3873 /* disable update rules that conflict with our job */
3874 solver_disablepolicyrules(solv);
3876 /* make initial decisions based on assertion rules */
3877 makeruledecisions(solv);
3878 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3881 * ********************************************
3883 * ********************************************
3886 now = solv_timems(0);
3887 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3888 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3891 * prepare solution queue if there were problems
3893 solver_prepare_solutions(solv);
3895 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);
3896 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3898 /* return number of problems */
3899 return solv->problems.count ? solv->problems.count / 2 : 0;
3903 solver_create_transaction(Solver *solv)
3905 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
3908 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3910 queue_free(orphanedq);
3911 queue_init_clone(orphanedq, &solv->orphaned);
3914 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
3916 Pool *pool = solv->pool;
3917 Queue redoq, disabledq;
3923 if (!recommendationsq && !suggestionsq)
3926 map_init(&obsmap, pool->nsolvables);
3927 if (solv->installed)
3929 Id obs, *obsp, p, po, ppo;
3930 for (p = solv->installed->start; p < solv->installed->end; p++)
3932 s = pool->solvables + p;
3933 if (s->repo != solv->installed || !s->obsoletes)
3935 if (solv->decisionmap[p] <= 0)
3937 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
3939 obsp = s->repo->idarraydata + s->obsoletes;
3940 /* foreach obsoletes */
3941 while ((obs = *obsp++) != 0)
3942 FOR_PROVIDES(po, ppo, obs)
3943 MAPSET(&obsmap, po);
3948 queue_init(&disabledq);
3950 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3951 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
3953 if (r->d < 0) /* disabled ? */
3955 if (r->p >= 0) /* install job? */
3957 queue_push(&disabledq, i);
3958 solver_disablerule(solv, r);
3964 enabledisablelearntrules(solv);
3965 removedisabledconflicts(solv, &redoq);
3969 * find recommended packages
3971 if (recommendationsq)
3973 Id rec, *recp, p, pp;
3975 queue_empty(recommendationsq);
3976 /* create map of all recommened packages */
3977 solv->recommends_index = -1;
3978 MAPZERO(&solv->recommendsmap);
3980 /* put all packages the solver already chose in the map */
3981 if (solv->decisioncnt_weak)
3983 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
3986 why = solv->decisionq_why.elements[i];
3988 continue; /* forced by unit rule or dep resolving */
3989 p = solv->decisionq.elements[i];
3992 MAPSET(&solv->recommendsmap, p);
3996 for (i = 0; i < solv->decisionq.count; i++)
3998 p = solv->decisionq.elements[i];
4001 s = pool->solvables + p;
4004 recp = s->repo->idarraydata + s->recommends;
4005 while ((rec = *recp++) != 0)
4007 #ifdef ENABLE_COMPLEX_DEPS
4008 if (pool_is_complex_dep(pool, rec))
4010 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4014 FOR_PROVIDES(p, pp, rec)
4015 if (solv->decisionmap[p] > 0)
4021 FOR_PROVIDES(p, pp, rec)
4022 if (solv->decisionmap[p] > 0)
4023 MAPSET(&solv->recommendsmap, p);
4025 continue; /* p != 0: already fulfilled */
4027 FOR_PROVIDES(p, pp, rec)
4028 MAPSET(&solv->recommendsmap, p);
4032 for (i = 1; i < pool->nsolvables; i++)
4034 if (solv->decisionmap[i] < 0)
4036 if (solv->decisionmap[i] > 0 && noselected)
4038 if (MAPTST(&obsmap, i))
4040 s = pool->solvables + i;
4041 if (!MAPTST(&solv->recommendsmap, i))
4043 if (!s->supplements)
4045 if (!pool_installable(pool, s))
4047 if (!solver_is_supplementing(solv, s))
4050 queue_push(recommendationsq, i);
4052 /* we use MODE_SUGGEST here so that repo prio is ignored */
4053 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4057 * find suggested packages
4062 Id sug, *sugp, p, pp;
4064 queue_empty(suggestionsq);
4065 /* create map of all suggests that are still open */
4066 solv->recommends_index = -1;
4067 MAPZERO(&solv->suggestsmap);
4068 for (i = 0; i < solv->decisionq.count; i++)
4070 p = solv->decisionq.elements[i];
4073 s = pool->solvables + p;
4076 sugp = s->repo->idarraydata + s->suggests;
4077 while ((sug = *sugp++) != 0)
4079 #ifdef ENABLE_COMPLEX_DEPS
4080 if (pool_is_complex_dep(pool, sug))
4082 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4086 FOR_PROVIDES(p, pp, sug)
4087 if (solv->decisionmap[p] > 0)
4093 FOR_PROVIDES(p, pp, sug)
4094 if (solv->decisionmap[p] > 0)
4095 MAPSET(&solv->suggestsmap, p);
4097 continue; /* already fulfilled */
4099 FOR_PROVIDES(p, pp, sug)
4100 MAPSET(&solv->suggestsmap, p);
4104 for (i = 1; i < pool->nsolvables; i++)
4106 if (solv->decisionmap[i] < 0)
4108 if (solv->decisionmap[i] > 0 && noselected)
4110 if (MAPTST(&obsmap, i))
4112 s = pool->solvables + i;
4113 if (!MAPTST(&solv->suggestsmap, i))
4117 if (!pool_installable(pool, s))
4119 if (!solver_is_enhancing(solv, s))
4122 queue_push(suggestionsq, i);
4124 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4127 /* undo removedisabledconflicts */
4129 undo_removedisabledconflicts(solv, &redoq);
4132 /* undo job rule disabling */
4133 for (i = 0; i < disabledq.count; i++)
4134 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4135 queue_free(&disabledq);
4140 /***********************************************************************/
4141 /* disk usage computations */
4143 /*-------------------------------------------------------------------
4145 * calculate DU changes
4149 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4153 solver_create_state_maps(solv, &installedmap, 0);
4154 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4155 map_free(&installedmap);
4159 /*-------------------------------------------------------------------
4161 * calculate changes in install size
4165 solver_calc_installsizechange(Solver *solv)
4170 solver_create_state_maps(solv, &installedmap, 0);
4171 change = pool_calc_installsizechange(solv->pool, &installedmap);
4172 map_free(&installedmap);
4177 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4179 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4183 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4185 Pool *pool = solv->pool;
4188 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4189 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4190 for (i = 0; i < res->count; i++)
4191 if (res->elements[i] != -1)
4193 Solvable *s = pool->solvables + pkgs->elements[i];
4194 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4195 res->elements[i] = -1;
4197 map_free(&installedmap);
4200 /*-------------------------------------------------------------------
4202 * decision introspection
4206 solver_get_decisionlevel(Solver *solv, Id p)
4208 return solv->decisionmap[p];
4212 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4214 queue_free(decisionq);
4215 queue_init_clone(decisionq, &solv->decisionq);
4219 solver_get_lastdecisionblocklevel(Solver *solv)
4222 if (solv->decisionq.count == 0)
4224 p = solv->decisionq.elements[solv->decisionq.count - 1];
4227 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4231 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4236 queue_empty(decisionq);
4237 for (i = 0; i < solv->decisionq.count; i++)
4239 p = solv->decisionq.elements[i];
4242 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4245 if (i == solv->decisionq.count)
4247 for (i = 0; i < solv->decisionq.count; i++)
4249 p = solv->decisionq.elements[i];
4252 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4253 queue_push(decisionq, p);
4260 solver_describe_decision(Solver *solv, Id p, Id *infop)
4267 if (!solv->decisionmap[p])
4268 return SOLVER_REASON_UNRELATED;
4269 pp = solv->decisionmap[p] < 0 ? -p : p;
4270 for (i = 0; i < solv->decisionq.count; i++)
4271 if (solv->decisionq.elements[i] == pp)
4273 if (i == solv->decisionq.count) /* just in case... */
4274 return SOLVER_REASON_UNRELATED;
4275 why = solv->decisionq_why.elements[i];
4277 *infop = why > 0 ? why : -why;
4279 return SOLVER_REASON_UNIT_RULE;
4281 if (i < solv->decisioncnt_update)
4284 return SOLVER_REASON_KEEP_INSTALLED;
4285 return SOLVER_REASON_RESOLVE_JOB;
4287 if (i < solv->decisioncnt_keep)
4289 if (why == 0 && pp < 0)
4290 return SOLVER_REASON_CLEANDEPS_ERASE;
4291 return SOLVER_REASON_UPDATE_INSTALLED;
4293 if (i < solv->decisioncnt_resolve)
4295 if (why == 0 && pp < 0)
4296 return SOLVER_REASON_CLEANDEPS_ERASE;
4297 return SOLVER_REASON_KEEP_INSTALLED;
4300 return SOLVER_REASON_RESOLVE;
4301 /* weak or orphaned */
4302 if (solv->decisionq.count < solv->decisioncnt_orphan)
4303 return SOLVER_REASON_WEAKDEP;
4304 return SOLVER_REASON_RESOLVE_ORPHAN;
4309 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4311 Pool *pool = solv->pool;
4313 int level = solv->decisionmap[p];
4320 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4321 if (solv->decisionq.elements[decisionno] == p)
4323 if (decisionno == solv->decisionq.count)
4325 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4328 /* 1) list all packages that recommend us */
4329 for (i = 1; i < pool->nsolvables; i++)
4331 Id *recp, rec, pp2, p2;
4332 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4334 s = pool->solvables + i;
4337 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4339 recp = s->repo->idarraydata + s->recommends;
4340 while ((rec = *recp++) != 0)
4343 FOR_PROVIDES(p2, pp2, rec)
4349 /* if p2 is already installed, this recommends is ignored */
4350 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4356 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4357 queue_push2(whyq, p2, rec);
4361 /* 2) list all supplements */
4362 s = pool->solvables + p;
4363 if (s->supplements && level > 0)
4365 Id *supp, sup, pp2, p2;
4366 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4367 * everything above our level in the decisionmap */
4368 for (i = decisionno; i < solv->decisionq.count; i++ )
4370 p2 = solv->decisionq.elements[i];
4372 solv->decisionmap[p2] = -solv->decisionmap[p2];
4374 supp = s->repo->idarraydata + s->supplements;
4375 while ((sup = *supp++) != 0)
4376 if (solver_dep_fulfilled(solv, sup))
4379 /* let's see if this is an easy supp */
4380 FOR_PROVIDES(p2, pp2, sup)
4382 if (!solv->addalreadyrecommended && solv->installed)
4384 if (pool->solvables[p2].repo == solv->installed)
4387 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4389 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4390 queue_push2(whyq, p2, sup);
4396 /* hard case, just note dependency with no package */
4397 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4398 queue_push2(whyq, 0, sup);
4401 for (i = decisionno; i < solv->decisionq.count; i++)
4403 p2 = solv->decisionq.elements[i];
4405 solv->decisionmap[p2] = -solv->decisionmap[p2];
4411 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4414 how &= SOLVER_SELECTMASK;
4416 if (how == SOLVER_SOLVABLE_ALL)
4418 FOR_POOL_SOLVABLES(p)
4419 queue_push(pkgs, p);
4421 else if (how == SOLVER_SOLVABLE_REPO)
4423 Repo *repo = pool_id2repo(pool, what);
4426 FOR_REPO_SOLVABLES(repo, p, s)
4427 queue_push(pkgs, p);
4431 FOR_JOB_SELECT(p, pp, how, what)
4432 queue_push(pkgs, p);
4437 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4440 Id select = how & SOLVER_SELECTMASK;
4441 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4443 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4445 if (!pool->installed)
4447 FOR_JOB_SELECT(p, pp, select, what)
4448 if (pool->solvables[p].repo == pool->installed)
4451 FOR_JOB_SELECT(p, pp, select, what)
4453 Solvable *s = pool->solvables + p;
4454 FOR_PROVIDES(pi, pip, s->name)
4456 Solvable *si = pool->solvables + pi;
4457 if (si->repo != pool->installed || si->name != s->name)
4463 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4464 while ((obs = *obsp++) != 0)
4466 FOR_PROVIDES(pi, pip, obs)
4468 Solvable *si = pool->solvables + pi;
4469 if (si->repo != pool->installed)
4471 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4473 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4484 solver_select2str(Pool *pool, Id select, Id what)
4488 select &= SOLVER_SELECTMASK;
4489 if (select == SOLVER_SOLVABLE)
4490 return pool_solvid2str(pool, what);
4491 if (select == SOLVER_SOLVABLE_NAME)
4492 return pool_dep2str(pool, what);
4493 if (select == SOLVER_SOLVABLE_PROVIDES)
4495 s = pool_dep2str(pool, what);
4496 b = pool_alloctmpspace(pool, 11 + strlen(s));
4497 sprintf(b, "providing %s", s);
4500 if (select == SOLVER_SOLVABLE_ONE_OF)
4504 while ((p = pool->whatprovidesdata[what++]) != 0)
4506 s = pool_solvid2str(pool, p);
4508 b = pool_tmpappend(pool, b, ", ", s);
4510 b = pool_tmpjoin(pool, s, 0, 0);
4511 pool_freetmpspace(pool, s);
4513 return b ? b : "nothing";
4515 if (select == SOLVER_SOLVABLE_REPO)
4517 b = pool_alloctmpspace(pool, 20);
4518 sprintf(b, "repo #%d", what);
4521 if (select == SOLVER_SOLVABLE_ALL)
4522 return "all packages";
4523 return "unknown job select";
4527 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
4529 Id select = how & SOLVER_SELECTMASK;
4530 const char *strstart = 0, *strend = 0;
4534 switch (how & SOLVER_JOBMASK)
4537 return "do nothing";
4538 case SOLVER_INSTALL:
4539 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
4540 strstart = "keep ", strend = " installed";
4541 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
4542 strstart = "install ";
4543 else if (select == SOLVER_SOLVABLE_PROVIDES)
4544 strstart = "install a package ";
4546 strstart = "install one of ";
4549 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
4550 strstart = "keep ", strend = " uninstalled";
4551 else if (select == SOLVER_SOLVABLE_PROVIDES)
4552 strstart = "deinstall all packages ";
4554 strstart = "deinstall ";
4557 strstart = "update ";
4559 case SOLVER_WEAKENDEPS:
4560 strstart = "weaken deps of ";
4562 case SOLVER_MULTIVERSION:
4563 strstart = "multi version ";
4568 case SOLVER_DISTUPGRADE:
4569 strstart = "dist upgrade ";
4572 strstart = "verify ";
4574 case SOLVER_DROP_ORPHANED:
4575 strstart = "deinstall ", strend = " if orphaned";
4577 case SOLVER_USERINSTALLED:
4578 strstart = "regard ", strend = " as userinstalled";
4581 strstart = "unknown job ";
4584 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
4586 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
4589 s = pool_tmpappend(pool, s, " ", 0);
4590 if (how & SOLVER_WEAK)
4591 s = pool_tmpappend(pool, s, ",weak", 0);
4592 if (how & SOLVER_ESSENTIAL)
4593 s = pool_tmpappend(pool, s, ",essential", 0);
4594 if (how & SOLVER_CLEANDEPS)
4595 s = pool_tmpappend(pool, s, ",cleandeps", 0);
4596 if (how & SOLVER_ORUPDATE)
4597 s = pool_tmpappend(pool, s, ",orupdate", 0);
4598 if (how & SOLVER_FORCEBEST)
4599 s = pool_tmpappend(pool, s, ",forcebest", 0);
4600 if (how & SOLVER_TARGETED)
4601 s = pool_tmpappend(pool, s, ",targeted", 0);
4602 if (how & SOLVER_SETEV)
4603 s = pool_tmpappend(pool, s, ",setev", 0);
4604 if (how & SOLVER_SETEVR)
4605 s = pool_tmpappend(pool, s, ",setevr", 0);
4606 if (how & SOLVER_SETARCH)
4607 s = pool_tmpappend(pool, s, ",setarch", 0);
4608 if (how & SOLVER_SETVENDOR)
4609 s = pool_tmpappend(pool, s, ",setvendor", 0);
4610 if (how & SOLVER_SETREPO)
4611 s = pool_tmpappend(pool, s, ",setrepo", 0);
4612 if (how & SOLVER_SETNAME)
4613 s = pool_tmpappend(pool, s, ",setname", 0);
4614 if (how & SOLVER_NOAUTOSET)
4615 s = pool_tmpappend(pool, s, ",noautoset", 0);
4616 if (s[o + 1] != ',')
4617 s = pool_tmpappend(pool, s, ",?", 0);
4619 return pool_tmpappend(pool, s, "]", 0);