2 * Copyright (c) 2007-2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
21 #include "solver_private.h"
27 #include "solverdebug.h"
29 #include "linkedpkg.h"
31 #define RULES_BLOCK 63
33 /********************************************************************
35 * dependency check helpers
39 /*-------------------------------------------------------------------
40 * handle split provides
42 * a splitprovides dep looks like
43 * namespace:splitprovides(pkg REL_WITH path)
44 * and is only true if pkg is installed and contains the specified path.
45 * we also make sure that pkg is selected for an update, otherwise the
46 * update would always be forced onto the user.
49 solver_splitprovides(Solver *solv, Id dep)
51 Pool *pool = solv->pool;
56 if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
60 rd = GETRELDEP(pool, dep);
61 if (rd->flags != REL_WITH)
64 * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
65 * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
66 * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
67 * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
68 * we filter the package name further down anyway).
70 if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
71 pp = pool_searchlazywhatprovidesq(pool, rd->evr);
73 pp = pool_whatprovides(pool, dep);
74 while ((p = pool->whatprovidesdata[pp++]) != 0)
76 /* here we have packages that provide the correct name and contain the path,
77 * now do extra filtering */
78 s = pool->solvables + p;
79 if (s->repo == solv->installed && s->name == rd->name &&
80 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
87 /*-------------------------------------------------------------------
88 * solver_dep_installed
92 solver_dep_installed(Solver *solv, Id dep)
95 Pool *pool = solv->pool;
100 Reldep *rd = GETRELDEP(pool, dep);
101 if (rd->flags == REL_AND)
103 if (!solver_dep_installed(solv, rd->name))
105 return solver_dep_installed(solv, rd->evr);
107 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
108 return solver_dep_installed(solv, rd->evr);
110 FOR_PROVIDES(p, pp, dep)
112 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
119 /* mirrors solver_dep_installed, but returns 2 if a
120 * dependency listed in solv->installsuppdepq was involved */
122 solver_check_installsuppdepq_dep(Solver *solv, Id dep)
124 Pool *pool = solv->pool;
130 Reldep *rd = GETRELDEP(pool, dep);
131 if (rd->flags == REL_AND)
133 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
136 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
139 return r1 == 2 || r2 == 2 ? 2 : 1;
141 if (rd->flags == REL_OR)
143 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
144 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
147 return r1 == 2 || r2 == 2 ? 2 : 1;
149 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
150 return solver_splitprovides(solv, rd->evr);
151 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
152 return solver_dep_installed(solv, rd->evr);
153 if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
156 for (i = 0; i < q->count; i++)
157 if (q->elements[i] == dep || q->elements[i] == rd->name)
161 FOR_PROVIDES(p, pp, dep)
162 if (solv->decisionmap[p] > 0)
168 solver_check_installsuppdepq(Solver *solv, Solvable *s)
171 supp = s->repo->idarraydata + s->supplements;
172 while ((sup = *supp++) != 0)
173 if (solver_check_installsuppdepq_dep(solv, sup) == 2)
179 autouninstall(Solver *solv, Id *problem)
181 Pool *pool = solv->pool;
183 int lastfeature = 0, lastupdate = 0;
187 for (i = 0; (v = problem[i]) != 0; i++)
190 extraflags &= solv->job.elements[-v - 1];
191 if (v >= solv->featurerules && v < solv->featurerules_end)
194 if (v >= solv->updaterules && v < solv->updaterules_end)
196 /* check if identical to feature rule */
197 Id p = solv->rules[v].p;
201 r = solv->rules + solv->featurerules + (p - solv->installed->start);
204 /* update rule == feature rule */
213 if (!lastupdate && !lastfeature)
215 v = lastupdate ? lastupdate : lastfeature;
216 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
217 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
218 solver_disableproblem(solv, v);
219 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
221 /* add the package to the updatepkgs list, this will automatically turn
222 * on cleandeps mode */
223 Id p = solv->rules[v].p;
224 if (!solv->cleandeps_updatepkgs)
226 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
227 queue_init(solv->cleandeps_updatepkgs);
231 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
232 queue_pushunique(solv->cleandeps_updatepkgs, p);
233 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
234 solver_disablepolicyrules(solv);
240 /************************************************************************/
243 * enable/disable learnt rules
245 * we have enabled or disabled some of our rules. We now reenable all
246 * of our learnt rules except the ones that were learnt from rules that
250 enabledisablelearntrules(Solver *solv)
252 Pool *pool = solv->pool;
257 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
258 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
260 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
261 while ((why = *whyp++) != 0)
263 assert(why > 0 && why < i);
264 if (solv->rules[why].d < 0)
267 /* why != 0: we found a disabled rule, disable the learnt rule */
268 if (why && r->d >= 0)
270 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
272 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
273 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
275 solver_disablerule(solv, r);
277 else if (!why && r->d < 0)
279 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
281 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
282 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
284 solver_enablerule(solv, r);
291 * make assertion rules into decisions
293 * Go through rules and add direct assertions to the decisionqueue.
294 * If we find a conflict, disable rules and add them to problem queue.
298 makeruledecisions(Solver *solv)
300 Pool *pool = solv->pool;
305 int record_proof = 1;
307 int havedisabled = 0;
309 /* The system solvable is always installed first */
310 assert(solv->decisionq.count == 0);
311 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
312 queue_push(&solv->decisionq_why, 0);
313 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
315 decisionstart = solv->decisionq.count;
318 /* if we needed to re-run, back up decisions to decisionstart */
319 while (solv->decisionq.count > decisionstart)
321 v = solv->decisionq.elements[--solv->decisionq.count];
322 --solv->decisionq_why.count;
324 solv->decisionmap[vv] = 0;
327 /* note that the ruleassertions queue is ordered */
328 for (ii = 0; ii < solv->ruleassertions.count; ii++)
330 ri = solv->ruleassertions.elements[ii];
331 r = solv->rules + ri;
333 if (havedisabled && ri >= solv->learntrules)
335 /* just started with learnt rule assertions. If we have disabled
336 * some rules, adapt the learnt rule status */
337 enabledisablelearntrules(solv);
341 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
344 /* do weak rules in phase 2 */
345 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
351 if (!solv->decisionmap[vv]) /* if not yet decided */
353 queue_push(&solv->decisionq, v);
354 queue_push(&solv->decisionq_why, r - solv->rules);
355 solv->decisionmap[vv] = v > 0 ? 1 : -1;
356 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
358 Solvable *s = solv->pool->solvables + vv;
360 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
362 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
367 /* check against previous decision: is there a conflict? */
368 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
370 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
376 * The rule (r) we're currently processing says something
377 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
381 if (ri >= solv->learntrules)
383 /* conflict with a learnt rule */
384 /* can happen when packages cannot be installed for multiple reasons. */
385 /* we disable the learnt rule in this case */
386 /* (XXX: we should really call analyze_unsolvable_rule here!) */
387 solver_disablerule(solv, r);
392 * find the decision which is the "opposite" of the rule
394 for (i = 0; i < solv->decisionq.count; i++)
395 if (solv->decisionq.elements[i] == -v)
397 assert(i < solv->decisionq.count); /* assert that we found it */
398 oldproblemcount = solv->problems.count;
401 * conflict with system solvable ?
403 if (v == -SYSTEMSOLVABLE)
407 queue_push(&solv->problems, solv->learnt_pool.count);
408 queue_push(&solv->learnt_pool, ri);
409 queue_push(&solv->learnt_pool, 0);
412 queue_push(&solv->problems, 0);
413 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
414 if (ri >= solv->jobrules && ri < solv->jobrules_end)
415 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
418 queue_push(&solv->problems, v);
419 queue_push(&solv->problems, 0);
420 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
421 solv->problems.count = oldproblemcount;
422 solver_disableproblem(solv, v);
424 break; /* start over */
427 assert(solv->decisionq_why.elements[i] > 0);
430 * conflict with an rpm rule ?
432 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
436 queue_push(&solv->problems, solv->learnt_pool.count);
437 queue_push(&solv->learnt_pool, ri);
438 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
439 queue_push(&solv->learnt_pool, 0);
442 queue_push(&solv->problems, 0);
443 assert(v > 0 || v == -SYSTEMSOLVABLE);
444 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
445 if (ri >= solv->jobrules && ri < solv->jobrules_end)
446 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
449 queue_push(&solv->problems, v);
450 queue_push(&solv->problems, 0);
451 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
452 solv->problems.count = oldproblemcount;
453 solver_disableproblem(solv, v);
455 break; /* start over */
459 * conflict with another job or update/feature rule
465 queue_push(&solv->problems, solv->learnt_pool.count);
466 queue_push(&solv->learnt_pool, ri);
467 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
468 queue_push(&solv->learnt_pool, 0);
471 queue_push(&solv->problems, 0);
473 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
476 * push all of our rules (can only be feature or job rules)
477 * asserting this literal on the problem stack
479 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
481 if (rr->d < 0 /* disabled */
482 || rr->w2) /* or no assertion */
484 if (rr->p != vv /* not affecting the literal */
487 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
490 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
491 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
494 if (i >= solv->jobrules && i < solv->jobrules_end)
495 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
496 queue_push(&solv->problems, v);
498 queue_push(&solv->problems, 0);
500 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
501 solv->problems.count = oldproblemcount;
503 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
504 solver_disableproblem(solv, solv->problems.elements[i]);
506 break; /* start over */
508 if (ii < solv->ruleassertions.count)
512 * phase 2: now do the weak assertions
514 for (ii = 0; ii < solv->ruleassertions.count; ii++)
516 ri = solv->ruleassertions.elements[ii];
517 r = solv->rules + ri;
518 if (r->d < 0 || r->w2) /* disabled or no assertion */
520 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
525 if (!solv->decisionmap[vv]) /* if not yet decided */
527 queue_push(&solv->decisionq, v);
528 queue_push(&solv->decisionq_why, r - solv->rules);
529 solv->decisionmap[vv] = v > 0 ? 1 : -1;
530 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
532 Solvable *s = solv->pool->solvables + vv;
534 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
536 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
540 /* check against previous decision: is there a conflict? */
541 if (v > 0 && solv->decisionmap[vv] > 0)
543 if (v < 0 && solv->decisionmap[vv] < 0)
546 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
547 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
549 if (ri >= solv->jobrules && ri < solv->jobrules_end)
550 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
553 solver_disableproblem(solv, v);
555 solver_reenablepolicyrules(solv, -v);
557 break; /* start over */
559 if (ii == solv->ruleassertions.count)
560 break; /* finished! */
565 /********************************************************************/
569 /*-------------------------------------------------------------------
572 * initial setup for all watches
576 makewatches(Solver *solv)
580 int nsolvables = solv->pool->nsolvables;
582 solv_free(solv->watches);
583 /* lower half for removals, upper half for installs */
584 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
586 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
587 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
589 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
592 if (!r->w2) /* assertions do not need watches */
595 /* see addwatches_rule(solv, r) */
596 r->n1 = solv->watches[nsolvables + r->w1];
597 solv->watches[nsolvables + r->w1] = r - solv->rules;
599 r->n2 = solv->watches[nsolvables + r->w2];
600 solv->watches[nsolvables + r->w2] = r - solv->rules;
605 /*-------------------------------------------------------------------
607 * add watches (for a new learned rule)
608 * sets up watches for a single rule
610 * see also makewatches() above.
614 addwatches_rule(Solver *solv, Rule *r)
616 int nsolvables = solv->pool->nsolvables;
618 r->n1 = solv->watches[nsolvables + r->w1];
619 solv->watches[nsolvables + r->w1] = r - solv->rules;
621 r->n2 = solv->watches[nsolvables + r->w2];
622 solv->watches[nsolvables + r->w2] = r - solv->rules;
626 /********************************************************************/
632 /* shortcuts to check if a literal (positive or negative) assignment
633 * evaluates to 'true' or 'false'
635 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
636 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
637 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
639 /*-------------------------------------------------------------------
643 * make decision and propagate to all rules
645 * Evaluate each term affected by the decision (linked through watches).
646 * If we find unit rules we make new decisions based on them.
648 * return : 0 = everything is OK
649 * rule = conflict found in this rule
653 propagate(Solver *solv, int level)
655 Pool *pool = solv->pool;
656 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
658 Id p, pkg, other_watch;
660 Id *decisionmap = solv->decisionmap;
662 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
664 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
666 /* foreach non-propagated decision */
667 while (solv->propagate_index < solv->decisionq.count)
670 * 'pkg' was just decided
671 * negate because our watches trigger if literal goes FALSE
673 pkg = -solv->decisionq.elements[solv->propagate_index++];
675 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
677 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
678 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
681 /* foreach rule where 'pkg' is now FALSE */
682 for (rp = watches + pkg; *rp; rp = next_rp)
684 r = solv->rules + *rp;
687 /* rule is disabled, goto next */
695 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
697 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
698 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
701 /* 'pkg' was just decided (was set to FALSE)
703 * now find other literal watch, check clause
704 * and advance on linked list
718 * This term is already true (through the other literal)
719 * so we have nothing to do
721 if (DECISIONMAP_TRUE(other_watch))
725 * The other literal is FALSE or UNDEF
731 /* Not a binary clause, try to move our watch.
733 * Go over all literals and find one that is
737 * (TRUE is also ok, in that case the rule is fulfilled)
739 if (r->p /* we have a 'p' */
740 && r->p != other_watch /* which is not watched */
741 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
745 else /* go find a 'd' to make 'true' */
748 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
750 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
752 if (p != other_watch /* which is not watched */
753 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
761 * if we found some p that is UNDEF or TRUE, move
764 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
767 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
769 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
785 watches[p] = r - solv->rules;
788 /* search failed, thus all unwatched literals are FALSE */
793 * unit clause found, set literal other_watch to TRUE
796 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
797 return r; /* eek, a conflict! */
799 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
801 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
802 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
806 decisionmap[other_watch] = level; /* install! */
808 decisionmap[-other_watch] = -level; /* remove! */
810 queue_push(&solv->decisionq, other_watch);
811 queue_push(&solv->decisionq_why, r - solv->rules);
813 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
816 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
818 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
821 } /* foreach rule involving 'pkg' */
823 } /* while we have non-decided decisions */
825 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
827 return 0; /* all is well */
831 /********************************************************************/
834 /*-------------------------------------------------------------------
841 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
843 Pool *pool = solv->pool;
847 Map seen; /* global? */
848 Id d, v, vv, *dp, why;
850 int num = 0, l1num = 0;
851 int learnt_why = solv->learnt_pool.count;
852 Id *decisionmap = solv->decisionmap;
854 queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
856 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
857 map_init(&seen, pool->nsolvables);
858 idx = solv->decisionq.count;
861 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
862 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
863 queue_push(&solv->learnt_pool, c - solv->rules);
864 d = c->d < 0 ? -c->d - 1 : c->d;
865 dp = d ? pool->whatprovidesdata + d : 0;
866 /* go through all literals of the rule */
878 if (DECISIONMAP_TRUE(v)) /* the one true literal */
881 if (MAPTST(&seen, vv))
883 l = solv->decisionmap[vv];
886 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
888 l1num++; /* need to do this one in level1 pass */
890 num++; /* need to do this one as well */
893 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
899 if (!num && !--l1num)
900 break; /* all level 1 literals done */
902 /* find the next literal to investigate */
903 /* (as num + l1num > 0, we know that we'll always find one) */
907 v = solv->decisionq.elements[--idx];
909 if (MAPTST(&seen, vv))
914 if (num && --num == 0)
916 *pr = -v; /* so that v doesn't get lost */
919 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
920 /* clear non-l1 bits from seen map */
921 for (i = 0; i < r.count; i++)
924 MAPCLR(&seen, v > 0 ? v : -v);
926 /* only level 1 marks left in seen map */
927 l1num++; /* as l1retry decrements it */
931 why = solv->decisionq_why.elements[idx];
932 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
934 c = solv->rules + why;
940 else if (r.count == 1 && r.elements[0] < 0)
943 *dr = pool_queuetowhatprovides(pool, &r);
944 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
946 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
947 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
948 for (i = 0; i < r.count; i++)
949 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
951 /* push end marker on learnt reasons stack */
952 queue_push(&solv->learnt_pool, 0);
956 solv->stats_learned++;
961 /*-------------------------------------------------------------------
965 * reset all solver decisions
966 * called after rules have been enabled/disabled
970 solver_reset(Solver *solv)
972 Pool *pool = solv->pool;
976 /* rewind all decisions */
977 for (i = solv->decisionq.count - 1; i >= 0; i--)
979 v = solv->decisionq.elements[i];
980 solv->decisionmap[v > 0 ? v : -v] = 0;
982 queue_empty(&solv->decisionq_why);
983 queue_empty(&solv->decisionq);
984 solv->recommends_index = -1;
985 solv->propagate_index = 0;
986 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
987 queue_empty(&solv->branches);
989 /* adapt learnt rule status to new set of enabled/disabled rules */
990 enabledisablelearntrules(solv);
992 /* redo all assertion rule decisions */
993 makeruledecisions(solv);
994 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
998 /*-------------------------------------------------------------------
1000 * analyze_unsolvable_rule
1002 * recursion helper used by analyze_unsolvable
1006 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1008 Pool *pool = solv->pool;
1010 Id why = r - solv->rules;
1012 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1013 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1014 if (solv->learntrules && why >= solv->learntrules)
1016 if (MAPTST(rseen, why - solv->learntrules))
1018 MAPSET(rseen, why - solv->learntrules);
1019 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1020 if (solv->learnt_pool.elements[i] > 0)
1021 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1024 if (MAPTST(&solv->weakrulemap, why))
1025 if (!*lastweakp || why > *lastweakp)
1027 /* do not add rpm rules to problem */
1028 if (why < solv->rpmrules_end)
1030 /* turn rule into problem */
1031 if (why >= solv->jobrules && why < solv->jobrules_end)
1032 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1033 /* normalize dup/infarch rules */
1034 if (why > solv->infarchrules && why < solv->infarchrules_end)
1036 Id name = pool->solvables[-solv->rules[why].p].name;
1037 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1040 if (why > solv->duprules && why < solv->duprules_end)
1042 Id name = pool->solvables[-solv->rules[why].p].name;
1043 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1047 /* return if problem already countains our rule */
1048 if (solv->problems.count)
1050 for (i = solv->problems.count - 1; i >= 0; i--)
1051 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1053 else if (solv->problems.elements[i] == why)
1056 queue_push(&solv->problems, why);
1060 /*-------------------------------------------------------------------
1062 * analyze_unsolvable
1064 * We know that the problem is not solvable. Record all involved
1065 * rules (i.e. the "proof") into solv->learnt_pool.
1066 * Record the learnt pool index and all non-rpm rules into
1067 * solv->problems. (Our solutions to fix the problems are to
1068 * disable those rules.)
1070 * If the proof contains at least one weak rule, we disable the
1073 * Otherwise we return 0 if disablerules is not set or disable
1074 * _all_ of the problem rules and return 1.
1076 * return: 1 - disabled some rules, try again
1081 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1083 Pool *pool = solv->pool;
1085 Map seen; /* global to speed things up? */
1087 Id d, v, vv, *dp, why;
1089 Id *decisionmap = solv->decisionmap;
1090 int oldproblemcount;
1091 int oldlearntpoolcount;
1093 int record_proof = 1;
1095 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1096 solv->stats_unsolvable++;
1097 oldproblemcount = solv->problems.count;
1098 oldlearntpoolcount = solv->learnt_pool.count;
1100 /* make room for proof index */
1101 /* must update it later, as analyze_unsolvable_rule would confuse
1102 * it with a rule index if we put the real value in already */
1103 queue_push(&solv->problems, 0);
1106 map_init(&seen, pool->nsolvables);
1107 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1109 queue_push(&solv->learnt_pool, r - solv->rules);
1111 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1112 d = r->d < 0 ? -r->d - 1 : r->d;
1113 dp = d ? pool->whatprovidesdata + d : 0;
1124 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1126 vv = v > 0 ? v : -v;
1127 l = solv->decisionmap[vv];
1132 idx = solv->decisionq.count;
1135 v = solv->decisionq.elements[--idx];
1136 vv = v > 0 ? v : -v;
1137 if (!MAPTST(&seen, vv) || vv == SYSTEMSOLVABLE)
1139 why = solv->decisionq_why.elements[idx];
1142 queue_push(&solv->learnt_pool, why);
1143 r = solv->rules + why;
1144 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1145 d = r->d < 0 ? -r->d - 1 : r->d;
1146 dp = d ? pool->whatprovidesdata + d : 0;
1157 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1159 vv = v > 0 ? v : -v;
1160 l = solv->decisionmap[vv];
1168 queue_push(&solv->problems, 0); /* mark end of this problem */
1172 /* disable last weak rule */
1173 solv->problems.count = oldproblemcount;
1174 solv->learnt_pool.count = oldlearntpoolcount;
1175 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1176 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1179 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1180 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1181 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1182 solver_disablechoicerules(solv, solv->rules + lastweak);
1183 solver_disableproblem(solv, v);
1185 solver_reenablepolicyrules(solv, -v);
1190 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
1192 solv->problems.count = oldproblemcount;
1193 solv->learnt_pool.count = oldlearntpoolcount;
1201 queue_push(&solv->learnt_pool, 0);
1202 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1205 /* + 2: index + trailing zero */
1206 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1208 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1209 solver_disableproblem(solv, solv->problems.elements[i]);
1210 /* XXX: might want to enable all weak rules again */
1214 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1219 /********************************************************************/
1220 /* Decision revert */
1222 /*-------------------------------------------------------------------
1225 * revert decisionq to a level
1229 revert(Solver *solv, int level)
1231 Pool *pool = solv->pool;
1233 while (solv->decisionq.count)
1235 v = solv->decisionq.elements[solv->decisionq.count - 1];
1236 vv = v > 0 ? v : -v;
1237 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1239 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1240 solv->decisionmap[vv] = 0;
1241 solv->decisionq.count--;
1242 solv->decisionq_why.count--;
1243 solv->propagate_index = solv->decisionq.count;
1245 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1247 solv->branches.count--;
1248 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1249 solv->branches.count--;
1251 if (solv->recommends_index > solv->decisionq.count)
1252 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
1253 if (solv->decisionq.count < solv->decisioncnt_update)
1254 solv->decisioncnt_update = 0;
1255 if (solv->decisionq.count < solv->decisioncnt_keep)
1256 solv->decisioncnt_keep = 0;
1257 if (solv->decisionq.count < solv->decisioncnt_resolve)
1258 solv->decisioncnt_resolve = 0;
1259 if (solv->decisionq.count < solv->decisioncnt_weak)
1260 solv->decisioncnt_weak= 0;
1261 if (solv->decisionq.count < solv->decisioncnt_orphan)
1262 solv->decisioncnt_orphan = 0;
1266 /*-------------------------------------------------------------------
1268 * watch2onhighest - put watch2 on literal with highest level
1272 watch2onhighest(Solver *solv, Rule *r)
1277 d = r->d < 0 ? -r->d - 1 : r->d;
1279 return; /* binary rule, both watches are set */
1280 dp = solv->pool->whatprovidesdata + d;
1281 while ((v = *dp++) != 0)
1283 l = solv->decisionmap[v < 0 ? -v : v];
1295 /*-------------------------------------------------------------------
1299 * add free decision (solvable to install) to decisionq
1300 * increase level and propagate decision
1301 * return if no conflict.
1303 * in conflict case, analyze conflict rule, add resulting
1304 * rule to learnt rule set, make decision from learnt
1305 * rule (always unit) and re-propagate.
1307 * returns the new solver level or 0 if unsolvable
1312 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1314 Pool *pool = solv->pool;
1319 assert(ruleid >= 0);
1324 solv->decisionmap[decision] = level;
1326 solv->decisionmap[-decision] = -level;
1327 queue_push(&solv->decisionq, decision);
1328 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1332 r = propagate(solv, level);
1336 return analyze_unsolvable(solv, r, disablerules);
1337 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1338 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1339 assert(l > 0 && l < level);
1340 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1342 revert(solv, level);
1343 r = solver_addrule(solv, p, d);
1345 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1346 queue_push(&solv->learnt_why, why);
1349 /* at least 2 literals, needs watches */
1350 watch2onhighest(solv, r);
1351 addwatches_rule(solv, r);
1355 /* learnt rule is an assertion */
1356 queue_push(&solv->ruleassertions, r - solv->rules);
1358 /* the new rule is unit by design */
1359 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1360 queue_push(&solv->decisionq, p);
1361 queue_push(&solv->decisionq_why, r - solv->rules);
1362 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1364 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1365 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1366 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1367 solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
1374 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1376 Pool *pool = solv->pool;
1377 int i, j, haveone = 0, dqcount = dq->count;
1381 /* at the time we process jobrules the installed packages are not kept yet */
1382 /* reorder so that "future-supplemented" packages come first */
1383 FOR_REPO_SOLVABLES(solv->installed, p, s)
1385 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1387 if (solv->decisionmap[p] == 0)
1389 solv->decisionmap[p] = level;
1395 for (i = 0; i < dqcount; i++)
1396 if (!solver_is_enhancing(solv, pool->solvables + dq->elements[i]))
1398 queue_push(dq, dq->elements[i]);
1399 dq->elements[i] = 0;
1401 dqcount = dq->count;
1402 for (i = 0; i < dqcount; i++)
1403 if (dq->elements[i] && !solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1405 queue_push(dq, dq->elements[i]);
1406 dq->elements[i] = 0;
1408 for (i = j = 0; i < dq->count; i++)
1409 if (dq->elements[i])
1410 dq->elements[j++] = dq->elements[i];
1411 queue_truncate(dq, j);
1412 FOR_REPO_SOLVABLES(solv->installed, p, s)
1413 if (solv->decisionmap[p] == level)
1414 solv->decisionmap[p] = 0;
1417 /*-------------------------------------------------------------------
1419 * select and install
1421 * install best package from the queue. We add an extra package, inst, if
1422 * provided. See comment in weak install section.
1424 * returns the new solver level or 0 if unsolvable
1429 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1431 Pool *pool = solv->pool;
1436 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1439 /* XXX: didn't we already do that? */
1440 /* XXX: shouldn't we prefer installed packages? */
1441 /* XXX: move to policy.c? */
1442 /* choose the supplemented one */
1443 for (i = 0; i < dq->count; i++)
1444 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1446 dq->elements[0] = dq->elements[i];
1451 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed)
1452 reorder_dq_for_jobrules(solv, level, dq);
1455 /* multiple candidates, open a branch */
1456 for (i = 1; i < dq->count; i++)
1457 queue_push(&solv->branches, dq->elements[i]);
1458 queue_push(&solv->branches, -level);
1460 p = dq->elements[0];
1462 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1464 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1468 /********************************************************************/
1469 /* Main solver interface */
1472 /*-------------------------------------------------------------------
1475 * create solver structure
1477 * pool: all available solvables
1478 * installed: installed Solvables
1481 * Upon solving, rules are created to flag the Solvables
1482 * of the 'installed' Repo as installed.
1486 solver_create(Pool *pool)
1489 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1491 solv->installed = pool->installed;
1493 solv->allownamechange = 1;
1495 solv->dup_allowdowngrade = 1;
1496 solv->dup_allownamechange = 1;
1497 solv->dup_allowarchchange = 1;
1498 solv->dup_allowvendorchange = 1;
1500 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1502 queue_init(&solv->ruletojob);
1503 queue_init(&solv->decisionq);
1504 queue_init(&solv->decisionq_why);
1505 queue_init(&solv->problems);
1506 queue_init(&solv->orphaned);
1507 queue_init(&solv->learnt_why);
1508 queue_init(&solv->learnt_pool);
1509 queue_init(&solv->branches);
1510 queue_init(&solv->weakruleq);
1511 queue_init(&solv->ruleassertions);
1512 queue_init(&solv->addedmap_deduceq);
1514 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1516 map_init(&solv->recommendsmap, pool->nsolvables);
1517 map_init(&solv->suggestsmap, pool->nsolvables);
1518 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1519 solv->recommends_index = 0;
1521 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1523 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1524 memset(solv->rules, 0, sizeof(Rule));
1530 /*-------------------------------------------------------------------
1536 queuep_free(Queue **qp)
1541 *qp = solv_free(*qp);
1545 map_zerosize(Map *m)
1555 solver_free(Solver *solv)
1557 queue_free(&solv->job);
1558 queue_free(&solv->ruletojob);
1559 queue_free(&solv->decisionq);
1560 queue_free(&solv->decisionq_why);
1561 queue_free(&solv->learnt_why);
1562 queue_free(&solv->learnt_pool);
1563 queue_free(&solv->problems);
1564 queue_free(&solv->solutions);
1565 queue_free(&solv->orphaned);
1566 queue_free(&solv->branches);
1567 queue_free(&solv->weakruleq);
1568 queue_free(&solv->ruleassertions);
1569 queue_free(&solv->addedmap_deduceq);
1570 queuep_free(&solv->cleandeps_updatepkgs);
1571 queuep_free(&solv->cleandeps_mistakes);
1572 queuep_free(&solv->update_targets);
1573 queuep_free(&solv->installsuppdepq);
1574 queuep_free(&solv->recommendscplxq);
1575 queuep_free(&solv->suggestscplxq);
1577 map_free(&solv->recommendsmap);
1578 map_free(&solv->suggestsmap);
1579 map_free(&solv->noupdate);
1580 map_free(&solv->weakrulemap);
1581 map_free(&solv->multiversion);
1583 map_free(&solv->updatemap);
1584 map_free(&solv->bestupdatemap);
1585 map_free(&solv->fixmap);
1586 map_free(&solv->dupmap);
1587 map_free(&solv->dupinvolvedmap);
1588 map_free(&solv->droporphanedmap);
1589 map_free(&solv->cleandepsmap);
1591 solv_free(solv->decisionmap);
1592 solv_free(solv->rules);
1593 solv_free(solv->watches);
1594 solv_free(solv->obsoletes);
1595 solv_free(solv->obsoletes_data);
1596 solv_free(solv->specialupdaters);
1597 solv_free(solv->choicerules_ref);
1598 solv_free(solv->bestrules_pkg);
1599 solv_free(solv->instbuddy);
1604 solver_get_flag(Solver *solv, int flag)
1608 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1609 return solv->allowdowngrade;
1610 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1611 return solv->allownamechange;
1612 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1613 return solv->allowarchchange;
1614 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1615 return solv->allowvendorchange;
1616 case SOLVER_FLAG_ALLOW_UNINSTALL:
1617 return solv->allowuninstall;
1618 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1619 return solv->noupdateprovide;
1620 case SOLVER_FLAG_SPLITPROVIDES:
1621 return solv->dosplitprovides;
1622 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1623 return solv->dontinstallrecommended;
1624 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1625 return solv->addalreadyrecommended;
1626 case SOLVER_FLAG_NO_INFARCHCHECK:
1627 return solv->noinfarchcheck;
1628 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1629 return solv->keepexplicitobsoletes;
1630 case SOLVER_FLAG_BEST_OBEY_POLICY:
1631 return solv->bestobeypolicy;
1632 case SOLVER_FLAG_NO_AUTOTARGET:
1633 return solv->noautotarget;
1634 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1635 return solv->dup_allowdowngrade;
1636 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1637 return solv->dup_allownamechange;
1638 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1639 return solv->dup_allowarchchange;
1640 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1641 return solv->dup_allowvendorchange;
1649 solver_set_flag(Solver *solv, int flag, int value)
1651 int old = solver_get_flag(solv, flag);
1654 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1655 solv->allowdowngrade = value;
1657 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1658 solv->allownamechange = value;
1660 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1661 solv->allowarchchange = value;
1663 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1664 solv->allowvendorchange = value;
1666 case SOLVER_FLAG_ALLOW_UNINSTALL:
1667 solv->allowuninstall = value;
1669 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1670 solv->noupdateprovide = value;
1672 case SOLVER_FLAG_SPLITPROVIDES:
1673 solv->dosplitprovides = value;
1675 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1676 solv->dontinstallrecommended = value;
1678 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1679 solv->addalreadyrecommended = value;
1681 case SOLVER_FLAG_NO_INFARCHCHECK:
1682 solv->noinfarchcheck = value;
1684 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1685 solv->keepexplicitobsoletes = value;
1687 case SOLVER_FLAG_BEST_OBEY_POLICY:
1688 solv->bestobeypolicy = value;
1690 case SOLVER_FLAG_NO_AUTOTARGET:
1691 solv->noautotarget = value;
1693 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1694 solv->dup_allowdowngrade = value;
1696 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1697 solv->dup_allownamechange = value;
1699 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1700 solv->dup_allowarchchange = value;
1702 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1703 solv->dup_allowvendorchange = value;
1712 cleandeps_check_mistakes(Solver *solv, int level)
1714 Pool *pool = solv->pool;
1718 int mademistake = 0;
1720 if (!solv->cleandepsmap.size)
1722 /* check for mistakes */
1723 for (i = solv->installed->start; i < solv->installed->end; i++)
1725 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1727 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1728 /* a mistake is when the featurerule is true but the updaterule is false */
1731 FOR_RULELITERALS(p, pp, r)
1732 if (p > 0 && solv->decisionmap[p] > 0)
1735 continue; /* feature rule is not true */
1736 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1739 FOR_RULELITERALS(p, pp, r)
1740 if (p > 0 && solv->decisionmap[p] > 0)
1743 continue; /* update rule is true */
1744 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1745 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1746 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1747 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1748 if (!solv->cleandeps_mistakes)
1750 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1751 queue_init(solv->cleandeps_mistakes);
1753 queue_push(solv->cleandeps_mistakes, i);
1754 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1755 solver_reenablepolicyrules_cleandeps(solv, i);
1764 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1768 for (i = j = 0; i < q->count; i++)
1771 for (cp2 = cp; *cp2; cp2++)
1774 q->elements[j++] = p;
1778 queue_truncate(q, j);
1781 #ifdef ENABLE_COMPLEX_DEPS
1784 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1786 Pool *pool = solv->pool;
1787 int oldcnt = dq->count;
1793 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1795 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1796 if (i == 0 || i == 1)
1799 for (i = oldcnt; i < cutcnt; i++)
1802 for (; (p = dq->elements[i]) != 0; i++)
1806 if (solv->decisionmap[-p] <= 0)
1810 if (solv->decisionmap[p] > 0)
1812 queue_truncate(dq, blkcnt);
1817 if (!MAPTST(dqmap, p))
1822 if (solv->decisionmap[p] < 0)
1824 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))))
1829 while (dq->elements[i])
1832 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1834 if (dq->count != oldcnt)
1836 for (j = oldcnt; j < dq->count; j++)
1838 p = dq->elements[j];
1839 for (i = 0; i < j; i++)
1840 if (dq->elements[i] == p)
1842 dq->elements[j] = 0;
1846 for (i = j = oldcnt; j < dq->count; j++)
1847 if (dq->elements[j])
1848 dq->elements[i++] = dq->elements[j];
1849 queue_truncate(dq, i);
1852 printf("RETURN:\n");
1853 for (i = oldcnt; i < dq->count; i++)
1854 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
1859 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
1861 Pool *pool = solv->pool;
1867 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
1870 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
1871 if (i == 0 || i == 1)
1876 for (i = 0; i < dq.count; i++)
1879 for (; (p = dq.elements[i]) != 0; i++)
1883 if (solv->decisionmap[-p] <= 0)
1887 if (solv->decisionmap[p] > 0)
1892 for (i++; (p = dq.elements[i]) != 0; i++)
1893 if (p > 0 && solv->decisionmap[p] > 0)
1901 for (i = blk; (p = dq.elements[i]) != 0; i++)
1905 while (dq.elements[i])
1913 /*-------------------------------------------------------------------
1917 * all rules have been set up, now actually run the solver
1922 solver_run_sat(Solver *solv, int disablerules, int doweak)
1924 Queue dq; /* local decisionqueue */
1925 Queue dqs; /* local decisionqueue for supplements */
1931 Pool *pool = solv->pool;
1933 int minimizationsteps;
1934 int installedpos = solv->installed ? solv->installed->start : 0;
1936 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
1938 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
1939 for (i = 1; i < solv->nrules; i++)
1940 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
1943 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
1945 /* start SAT algorithm */
1947 systemlevel = level + 1;
1948 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
1954 * here's the main loop:
1955 * 1) propagate new decisions (only needed once)
1957 * 3) try to keep installed packages
1958 * 4) fulfill all unresolved rules
1959 * 5) install recommended packages
1960 * 6) minimalize solution if we had choices
1961 * if we encounter a problem, we rewind to a safe level and restart
1965 minimizationsteps = 0;
1969 * initial propagation of the assertions
1973 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
1974 if ((r = propagate(solv, level)) != 0)
1976 if (analyze_unsolvable(solv, r, disablerules))
1979 break; /* unsolvable */
1984 * resolve jobs first
1986 if (level < systemlevel)
1988 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1989 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1992 if (r->d < 0) /* ignore disabled rules */
1995 FOR_RULELITERALS(l, pp, r)
1999 if (solv->decisionmap[-l] <= 0)
2004 if (solv->decisionmap[l] > 0)
2006 if (solv->decisionmap[l] == 0)
2012 /* prune to installed if not updating */
2013 if (dq.count > 1 && solv->installed && !solv->updatemap_all &&
2014 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
2017 for (j = k = 0; j < dq.count; j++)
2019 Solvable *s = pool->solvables + dq.elements[j];
2020 if (s->repo == solv->installed)
2022 dq.elements[k++] = dq.elements[j];
2023 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq.elements[j] - solv->installed->start))
2025 k = 0; /* package wants to be updated, do not prune */
2034 level = selectandinstall(solv, level, &dq, disablerules, i);
2037 if (level <= olevel)
2041 break; /* unsolvable */
2042 systemlevel = level + 1;
2043 if (i < solv->jobrules_end)
2045 if (!solv->decisioncnt_update)
2046 solv->decisioncnt_update = solv->decisionq.count;
2050 * installed packages
2052 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2054 Repo *installed = solv->installed;
2057 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2058 /* we use two passes if we need to update packages
2059 * to create a better user experience */
2060 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2062 int passlevel = level;
2063 Id *specialupdaters = solv->specialupdaters;
2064 if (pass == 1 && !solv->decisioncnt_keep)
2065 solv->decisioncnt_keep = solv->decisionq.count;
2066 /* start with installedpos, the position that gave us problems the last time */
2067 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2072 if (i == installed->end)
2073 i = installed->start;
2074 s = pool->solvables + i;
2075 if (s->repo != installed)
2078 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2079 continue; /* already decided */
2080 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2081 continue; /* updates first */
2082 r = solv->rules + solv->updaterules + (i - installed->start);
2084 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2085 rr -= solv->installed->end - solv->installed->start;
2086 if (!rr->p) /* identical to update rule? */
2088 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2089 continue; /* orpaned package */
2091 /* check if we should update this package to the latest version
2092 * noupdate is set for erase jobs, in that case we want to deinstall
2093 * the installed package and not replace it with a newer version
2094 * rr->p != i is for dup jobs where the installed package cannot be kept */
2096 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)))
2100 /* specialupdater with no update/feature rule */
2101 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2103 if (solv->decisionmap[p] > 0)
2108 if (!solv->decisionmap[p])
2112 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2114 /* special multiversion handling, make sure best version is chosen */
2115 if (rr->p == i && solv->decisionmap[i] >= 0)
2117 while ((p = pool->whatprovidesdata[d++]) != 0)
2118 if (solv->decisionmap[p] >= 0)
2120 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2121 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2124 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2126 if (p != i && solv->decisionmap[p] == 0)
2128 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2129 if (!rr->p) /* update rule == feature rule? */
2130 rr = rr - solv->featurerules + solv->updaterules;
2139 /* update to best package of the update rule */
2140 FOR_RULELITERALS(p, pp, rr)
2142 if (solv->decisionmap[p] > 0)
2144 dq.count = 0; /* already fulfilled */
2147 if (!solv->decisionmap[p])
2152 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2153 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2154 /* install best version */
2158 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2165 if (level <= olevel)
2167 if (level == 1 || level < passlevel)
2168 break; /* trouble */
2170 n = installed->start; /* redo all */
2176 /* if still undecided keep package */
2177 if (solv->decisionmap[i] == 0)
2180 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2183 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2184 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2191 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2192 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2196 if (level <= olevel)
2198 if (level == 1 || level < passlevel)
2199 break; /* trouble */
2201 n = installed->start; /* redo all */
2204 continue; /* retry with learnt rule */
2208 if (n < installed->end)
2210 installedpos = i; /* retry problem solvable next time */
2211 break; /* ran into trouble */
2213 installedpos = installed->start; /* reset installedpos */
2216 break; /* unsolvable */
2217 systemlevel = level + 1;
2219 continue; /* had trouble, retry */
2221 if (!solv->decisioncnt_keep)
2222 solv->decisioncnt_keep = solv->decisionq.count;
2224 if (level < systemlevel)
2225 systemlevel = level;
2230 if (!solv->decisioncnt_resolve)
2231 solv->decisioncnt_resolve = solv->decisionq.count;
2232 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2233 for (i = 1, n = 1; n < solv->nrules; i++, n++)
2235 if (i == solv->nrules)
2237 r = solv->rules + i;
2238 if (r->d < 0) /* ignore disabled rules */
2240 if (r->p < 0) /* most common cases first */
2242 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2249 /* binary or unary rule */
2250 /* need two positive undecided literals, r->p already checked above */
2253 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2255 queue_push(&dq, r->p);
2256 queue_push(&dq, r->w2);
2261 * all negative literals are installed
2262 * no positive literal is installed
2263 * i.e. the rule is not fulfilled and we
2264 * just need to decide on the positive literals
2265 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2269 if (solv->decisionmap[r->p] > 0)
2271 if (solv->decisionmap[r->p] == 0)
2272 queue_push(&dq, r->p);
2274 dp = pool->whatprovidesdata + r->d;
2275 while ((p = *dp++) != 0)
2279 if (solv->decisionmap[-p] <= 0)
2284 if (solv->decisionmap[p] > 0)
2286 if (solv->decisionmap[p] == 0)
2293 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2295 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2296 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2298 /* dq.count < 2 cannot happen as this means that
2299 * the rule is unit */
2300 assert(dq.count > 1);
2302 /* prune to cleandeps packages */
2303 if (solv->cleandepsmap.size && solv->installed)
2305 Repo *installed = solv->installed;
2306 for (j = 0; j < dq.count; j++)
2307 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2311 dq.elements[0] = dq.elements[j];
2312 queue_truncate(&dq, 1);
2317 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2319 break; /* unsolvable */
2320 if (level < systemlevel || level == 1)
2321 break; /* trouble */
2322 /* something changed, so look at all rules again */
2326 if (n != solv->nrules) /* ran into trouble? */
2329 break; /* unsolvable */
2330 continue; /* start over */
2333 /* decide leftover cleandeps packages */
2334 if (solv->cleandepsmap.size && solv->installed)
2336 for (p = solv->installed->start; p < solv->installed->end; p++)
2338 s = pool->solvables + p;
2339 if (s->repo != solv->installed)
2341 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2343 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2345 level = setpropagatelearn(solv, level, -p, 0, 0);
2350 if (p < solv->installed->end)
2354 /* at this point we have a consistent system. now do the extras... */
2356 if (!solv->decisioncnt_weak)
2357 solv->decisioncnt_weak = solv->decisionq.count;
2362 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2363 queue_empty(&dq); /* recommended packages */
2364 queue_empty(&dqs); /* supplemented packages */
2365 for (i = 1; i < pool->nsolvables; i++)
2367 if (solv->decisionmap[i] < 0)
2369 if (solv->decisionmap[i] > 0)
2371 /* installed, check for recommends */
2372 Id *recp, rec, pp, p;
2373 s = pool->solvables + i;
2374 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2376 /* XXX need to special case AND ? */
2379 recp = s->repo->idarraydata + s->recommends;
2380 while ((rec = *recp++) != 0)
2382 #ifdef ENABLE_COMPLEX_DEPS
2383 if (pool_is_complex_dep(pool, rec))
2385 add_complex_recommends(solv, rec, &dq, 0);
2390 FOR_PROVIDES(p, pp, rec)
2392 if (solv->decisionmap[p] > 0)
2397 else if (solv->decisionmap[p] == 0)
2399 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))))
2401 queue_pushunique(&dq, p);
2409 s = pool->solvables + i;
2410 if (!s->supplements)
2412 if (!pool_installable(pool, s))
2414 if (!solver_is_supplementing(solv, s))
2416 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2418 queue_push(&dqs, i);
2422 /* filter out all packages obsoleted by installed packages */
2423 /* this is no longer needed if we have reverse obsoletes */
2424 if ((dqs.count || dq.count) && solv->installed)
2427 Id obs, *obsp, po, ppo;
2429 map_init(&obsmap, pool->nsolvables);
2430 for (p = solv->installed->start; p < solv->installed->end; p++)
2432 s = pool->solvables + p;
2433 if (s->repo != solv->installed || !s->obsoletes)
2435 if (solv->decisionmap[p] <= 0)
2437 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
2439 obsp = s->repo->idarraydata + s->obsoletes;
2440 /* foreach obsoletes */
2441 while ((obs = *obsp++) != 0)
2442 FOR_PROVIDES(po, ppo, obs)
2443 MAPSET(&obsmap, po);
2445 for (i = j = 0; i < dqs.count; i++)
2446 if (!MAPTST(&obsmap, dqs.elements[i]))
2447 dqs.elements[j++] = dqs.elements[i];
2449 for (i = j = 0; i < dq.count; i++)
2450 if (!MAPTST(&obsmap, dq.elements[i]))
2451 dq.elements[j++] = dq.elements[i];
2456 /* filter out all already supplemented packages if requested */
2457 if (!solv->addalreadyrecommended && dqs.count)
2459 int dosplitprovides_old = solv->dosplitprovides;
2460 /* turn off all new packages */
2461 for (i = 0; i < solv->decisionq.count; i++)
2463 p = solv->decisionq.elements[i];
2466 s = pool->solvables + p;
2467 if (s->repo && s->repo != solv->installed)
2468 solv->decisionmap[p] = -solv->decisionmap[p];
2470 solv->dosplitprovides = 0;
2471 /* filter out old supplements */
2472 for (i = j = 0; i < dqs.count; i++)
2474 p = dqs.elements[i];
2475 s = pool->solvables + p;
2476 if (!s->supplements)
2478 if (!solver_is_supplementing(solv, s))
2479 dqs.elements[j++] = p;
2480 else if (solv->installsuppdepq && solver_check_installsuppdepq(solv, s))
2481 dqs.elements[j++] = p;
2484 /* undo turning off */
2485 for (i = 0; i < solv->decisionq.count; i++)
2487 p = solv->decisionq.elements[i];
2490 s = pool->solvables + p;
2491 if (s->repo && s->repo != solv->installed)
2492 solv->decisionmap[p] = -solv->decisionmap[p];
2494 solv->dosplitprovides = dosplitprovides_old;
2497 /* multiversion doesn't mix well with supplements.
2498 * filter supplemented packages where we already decided
2499 * to install a different version (see bnc#501088) */
2500 if (dqs.count && solv->multiversion.size)
2502 for (i = j = 0; i < dqs.count; i++)
2504 p = dqs.elements[i];
2505 if (MAPTST(&solv->multiversion, p))
2508 s = pool->solvables + p;
2509 FOR_PROVIDES(p2, pp2, s->name)
2510 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2513 continue; /* ignore this package */
2515 dqs.elements[j++] = p;
2520 /* make dq contain both recommended and supplemented pkgs */
2523 for (i = 0; i < dqs.count; i++)
2524 queue_pushunique(&dq, dqs.elements[i]);
2530 int decisioncount = solv->decisionq.count;
2534 /* simple case, just one package. no need to choose to best version */
2537 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2539 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2540 level = setpropagatelearn(solv, level, p, 0, 0);
2543 continue; /* back to main loop */
2546 /* filter packages, this gives us the best versions */
2547 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2549 /* create map of result */
2550 map_init(&dqmap, pool->nsolvables);
2551 for (i = 0; i < dq.count; i++)
2552 MAPSET(&dqmap, dq.elements[i]);
2554 /* install all supplemented packages */
2555 for (i = 0; i < dqs.count; i++)
2557 p = dqs.elements[i];
2558 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2560 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2562 level = setpropagatelearn(solv, level, p, 0, 0);
2563 if (level <= olevel)
2566 if (i < dqs.count || solv->decisionq.count < decisioncount)
2574 /* install all recommended packages */
2575 /* more work as we want to created branches if multiple
2576 * choices are valid */
2577 for (i = 0; i < decisioncount; i++)
2580 p = solv->decisionq.elements[i];
2583 s = pool->solvables + p;
2584 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2588 recp = s->repo->idarraydata + s->recommends;
2589 while ((rec = *recp++) != 0)
2592 #ifdef ENABLE_COMPLEX_DEPS
2593 if (pool_is_complex_dep(pool, rec))
2594 add_complex_recommends(solv, rec, &dq, &dqmap);
2597 FOR_PROVIDES(p, pp, rec)
2599 if (solv->decisionmap[p] > 0)
2604 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2611 /* multiple candidates, open a branch */
2612 for (i = 1; i < dq.count; i++)
2613 queue_push(&solv->branches, dq.elements[i]);
2614 queue_push(&solv->branches, -level);
2617 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2619 level = setpropagatelearn(solv, level, p, 0, 0);
2620 if (level <= olevel || solv->decisionq.count < decisioncount)
2621 break; /* we had to revert some decisions */
2624 break; /* had a problem above, quit loop */
2629 continue; /* back to main loop so that all deps are checked */
2633 if (!solv->decisioncnt_orphan)
2634 solv->decisioncnt_orphan = solv->decisionq.count;
2635 if (solv->dupmap_all && solv->installed)
2637 int installedone = 0;
2639 /* let's see if we can install some unsupported package */
2640 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2641 for (i = 0; i < solv->orphaned.count; i++)
2643 p = solv->orphaned.elements[i];
2644 if (solv->decisionmap[p])
2645 continue; /* already decided */
2646 if (solv->droporphanedmap_all)
2648 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2650 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2652 level = setpropagatelearn(solv, level, p, 0, 0);
2657 if (installedone || i < solv->orphaned.count)
2661 continue; /* back to main loop */
2663 for (i = 0; i < solv->orphaned.count; i++)
2665 p = solv->orphaned.elements[i];
2666 if (solv->decisionmap[p])
2667 continue; /* already decided */
2668 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2670 level = setpropagatelearn(solv, level, -p, 0, 0);
2674 if (i < solv->orphaned.count)
2678 continue; /* back to main loop */
2682 /* one final pass to make sure we decided all installed packages */
2683 if (solv->installed)
2685 for (p = solv->installed->start; p < solv->installed->end; p++)
2687 if (solv->decisionmap[p])
2688 continue; /* already decided */
2689 s = pool->solvables + p;
2690 if (s->repo != solv->installed)
2692 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2694 level = setpropagatelearn(solv, level, -p, 0, 0);
2698 if (p < solv->installed->end)
2702 continue; /* back to main loop */
2706 if (solv->installed && solv->cleandepsmap.size)
2708 if (cleandeps_check_mistakes(solv, level))
2710 level = 1; /* restart from scratch */
2711 systemlevel = level + 1;
2716 if (solv->solution_callback)
2718 solv->solution_callback(solv, solv->solution_callback_data);
2719 if (solv->branches.count)
2721 int i = solv->branches.count - 1;
2722 int l = -solv->branches.elements[i];
2726 if (solv->branches.elements[i - 1] < 0)
2728 p = solv->branches.elements[i];
2729 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2731 for (j = i + 1; j < solv->branches.count; j++)
2732 queue_push(&dq, solv->branches.elements[j]);
2733 solv->branches.count = i;
2735 revert(solv, level);
2737 for (j = 0; j < dq.count; j++)
2738 queue_push(&solv->branches, dq.elements[j]);
2740 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2742 level = setpropagatelearn(solv, level, p, disablerules, why);
2747 /* all branches done, we're finally finished */
2751 /* auto-minimization step */
2752 if (solv->branches.count)
2754 int l = 0, lasti = -1, lastl = -1;
2758 for (i = solv->branches.count - 1; i >= 0; i--)
2760 p = solv->branches.elements[i];
2763 else if (p > 0 && solv->decisionmap[p] > l + 1)
2771 /* kill old solvable so that we do not loop */
2772 p = solv->branches.elements[lasti];
2773 solv->branches.elements[lasti] = 0;
2774 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2775 minimizationsteps++;
2778 revert(solv, level);
2779 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2782 level = setpropagatelearn(solv, level, p, disablerules, why);
2785 continue; /* back to main loop */
2788 /* no minimization found, we're finally finished! */
2792 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2794 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2800 solv->decisioncnt_update = solv->decisionq.count;
2801 solv->decisioncnt_keep = solv->decisionq.count;
2802 solv->decisioncnt_resolve = solv->decisionq.count;
2803 solv->decisioncnt_weak = solv->decisionq.count;
2804 solv->decisioncnt_orphan = solv->decisionq.count;
2807 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2812 /*-------------------------------------------------------------------
2814 * remove disabled conflicts
2816 * purpose: update the decisionmap after some rules were disabled.
2817 * this is used to calculate the suggested/recommended package list.
2818 * Also returns a "removed" list to undo the discisionmap changes.
2822 removedisabledconflicts(Solver *solv, Queue *removed)
2824 Pool *pool = solv->pool;
2829 Id *decisionmap = solv->decisionmap;
2831 queue_empty(removed);
2832 for (i = 0; i < solv->decisionq.count; i++)
2834 p = solv->decisionq.elements[i];
2836 continue; /* conflicts only, please */
2837 why = solv->decisionq_why.elements[i];
2840 /* no rule involved, must be a orphan package drop */
2843 /* we never do conflicts on free decisions, so there
2844 * must have been an unit rule */
2846 r = solv->rules + why;
2847 if (r->d < 0 && decisionmap[-p])
2849 /* rule is now disabled, remove from decisionmap */
2850 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2851 queue_push(removed, -p);
2852 queue_push(removed, decisionmap[-p]);
2853 decisionmap[-p] = 0;
2856 if (!removed->count)
2858 /* we removed some confliced packages. some of them might still
2859 * be in conflict, so search for unit rules and re-conflict */
2861 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2863 if (i == solv->nrules)
2866 r = solv->rules + i;
2872 if (r->p < 0 && !decisionmap[-r->p])
2878 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2880 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2885 if (r->p < 0 && decisionmap[-r->p] == 0)
2887 if (new || DECISIONMAP_FALSE(r->p))
2889 dp = pool->whatprovidesdata + r->d;
2890 while ((p = *dp++) != 0)
2892 if (new && p == new)
2894 if (p < 0 && decisionmap[-p] == 0)
2903 else if (!DECISIONMAP_FALSE(p))
2913 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2914 decisionmap[-new] = -1;
2916 n = 0; /* redo all rules */
2922 undo_removedisabledconflicts(Solver *solv, Queue *removed)
2925 for (i = 0; i < removed->count; i += 2)
2926 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
2930 /*-------------------------------------------------------------------
2932 * weaken solvable dependencies
2936 weaken_solvable_deps(Solver *solv, Id p)
2941 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
2945 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2946 continue; /* conflict */
2947 queue_push(&solv->weakruleq, i);
2952 /********************************************************************/
2957 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
2960 Id how, what, select;
2962 for (i = 0; i < job->count; i += 2)
2964 how = job->elements[i];
2965 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
2967 what = job->elements[i + 1];
2968 select = how & SOLVER_SELECTMASK;
2969 if (!multiversionmap->size)
2970 map_grow(multiversionmap, pool->nsolvables);
2971 if (select == SOLVER_SOLVABLE_ALL)
2973 FOR_POOL_SOLVABLES(p)
2974 MAPSET(multiversionmap, p);
2976 else if (select == SOLVER_SOLVABLE_REPO)
2979 Repo *repo = pool_id2repo(pool, what);
2981 FOR_REPO_SOLVABLES(repo, p, s)
2982 MAPSET(multiversionmap, p);
2984 FOR_JOB_SELECT(p, pp, select, what)
2985 MAPSET(multiversionmap, p);
2990 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
2992 solver_calculate_multiversionmap(pool, job, multiversionmap);
2996 * add a rule created by a job, record job number and weak flag
2999 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
3001 solver_addrule(solv, p, d);
3002 queue_push(&solv->ruletojob, job);
3004 queue_push(&solv->weakruleq, solv->nrules - 1);
3008 add_cleandeps_package(Solver *solv, Id p)
3010 if (!solv->cleandeps_updatepkgs)
3012 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3013 queue_init(solv->cleandeps_updatepkgs);
3015 queue_pushunique(solv->cleandeps_updatepkgs, p);
3019 add_update_target(Solver *solv, Id p, Id how)
3021 Pool *pool = solv->pool;
3022 Solvable *s = pool->solvables + p;
3023 Repo *installed = solv->installed;
3025 if (!solv->update_targets)
3027 solv->update_targets = solv_calloc(1, sizeof(Queue));
3028 queue_init(solv->update_targets);
3030 if (s->repo == installed)
3032 queue_push2(solv->update_targets, p, p);
3035 FOR_PROVIDES(pi, pip, s->name)
3037 Solvable *si = pool->solvables + pi;
3038 if (si->repo != installed || si->name != s->name)
3040 if (how & SOLVER_FORCEBEST)
3042 if (!solv->bestupdatemap.size)
3043 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3044 MAPSET(&solv->bestupdatemap, pi - installed->start);
3046 if (how & SOLVER_CLEANDEPS)
3047 add_cleandeps_package(solv, pi);
3048 queue_push2(solv->update_targets, pi, p);
3049 /* check if it's ok to keep the installed package */
3050 if (s->evr == si->evr && solvable_identical(s, si))
3051 queue_push2(solv->update_targets, pi, pi);
3055 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3056 while ((obs = *obsp++) != 0)
3058 FOR_PROVIDES(pi, pip, obs)
3060 Solvable *si = pool->solvables + pi;
3061 if (si->repo != installed)
3063 if (si->name == s->name)
3064 continue; /* already handled above */
3065 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3067 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3069 if (how & SOLVER_FORCEBEST)
3071 if (!solv->bestupdatemap.size)
3072 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3073 MAPSET(&solv->bestupdatemap, pi - installed->start);
3075 if (how & SOLVER_CLEANDEPS)
3076 add_cleandeps_package(solv, pi);
3077 queue_push2(solv->update_targets, pi, p);
3084 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3094 transform_update_targets(Solver *solv)
3096 Repo *installed = solv->installed;
3097 Queue *update_targets = solv->update_targets;
3099 Id p, q, lastp, lastq;
3101 if (!update_targets->count)
3103 queue_free(update_targets);
3104 solv->update_targets = solv_free(update_targets);
3107 if (update_targets->count > 2)
3108 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3109 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3111 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3113 if ((p = update_targets->elements[i]) != lastp)
3115 if (!solv->updatemap.size)
3116 map_grow(&solv->updatemap, installed->end - installed->start);
3117 MAPSET(&solv->updatemap, p - installed->start);
3118 update_targets->elements[j++] = 0; /* finish old set */
3119 update_targets->elements[p - installed->start] = j; /* start new set */
3123 if ((q = update_targets->elements[i + 1]) != lastq)
3125 update_targets->elements[j++] = q;
3129 queue_truncate(update_targets, j);
3130 queue_push(update_targets, 0); /* finish last set */
3135 addedmap2deduceq(Solver *solv, Map *addedmap)
3137 Pool *pool = solv->pool;
3142 queue_empty(&solv->addedmap_deduceq);
3143 for (i = 2, j = solv->rpmrules_end - 1; i < pool->nsolvables && j > 0; j--)
3145 r = solv->rules + j;
3148 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3151 if (!MAPTST(addedmap, p))
3153 /* should never happen, but... */
3154 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3155 queue_push(&solv->addedmap_deduceq, -p);
3159 if (MAPTST(addedmap, i))
3160 queue_push(&solv->addedmap_deduceq, i);
3164 for (; i < pool->nsolvables; i++)
3165 if (MAPTST(addedmap, i))
3166 queue_push(&solv->addedmap_deduceq, i);
3168 for (i = 2; i < pool->nsolvables; i++)
3169 if (MAPTST(addedmap, i))
3174 deduceq2addedmap(Solver *solv, Map *addedmap)
3179 for (j = solv->rpmrules_end - 1; j > 0; j--)
3181 r = solv->rules + j;
3182 if (r->d < 0 && r->p)
3183 solver_enablerule(solv, r);
3186 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3189 MAPSET(addedmap, p);
3191 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3193 p = solv->addedmap_deduceq.elements[j];
3195 MAPSET(addedmap, p);
3197 MAPCLR(addedmap, p);
3209 solver_solve(Solver *solv, Queue *job)
3211 Pool *pool = solv->pool;
3212 Repo *installed = solv->installed;
3214 int oldnrules, initialnrules;
3215 Map addedmap; /* '1' == have rpm-rules for solvable */
3216 Map installcandidatemap;
3217 Id how, what, select, name, weak, p, pp, d;
3221 int now, solve_start;
3223 int hasbestinstalljob = 0;
3225 solve_start = solv_timems(0);
3227 /* log solver options */
3228 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3229 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3230 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);
3231 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3232 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3233 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3235 /* create whatprovides if not already there */
3236 if (!pool->whatprovides)
3237 pool_createwhatprovides(pool);
3239 /* create obsolete index */
3240 policy_create_obsolete_index(solv);
3243 queue_free(&solv->job);
3244 queue_init_clone(&solv->job, job);
3245 solv->pooljobcnt = pool->pooljobs.count;
3246 if (pool->pooljobs.count)
3247 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3250 /* free old stuff in jase we re-run a solver */
3251 queuep_free(&solv->update_targets);
3252 queuep_free(&solv->cleandeps_updatepkgs);
3253 queue_empty(&solv->ruleassertions);
3254 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3255 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3256 if (solv->noupdate.size)
3257 map_empty(&solv->noupdate);
3258 map_zerosize(&solv->multiversion);
3259 solv->updatemap_all = 0;
3260 map_zerosize(&solv->updatemap);
3261 solv->bestupdatemap_all = 0;
3262 map_zerosize(&solv->bestupdatemap);
3263 solv->fixmap_all = 0;
3264 map_zerosize(&solv->fixmap);
3265 solv->dupmap_all = 0;
3266 map_zerosize(&solv->dupmap);
3267 map_zerosize(&solv->dupinvolvedmap);
3268 solv->droporphanedmap_all = 0;
3269 map_zerosize(&solv->droporphanedmap);
3270 map_zerosize(&solv->cleandepsmap);
3271 map_zerosize(&solv->weakrulemap);
3272 queue_empty(&solv->weakruleq);
3273 solv->watches = solv_free(solv->watches);
3274 queue_empty(&solv->ruletojob);
3275 if (solv->decisionq.count)
3276 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3277 queue_empty(&solv->decisionq);
3278 queue_empty(&solv->decisionq_why);
3279 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3280 queue_empty(&solv->learnt_why);
3281 queue_empty(&solv->learnt_pool);
3282 queue_empty(&solv->branches);
3283 solv->propagate_index = 0;
3284 queue_empty(&solv->problems);
3285 queue_empty(&solv->solutions);
3286 queue_empty(&solv->orphaned);
3287 solv->stats_learned = solv->stats_unsolvable = 0;
3288 if (solv->recommends_index)
3290 map_empty(&solv->recommendsmap);
3291 map_empty(&solv->suggestsmap);
3292 queuep_free(&solv->recommendscplxq);
3293 queuep_free(&solv->suggestscplxq);
3294 solv->recommends_index = 0;
3296 solv->specialupdaters = solv_free(solv->specialupdaters);
3300 * create basic rule set of all involved packages
3301 * use addedmap bitmap to make sure we don't create rules twice
3304 /* create multiversion map if needed */
3305 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3307 map_init(&addedmap, pool->nsolvables);
3308 MAPSET(&addedmap, SYSTEMSOLVABLE);
3310 map_init(&installcandidatemap, pool->nsolvables);
3313 now = solv_timems(0);
3315 * create rules for all package that could be involved with the solving
3316 * so called: rpm rules
3319 initialnrules = solv->rpmrules_end ? solv->rpmrules_end : 1;
3320 if (initialnrules > 1)
3321 deduceq2addedmap(solv, &addedmap);
3322 if (solv->nrules != initialnrules)
3323 solver_shrinkrules(solv, initialnrules);
3324 solv->nrules = initialnrules;
3325 solv->rpmrules_end = 0;
3329 /* check for update/verify jobs as they need to be known early */
3330 for (i = 0; i < job->count; i += 2)
3332 how = job->elements[i];
3333 what = job->elements[i + 1];
3334 select = how & SOLVER_SELECTMASK;
3335 switch (how & SOLVER_JOBMASK)
3338 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3339 solv->fixmap_all = 1;
3340 FOR_JOB_SELECT(p, pp, select, what)
3342 s = pool->solvables + p;
3343 if (s->repo != installed)
3345 if (!solv->fixmap.size)
3346 map_grow(&solv->fixmap, installed->end - installed->start);
3347 MAPSET(&solv->fixmap, p - installed->start);
3351 if (select == SOLVER_SOLVABLE_ALL)
3353 solv->updatemap_all = 1;
3354 if (how & SOLVER_FORCEBEST)
3355 solv->bestupdatemap_all = 1;
3356 if (how & SOLVER_CLEANDEPS)
3358 FOR_REPO_SOLVABLES(installed, p, s)
3359 add_cleandeps_package(solv, p);
3362 else if (select == SOLVER_SOLVABLE_REPO)
3364 Repo *repo = pool_id2repo(pool, what);
3367 if (repo == installed && !(how & SOLVER_TARGETED))
3369 solv->updatemap_all = 1;
3370 if (how & SOLVER_FORCEBEST)
3371 solv->bestupdatemap_all = 1;
3372 if (how & SOLVER_CLEANDEPS)
3374 FOR_REPO_SOLVABLES(installed, p, s)
3375 add_cleandeps_package(solv, p);
3379 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3381 /* targeted update */
3382 FOR_REPO_SOLVABLES(repo, p, s)
3383 add_update_target(solv, p, how);
3387 if (!(how & SOLVER_TARGETED))
3390 FOR_JOB_SELECT(p, pp, select, what)
3392 s = pool->solvables + p;
3393 if (s->repo != installed)
3395 if (!solv->updatemap.size)
3396 map_grow(&solv->updatemap, installed->end - installed->start);
3397 MAPSET(&solv->updatemap, p - installed->start);
3398 if (how & SOLVER_FORCEBEST)
3400 if (!solv->bestupdatemap.size)
3401 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3402 MAPSET(&solv->bestupdatemap, p - installed->start);
3404 if (how & SOLVER_CLEANDEPS)
3405 add_cleandeps_package(solv, p);
3408 if (!targeted || solv->noautotarget)
3411 FOR_JOB_SELECT(p, pp, select, what)
3412 add_update_target(solv, p, how);
3420 if (solv->update_targets)
3421 transform_update_targets(solv);
3423 oldnrules = solv->nrules;
3424 FOR_REPO_SOLVABLES(installed, p, s)
3425 solver_addrpmrulesforsolvable(solv, s, &addedmap);
3426 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3427 oldnrules = solv->nrules;
3428 FOR_REPO_SOLVABLES(installed, p, s)
3429 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
3430 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3434 * create rules for all packages involved in the job
3435 * (to be installed or removed)
3438 oldnrules = solv->nrules;
3439 for (i = 0; i < job->count; i += 2)
3441 how = job->elements[i];
3442 what = job->elements[i + 1];
3443 select = how & SOLVER_SELECTMASK;
3445 switch (how & SOLVER_JOBMASK)
3447 case SOLVER_INSTALL:
3448 FOR_JOB_SELECT(p, pp, select, what)
3450 MAPSET(&installcandidatemap, p);
3451 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3454 case SOLVER_DISTUPGRADE:
3455 if (select == SOLVER_SOLVABLE_ALL)
3457 solv->dupmap_all = 1;
3458 solv->updatemap_all = 1;
3459 if (how & SOLVER_FORCEBEST)
3460 solv->bestupdatemap_all = 1;
3462 if (!solv->dupmap_all)
3469 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3473 * add rules for suggests, enhances
3475 oldnrules = solv->nrules;
3476 solver_addrpmrulesforweak(solv, &addedmap);
3477 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3479 #ifdef ENABLE_LINKED_PKGS
3480 oldnrules = solv->nrules;
3481 solver_addrpmrulesforlinked(solv, &addedmap);
3482 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of linked packages\n", solv->nrules - oldnrules);
3486 * first pass done, we now have all the rpm rules we need.
3487 * unify existing rules before going over all job rules and
3489 * at this point the system is always solvable,
3490 * as an empty system (remove all packages) is a valid solution
3493 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3495 int possible = 0, installable = 0;
3496 for (i = 1; i < pool->nsolvables; i++)
3498 if (pool_installable(pool, pool->solvables + i))
3500 if (MAPTST(&addedmap, i))
3503 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3506 if (solv->nrules > initialnrules)
3507 solver_unifyrules(solv); /* remove duplicate rpm rules */
3508 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
3510 if (solv->nrules > initialnrules)
3511 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3513 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3514 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
3516 /* create dup maps if needed. We need the maps early to create our
3519 solver_createdupmaps(solv);
3522 * create feature rules
3524 * foreach installed:
3525 * create assertion (keep installed, if no update available)
3527 * create update rule (A|update1(A)|update2(A)|...)
3529 * those are used later on to keep a version of the installed packages in
3533 solv->featurerules = solv->nrules; /* mark start of feature rules */
3536 /* foreach possibly installed solvable */
3537 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3539 if (s->repo != installed)
3541 solver_addrule(solv, 0, 0); /* create dummy rule */
3544 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3546 /* make sure we accounted for all rules */
3547 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3549 solv->featurerules_end = solv->nrules;
3552 * Add update rules for installed solvables
3554 * almost identical to feature rules
3555 * except that downgrades/archchanges/vendorchanges are not allowed
3558 solv->updaterules = solv->nrules;
3561 { /* foreach installed solvables */
3562 /* we create all update rules, but disable some later on depending on the job */
3563 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3567 if (s->repo != installed)
3569 solver_addrule(solv, 0, 0); /* create dummy rule */
3572 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3574 * check for and remove duplicate
3576 r = solv->rules + solv->nrules - 1; /* r: update rule */
3577 sr = r - (installed->end - installed->start); /* sr: feature rule */
3578 /* it's orphaned if there is no feature rule or the feature rule
3579 * consists just of the installed package */
3580 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
3581 queue_push(&solv->orphaned, i);
3584 /* assert(solv->dupmap_all && !sr->p); */
3587 if (!solver_rulecmp(solv, r, sr))
3588 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3590 solver_disablerule(solv, sr); /* disable feature rule */
3592 /* consistency check: we added a rule for _every_ installed solvable */
3593 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3595 solv->updaterules_end = solv->nrules;
3599 * now add all job rules
3602 solv->jobrules = solv->nrules;
3603 for (i = 0; i < job->count; i += 2)
3605 oldnrules = solv->nrules;
3607 if (i && i == solv->pooljobcnt)
3608 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3609 how = job->elements[i];
3610 what = job->elements[i + 1];
3611 weak = how & SOLVER_WEAK;
3612 select = how & SOLVER_SELECTMASK;
3613 switch (how & SOLVER_JOBMASK)
3615 case SOLVER_INSTALL:
3616 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3617 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3618 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3619 if (select == SOLVER_SOLVABLE)
3627 FOR_JOB_SELECT(p, pp, select, what)
3631 if (select == SOLVER_SOLVABLE_ONE_OF)
3632 break; /* ignore empty installs */
3633 /* no candidate found or unsupported, make this an impossible rule */
3634 queue_push(&q, -SYSTEMSOLVABLE);
3636 p = queue_shift(&q); /* get first candidate */
3637 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3639 /* force install of namespace supplements hack */
3640 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3642 Reldep *rd = GETRELDEP(pool, what);
3643 if (rd->flags == REL_NAMESPACE)
3646 if (!solv->installsuppdepq)
3648 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3649 queue_init(solv->installsuppdepq);
3651 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3654 solver_addjobrule(solv, p, d, i, weak);
3655 if (how & SOLVER_FORCEBEST)
3656 hasbestinstalljob = 1;
3659 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3660 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3661 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3662 /* specific solvable: by id or by nevra */
3663 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3664 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3666 FOR_POOL_SOLVABLES(p)
3667 solver_addjobrule(solv, -p, 0, i, weak);
3669 else if (select == SOLVER_SOLVABLE_REPO)
3671 Repo *repo = pool_id2repo(pool, what);
3673 FOR_REPO_SOLVABLES(repo, p, s)
3674 solver_addjobrule(solv, -p, 0, i, weak);
3676 FOR_JOB_SELECT(p, pp, select, what)
3678 s = pool->solvables + p;
3679 if (installed && s->repo == installed)
3680 name = !name ? s->name : -1;
3681 solver_addjobrule(solv, -p, 0, i, weak);
3683 /* special case for "erase a specific solvable": we also
3684 * erase all other solvables with that name, so that they
3685 * don't get picked up as replacement.
3686 * name is > 0 if exactly one installed solvable matched.
3688 /* XXX: look also at packages that obsolete this package? */
3693 FOR_PROVIDES(p, pp, name)
3695 s = pool->solvables + p;
3696 if (s->name != name)
3698 /* keep other versions installed */
3699 if (s->repo == installed)
3701 /* keep installcandidates of other jobs */
3702 if (MAPTST(&installcandidatemap, p))
3704 /* don't add the same rule twice */
3705 for (j = oldnrules; j < k; j++)
3706 if (solv->rules[j].p == -p)
3709 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
3715 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3718 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3720 case SOLVER_WEAKENDEPS:
3721 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3722 if (select != SOLVER_SOLVABLE)
3724 s = pool->solvables + what;
3725 weaken_solvable_deps(solv, what);
3727 case SOLVER_MULTIVERSION:
3728 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3731 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3732 if (select == SOLVER_SOLVABLE_ALL)
3734 FOR_POOL_SOLVABLES(p)
3735 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3737 else if (select == SOLVER_SOLVABLE_REPO)
3739 Repo *repo = pool_id2repo(pool, what);
3741 FOR_REPO_SOLVABLES(repo, p, s)
3742 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3744 FOR_JOB_SELECT(p, pp, select, what)
3745 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3747 case SOLVER_DISTUPGRADE:
3748 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3750 case SOLVER_DROP_ORPHANED:
3751 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3752 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3753 solv->droporphanedmap_all = 1;
3754 FOR_JOB_SELECT(p, pp, select, what)
3756 s = pool->solvables + p;
3757 if (!installed || s->repo != installed)
3759 if (!solv->droporphanedmap.size)
3760 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3761 MAPSET(&solv->droporphanedmap, p - installed->start);
3764 case SOLVER_USERINSTALLED:
3765 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3768 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3776 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3779 if (solv->nrules == oldnrules)
3780 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3781 for (j = oldnrules; j < solv->nrules; j++)
3783 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3784 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3788 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3789 solv->jobrules_end = solv->nrules;
3791 /* now create infarch and dup rules */
3792 if (!solv->noinfarchcheck)
3794 solver_addinfarchrules(solv, &addedmap);
3796 if (pool->implicitobsoleteusescolors)
3798 /* currently doesn't work well with infarch rules, so make
3800 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3801 queue_push(&solv->weakruleq, i);
3806 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3809 solver_addduprules(solv, &addedmap);
3811 solv->duprules = solv->duprules_end = solv->nrules;
3813 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3814 solver_addbestrules(solv, hasbestinstalljob);
3816 solv->bestrules = solv->bestrules_end = solv->nrules;
3819 solver_freedupmaps(solv); /* no longer needed */
3822 solver_addchoicerules(solv);
3824 solv->choicerules = solv->choicerules_end = solv->nrules;
3828 for (i = solv->featurerules; i < solv->nrules; i++)
3829 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3831 /* all rules created
3832 * --------------------------------------------------------------
3833 * prepare for solving
3836 /* free unneeded memory */
3837 map_free(&addedmap);
3838 map_free(&installcandidatemap);
3841 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);
3842 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3844 /* create weak map */
3845 map_init(&solv->weakrulemap, solv->nrules);
3846 for (i = 0; i < solv->weakruleq.count; i++)
3848 p = solv->weakruleq.elements[i];
3849 MAPSET(&solv->weakrulemap, p);
3852 /* enable cleandepsmap creation if we have updatepkgs */
3853 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
3854 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3856 if (solv->cleandeps_mistakes)
3858 queue_free(solv->cleandeps_mistakes);
3859 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3862 /* all new rules are learnt after this point */
3863 solv->learntrules = solv->nrules;
3865 /* create watches chains */
3868 /* create assertion index. it is only used to speed up
3869 * makeruledecsions() a bit */
3870 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3871 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3872 queue_push(&solv->ruleassertions, i);
3874 /* disable update rules that conflict with our job */
3875 solver_disablepolicyrules(solv);
3877 /* make initial decisions based on assertion rules */
3878 makeruledecisions(solv);
3879 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3882 * ********************************************
3884 * ********************************************
3887 now = solv_timems(0);
3888 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3889 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3892 * prepare solution queue if there were problems
3894 solver_prepare_solutions(solv);
3896 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);
3897 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3899 /* return number of problems */
3900 return solv->problems.count ? solv->problems.count / 2 : 0;
3904 solver_create_transaction(Solver *solv)
3906 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
3909 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3911 queue_free(orphanedq);
3912 queue_init_clone(orphanedq, &solv->orphaned);
3915 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
3917 Pool *pool = solv->pool;
3918 Queue redoq, disabledq;
3924 if (!recommendationsq && !suggestionsq)
3927 map_init(&obsmap, pool->nsolvables);
3928 if (solv->installed)
3930 Id obs, *obsp, p, po, ppo;
3931 for (p = solv->installed->start; p < solv->installed->end; p++)
3933 s = pool->solvables + p;
3934 if (s->repo != solv->installed || !s->obsoletes)
3936 if (solv->decisionmap[p] <= 0)
3938 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
3940 obsp = s->repo->idarraydata + s->obsoletes;
3941 /* foreach obsoletes */
3942 while ((obs = *obsp++) != 0)
3943 FOR_PROVIDES(po, ppo, obs)
3944 MAPSET(&obsmap, po);
3949 queue_init(&disabledq);
3951 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3952 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
3954 if (r->d < 0) /* disabled ? */
3956 if (r->p >= 0) /* install job? */
3958 queue_push(&disabledq, i);
3959 solver_disablerule(solv, r);
3965 enabledisablelearntrules(solv);
3966 removedisabledconflicts(solv, &redoq);
3970 * find recommended packages
3972 if (recommendationsq)
3974 Id rec, *recp, p, pp;
3976 queue_empty(recommendationsq);
3977 /* create map of all recommened packages */
3978 solv->recommends_index = -1;
3979 MAPZERO(&solv->recommendsmap);
3981 /* put all packages the solver already chose in the map */
3982 if (solv->decisioncnt_weak)
3984 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
3987 why = solv->decisionq_why.elements[i];
3989 continue; /* forced by unit rule or dep resolving */
3990 p = solv->decisionq.elements[i];
3993 MAPSET(&solv->recommendsmap, p);
3997 for (i = 0; i < solv->decisionq.count; i++)
3999 p = solv->decisionq.elements[i];
4002 s = pool->solvables + p;
4005 recp = s->repo->idarraydata + s->recommends;
4006 while ((rec = *recp++) != 0)
4008 #ifdef ENABLE_COMPLEX_DEPS
4009 if (pool_is_complex_dep(pool, rec))
4011 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4015 FOR_PROVIDES(p, pp, rec)
4016 if (solv->decisionmap[p] > 0)
4022 FOR_PROVIDES(p, pp, rec)
4023 if (solv->decisionmap[p] > 0)
4024 MAPSET(&solv->recommendsmap, p);
4026 continue; /* p != 0: already fulfilled */
4028 FOR_PROVIDES(p, pp, rec)
4029 MAPSET(&solv->recommendsmap, p);
4033 for (i = 1; i < pool->nsolvables; i++)
4035 if (solv->decisionmap[i] < 0)
4037 if (solv->decisionmap[i] > 0 && noselected)
4039 if (MAPTST(&obsmap, i))
4041 s = pool->solvables + i;
4042 if (!MAPTST(&solv->recommendsmap, i))
4044 if (!s->supplements)
4046 if (!pool_installable(pool, s))
4048 if (!solver_is_supplementing(solv, s))
4051 queue_push(recommendationsq, i);
4053 /* we use MODE_SUGGEST here so that repo prio is ignored */
4054 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4058 * find suggested packages
4063 Id sug, *sugp, p, pp;
4065 queue_empty(suggestionsq);
4066 /* create map of all suggests that are still open */
4067 solv->recommends_index = -1;
4068 MAPZERO(&solv->suggestsmap);
4069 for (i = 0; i < solv->decisionq.count; i++)
4071 p = solv->decisionq.elements[i];
4074 s = pool->solvables + p;
4077 sugp = s->repo->idarraydata + s->suggests;
4078 while ((sug = *sugp++) != 0)
4080 #ifdef ENABLE_COMPLEX_DEPS
4081 if (pool_is_complex_dep(pool, sug))
4083 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4087 FOR_PROVIDES(p, pp, sug)
4088 if (solv->decisionmap[p] > 0)
4094 FOR_PROVIDES(p, pp, sug)
4095 if (solv->decisionmap[p] > 0)
4096 MAPSET(&solv->suggestsmap, p);
4098 continue; /* already fulfilled */
4100 FOR_PROVIDES(p, pp, sug)
4101 MAPSET(&solv->suggestsmap, p);
4105 for (i = 1; i < pool->nsolvables; i++)
4107 if (solv->decisionmap[i] < 0)
4109 if (solv->decisionmap[i] > 0 && noselected)
4111 if (MAPTST(&obsmap, i))
4113 s = pool->solvables + i;
4114 if (!MAPTST(&solv->suggestsmap, i))
4118 if (!pool_installable(pool, s))
4120 if (!solver_is_enhancing(solv, s))
4123 queue_push(suggestionsq, i);
4125 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4128 /* undo removedisabledconflicts */
4130 undo_removedisabledconflicts(solv, &redoq);
4133 /* undo job rule disabling */
4134 for (i = 0; i < disabledq.count; i++)
4135 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4136 queue_free(&disabledq);
4141 /***********************************************************************/
4142 /* disk usage computations */
4144 /*-------------------------------------------------------------------
4146 * calculate DU changes
4150 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4154 solver_create_state_maps(solv, &installedmap, 0);
4155 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4156 map_free(&installedmap);
4160 /*-------------------------------------------------------------------
4162 * calculate changes in install size
4166 solver_calc_installsizechange(Solver *solv)
4171 solver_create_state_maps(solv, &installedmap, 0);
4172 change = pool_calc_installsizechange(solv->pool, &installedmap);
4173 map_free(&installedmap);
4178 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4180 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4184 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4186 Pool *pool = solv->pool;
4189 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4190 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4191 for (i = 0; i < res->count; i++)
4192 if (res->elements[i] != -1)
4194 Solvable *s = pool->solvables + pkgs->elements[i];
4195 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4196 res->elements[i] = -1;
4198 map_free(&installedmap);
4201 /*-------------------------------------------------------------------
4203 * decision introspection
4207 solver_get_decisionlevel(Solver *solv, Id p)
4209 return solv->decisionmap[p];
4213 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4215 queue_free(decisionq);
4216 queue_init_clone(decisionq, &solv->decisionq);
4220 solver_get_lastdecisionblocklevel(Solver *solv)
4223 if (solv->decisionq.count == 0)
4225 p = solv->decisionq.elements[solv->decisionq.count - 1];
4228 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4232 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4237 queue_empty(decisionq);
4238 for (i = 0; i < solv->decisionq.count; i++)
4240 p = solv->decisionq.elements[i];
4243 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4246 if (i == solv->decisionq.count)
4248 for (i = 0; i < solv->decisionq.count; i++)
4250 p = solv->decisionq.elements[i];
4253 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4254 queue_push(decisionq, p);
4261 solver_describe_decision(Solver *solv, Id p, Id *infop)
4268 if (!solv->decisionmap[p])
4269 return SOLVER_REASON_UNRELATED;
4270 pp = solv->decisionmap[p] < 0 ? -p : p;
4271 for (i = 0; i < solv->decisionq.count; i++)
4272 if (solv->decisionq.elements[i] == pp)
4274 if (i == solv->decisionq.count) /* just in case... */
4275 return SOLVER_REASON_UNRELATED;
4276 why = solv->decisionq_why.elements[i];
4278 *infop = why > 0 ? why : -why;
4280 return SOLVER_REASON_UNIT_RULE;
4282 if (i < solv->decisioncnt_update)
4285 return SOLVER_REASON_KEEP_INSTALLED;
4286 return SOLVER_REASON_RESOLVE_JOB;
4288 if (i < solv->decisioncnt_keep)
4290 if (why == 0 && pp < 0)
4291 return SOLVER_REASON_CLEANDEPS_ERASE;
4292 return SOLVER_REASON_UPDATE_INSTALLED;
4294 if (i < solv->decisioncnt_resolve)
4296 if (why == 0 && pp < 0)
4297 return SOLVER_REASON_CLEANDEPS_ERASE;
4298 return SOLVER_REASON_KEEP_INSTALLED;
4301 return SOLVER_REASON_RESOLVE;
4302 /* weak or orphaned */
4303 if (solv->decisionq.count < solv->decisioncnt_orphan)
4304 return SOLVER_REASON_WEAKDEP;
4305 return SOLVER_REASON_RESOLVE_ORPHAN;
4310 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4312 Pool *pool = solv->pool;
4314 int level = solv->decisionmap[p];
4321 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4322 if (solv->decisionq.elements[decisionno] == p)
4324 if (decisionno == solv->decisionq.count)
4326 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4329 /* 1) list all packages that recommend us */
4330 for (i = 1; i < pool->nsolvables; i++)
4332 Id *recp, rec, pp2, p2;
4333 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4335 s = pool->solvables + i;
4338 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4340 recp = s->repo->idarraydata + s->recommends;
4341 while ((rec = *recp++) != 0)
4344 FOR_PROVIDES(p2, pp2, rec)
4350 /* if p2 is already installed, this recommends is ignored */
4351 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4357 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4358 queue_push2(whyq, p2, rec);
4362 /* 2) list all supplements */
4363 s = pool->solvables + p;
4364 if (s->supplements && level > 0)
4366 Id *supp, sup, pp2, p2;
4367 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4368 * everything above our level in the decisionmap */
4369 for (i = decisionno; i < solv->decisionq.count; i++ )
4371 p2 = solv->decisionq.elements[i];
4373 solv->decisionmap[p2] = -solv->decisionmap[p2];
4375 supp = s->repo->idarraydata + s->supplements;
4376 while ((sup = *supp++) != 0)
4377 if (solver_dep_fulfilled(solv, sup))
4380 /* let's see if this is an easy supp */
4381 FOR_PROVIDES(p2, pp2, sup)
4383 if (!solv->addalreadyrecommended && solv->installed)
4385 if (pool->solvables[p2].repo == solv->installed)
4388 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4390 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4391 queue_push2(whyq, p2, sup);
4397 /* hard case, just note dependency with no package */
4398 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4399 queue_push2(whyq, 0, sup);
4402 for (i = decisionno; i < solv->decisionq.count; i++)
4404 p2 = solv->decisionq.elements[i];
4406 solv->decisionmap[p2] = -solv->decisionmap[p2];
4412 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4415 how &= SOLVER_SELECTMASK;
4417 if (how == SOLVER_SOLVABLE_ALL)
4419 FOR_POOL_SOLVABLES(p)
4420 queue_push(pkgs, p);
4422 else if (how == SOLVER_SOLVABLE_REPO)
4424 Repo *repo = pool_id2repo(pool, what);
4427 FOR_REPO_SOLVABLES(repo, p, s)
4428 queue_push(pkgs, p);
4432 FOR_JOB_SELECT(p, pp, how, what)
4433 queue_push(pkgs, p);
4438 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4441 Id select = how & SOLVER_SELECTMASK;
4442 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4444 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4446 if (!pool->installed)
4448 FOR_JOB_SELECT(p, pp, select, what)
4449 if (pool->solvables[p].repo == pool->installed)
4452 FOR_JOB_SELECT(p, pp, select, what)
4454 Solvable *s = pool->solvables + p;
4455 FOR_PROVIDES(pi, pip, s->name)
4457 Solvable *si = pool->solvables + pi;
4458 if (si->repo != pool->installed || si->name != s->name)
4464 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4465 while ((obs = *obsp++) != 0)
4467 FOR_PROVIDES(pi, pip, obs)
4469 Solvable *si = pool->solvables + pi;
4470 if (si->repo != pool->installed)
4472 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4474 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4485 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4487 return *(Id *)ap - *(Id *)bp;
4491 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4494 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4498 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4502 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4503 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4505 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4506 for (i = j = 0; i < q->count; i++)
4507 if (q->elements[i] != lastp)
4508 q->elements[j++] = lastp = q->elements[i];
4509 queue_truncate(q, j);
4513 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4515 Pool *pool = solv->pool;
4518 Repo *installed = solv->installed;
4522 map_init(&userinstalled, 0);
4524 /* first process jobs */
4525 for (i = 0; i < solv->job.count; i += 2)
4527 Id how = solv->job.elements[i];
4529 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4531 if (!userinstalled.size)
4532 map_grow(&userinstalled, installed->end - installed->start);
4533 what = solv->job.elements[i + 1];
4534 select = how & SOLVER_SELECTMASK;
4535 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4536 FOR_REPO_SOLVABLES(installed, p, s)
4537 MAPSET(&userinstalled, p - installed->start);
4538 FOR_JOB_SELECT(p, pp, select, what)
4539 if (pool->solvables[p].repo == installed)
4540 MAPSET(&userinstalled, p - installed->start);
4543 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4545 if ((how & SOLVER_NOTBYUSER) != 0)
4547 what = solv->job.elements[i + 1];
4548 select = how & SOLVER_SELECTMASK;
4549 FOR_JOB_SELECT(p, pp, select, what)
4550 if (solv->decisionmap[p] > 0)
4553 #ifdef ENABLE_LINKED_PKGS
4554 if (has_package_link(pool, pool->solvables + p))
4559 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4560 for (j = 0; j < lq.count; j++)
4561 if (solv->decisionmap[lq.elements[j]] > 0)
4562 queue_push(q, lq.elements[j]);
4567 /* now process updates of userinstalled packages */
4568 if (installed && userinstalled.size)
4570 for (i = 1; i < solv->decisionq.count; i++)
4572 p = solv->decisionq.elements[i];
4575 s = pool->solvables + p;
4578 if (s->repo == installed)
4580 if (MAPTST(&userinstalled, p - installed->start))
4584 /* new package, check if we replace a userinstalled one */
4585 FOR_PROVIDES(p2, pp, s->name)
4587 Solvable *ps = pool->solvables + p2;
4588 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4590 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
4592 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
4597 if (!p2 && s->repo != installed && s->obsoletes)
4599 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4600 while ((obs = *obsp++) != 0)
4602 FOR_PROVIDES(p2, pp, obs)
4604 Solvable *ps = pool->solvables + p2;
4605 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4607 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
4609 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
4620 map_free(&userinstalled);
4621 /* convert to names if asked */
4622 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4624 for (i = 0; i < q->count; i++)
4626 s = pool->solvables + q->elements[i];
4627 q->elements[i] = s->name;
4630 /* sort and unify */
4632 get_userinstalled_sort_uniq(pool, q, flags);
4633 /* invert if asked */
4634 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4636 /* first generate queue with all installed packages */
4639 for (i = 1; i < solv->decisionq.count; i++)
4641 p = solv->decisionq.elements[i];
4644 s = pool->solvables + p;
4647 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4648 queue_push(&invq, s->name);
4650 queue_push(&invq, p);
4652 /* push q on invq, just in case... */
4653 queue_insertn(&invq, invq.count, q->count, q->elements);
4655 get_userinstalled_sort_uniq(pool, &invq, flags);
4656 /* subtract queues (easy as they are sorted and invq is a superset of q) */
4659 for (i = j = 0; i < invq.count; i++)
4660 if (invq.elements[i] == q->elements[j])
4662 invq.elements[i] = 0;
4663 if (++j >= q->count)
4668 for (i = j = 0; i < invq.count; i++)
4669 if (invq.elements[i])
4670 queue_push(q, invq.elements[i]);
4676 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
4680 if (flags & GET_USERINSTALLED_INVERTED)
4686 if (!pool->installed)
4689 FOR_REPO_SOLVABLES(pool->installed, p, s)
4690 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
4691 queue_insertn(&invq, invq.count, q->count, q->elements);
4693 get_userinstalled_sort_uniq(pool, &invq, flags);
4694 /* now the fun part, add q again, sort, and remove all dups */
4695 queue_insertn(&invq, invq.count, q->count, q->elements);
4698 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4699 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
4701 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
4705 for (i = 0; i < invq.count; i++)
4707 if (invq.elements[i] == lastid)
4713 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4715 lastid = invq.elements[i];
4718 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4723 for (i = 0; i < q->count; i++)
4724 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
4729 solver_select2str(Pool *pool, Id select, Id what)
4733 select &= SOLVER_SELECTMASK;
4734 if (select == SOLVER_SOLVABLE)
4735 return pool_solvid2str(pool, what);
4736 if (select == SOLVER_SOLVABLE_NAME)
4737 return pool_dep2str(pool, what);
4738 if (select == SOLVER_SOLVABLE_PROVIDES)
4740 s = pool_dep2str(pool, what);
4741 b = pool_alloctmpspace(pool, 11 + strlen(s));
4742 sprintf(b, "providing %s", s);
4745 if (select == SOLVER_SOLVABLE_ONE_OF)
4749 while ((p = pool->whatprovidesdata[what++]) != 0)
4751 s = pool_solvid2str(pool, p);
4753 b = pool_tmpappend(pool, b, ", ", s);
4755 b = pool_tmpjoin(pool, s, 0, 0);
4756 pool_freetmpspace(pool, s);
4758 return b ? b : "nothing";
4760 if (select == SOLVER_SOLVABLE_REPO)
4762 b = pool_alloctmpspace(pool, 20);
4763 sprintf(b, "repo #%d", what);
4766 if (select == SOLVER_SOLVABLE_ALL)
4767 return "all packages";
4768 return "unknown job select";
4772 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
4774 Id select = how & SOLVER_SELECTMASK;
4775 const char *strstart = 0, *strend = 0;
4779 switch (how & SOLVER_JOBMASK)
4782 return "do nothing";
4783 case SOLVER_INSTALL:
4784 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
4785 strstart = "keep ", strend = " installed";
4786 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
4787 strstart = "install ";
4788 else if (select == SOLVER_SOLVABLE_PROVIDES)
4789 strstart = "install a package ";
4791 strstart = "install one of ";
4794 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
4795 strstart = "keep ", strend = " uninstalled";
4796 else if (select == SOLVER_SOLVABLE_PROVIDES)
4797 strstart = "deinstall all packages ";
4799 strstart = "deinstall ";
4802 strstart = "update ";
4804 case SOLVER_WEAKENDEPS:
4805 strstart = "weaken deps of ";
4807 case SOLVER_MULTIVERSION:
4808 strstart = "multi version ";
4813 case SOLVER_DISTUPGRADE:
4814 strstart = "dist upgrade ";
4817 strstart = "verify ";
4819 case SOLVER_DROP_ORPHANED:
4820 strstart = "deinstall ", strend = " if orphaned";
4822 case SOLVER_USERINSTALLED:
4823 strstart = "regard ", strend = " as userinstalled";
4826 strstart = "unknown job ";
4829 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
4831 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
4834 s = pool_tmpappend(pool, s, " ", 0);
4835 if (how & SOLVER_WEAK)
4836 s = pool_tmpappend(pool, s, ",weak", 0);
4837 if (how & SOLVER_ESSENTIAL)
4838 s = pool_tmpappend(pool, s, ",essential", 0);
4839 if (how & SOLVER_CLEANDEPS)
4840 s = pool_tmpappend(pool, s, ",cleandeps", 0);
4841 if (how & SOLVER_ORUPDATE)
4842 s = pool_tmpappend(pool, s, ",orupdate", 0);
4843 if (how & SOLVER_FORCEBEST)
4844 s = pool_tmpappend(pool, s, ",forcebest", 0);
4845 if (how & SOLVER_TARGETED)
4846 s = pool_tmpappend(pool, s, ",targeted", 0);
4847 if (how & SOLVER_SETEV)
4848 s = pool_tmpappend(pool, s, ",setev", 0);
4849 if (how & SOLVER_SETEVR)
4850 s = pool_tmpappend(pool, s, ",setevr", 0);
4851 if (how & SOLVER_SETARCH)
4852 s = pool_tmpappend(pool, s, ",setarch", 0);
4853 if (how & SOLVER_SETVENDOR)
4854 s = pool_tmpappend(pool, s, ",setvendor", 0);
4855 if (how & SOLVER_SETREPO)
4856 s = pool_tmpappend(pool, s, ",setrepo", 0);
4857 if (how & SOLVER_SETNAME)
4858 s = pool_tmpappend(pool, s, ",setname", 0);
4859 if (how & SOLVER_NOAUTOSET)
4860 s = pool_tmpappend(pool, s, ",noautoset", 0);
4861 if (s[o + 1] != ',')
4862 s = pool_tmpappend(pool, s, ",?", 0);
4864 return pool_tmpappend(pool, s, "]", 0);