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 #define RULES_BLOCK 63
31 /********************************************************************
33 * dependency check helpers
37 /*-------------------------------------------------------------------
38 * handle split provides
40 * a splitprovides dep looks like
41 * namespace:splitprovides(pkg REL_WITH path)
42 * and is only true if pkg is installed and contains the specified path.
43 * we also make sure that pkg is selected for an update, otherwise the
44 * update would always be forced onto the user.
47 solver_splitprovides(Solver *solv, Id dep)
49 Pool *pool = solv->pool;
54 if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
58 rd = GETRELDEP(pool, dep);
59 if (rd->flags != REL_WITH)
61 FOR_PROVIDES(p, pp, dep)
63 /* here we have packages that provide the correct name and contain the path,
64 * now do extra filtering */
65 s = pool->solvables + p;
66 if (s->repo == solv->installed && s->name == rd->name &&
67 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
74 /*-------------------------------------------------------------------
75 * solver_dep_installed
79 solver_dep_installed(Solver *solv, Id dep)
82 Pool *pool = solv->pool;
87 Reldep *rd = GETRELDEP(pool, dep);
88 if (rd->flags == REL_AND)
90 if (!solver_dep_installed(solv, rd->name))
92 return solver_dep_installed(solv, rd->evr);
94 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
95 return solver_dep_installed(solv, rd->evr);
97 FOR_PROVIDES(p, pp, dep)
99 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
106 /* mirrors solver_dep_installed, but returns 2 if a
107 * dependency listed in solv->installsuppdepq was involved */
109 solver_check_installsuppdepq_dep(Solver *solv, Id dep)
111 Pool *pool = solv->pool;
117 Reldep *rd = GETRELDEP(pool, dep);
118 if (rd->flags == REL_AND)
120 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
123 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
126 return r1 == 2 || r2 == 2 ? 2 : 1;
128 if (rd->flags == REL_OR)
130 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
131 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
134 return r1 == 2 || r2 == 2 ? 2 : 1;
136 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
137 return solver_splitprovides(solv, rd->evr);
138 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
139 return solver_dep_installed(solv, rd->evr);
140 if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
143 for (i = 0; i < q->count; i++)
144 if (q->elements[i] == dep || q->elements[i] == rd->name)
148 FOR_PROVIDES(p, pp, dep)
149 if (solv->decisionmap[p] > 0)
155 solver_check_installsuppdepq(Solver *solv, Solvable *s)
158 supp = s->repo->idarraydata + s->supplements;
159 while ((sup = *supp++) != 0)
160 if (solver_check_installsuppdepq_dep(solv, sup) == 2)
166 autouninstall(Solver *solv, Id *problem)
168 Pool *pool = solv->pool;
170 int lastfeature = 0, lastupdate = 0;
174 for (i = 0; (v = problem[i]) != 0; i++)
177 extraflags &= solv->job.elements[-v - 1];
178 if (v >= solv->featurerules && v < solv->featurerules_end)
181 if (v >= solv->updaterules && v < solv->updaterules_end)
183 /* check if identical to feature rule */
184 Id p = solv->rules[v].p;
188 r = solv->rules + solv->featurerules + (p - solv->installed->start);
191 /* update rule == feature rule */
200 if (!lastupdate && !lastfeature)
202 v = lastupdate ? lastupdate : lastfeature;
203 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
204 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
205 solver_disableproblem(solv, v);
206 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
208 /* add the package to the updatepkgs list, this will automatically turn
209 * on cleandeps mode */
210 Id p = solv->rules[v].p;
211 if (!solv->cleandeps_updatepkgs)
213 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
214 queue_init(solv->cleandeps_updatepkgs);
218 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
219 queue_pushunique(solv->cleandeps_updatepkgs, p);
220 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
221 solver_disablepolicyrules(solv);
227 /************************************************************************/
230 * enable/disable learnt rules
232 * we have enabled or disabled some of our rules. We now reenable all
233 * of our learnt rules except the ones that were learnt from rules that
237 enabledisablelearntrules(Solver *solv)
239 Pool *pool = solv->pool;
244 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
245 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
247 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
248 while ((why = *whyp++) != 0)
250 assert(why > 0 && why < i);
251 if (solv->rules[why].d < 0)
254 /* why != 0: we found a disabled rule, disable the learnt rule */
255 if (why && r->d >= 0)
257 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
259 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
260 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
262 solver_disablerule(solv, r);
264 else if (!why && r->d < 0)
266 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
268 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
269 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
271 solver_enablerule(solv, r);
278 * make assertion rules into decisions
280 * Go through rules and add direct assertions to the decisionqueue.
281 * If we find a conflict, disable rules and add them to problem queue.
285 makeruledecisions(Solver *solv)
287 Pool *pool = solv->pool;
292 int record_proof = 1;
294 int havedisabled = 0;
296 /* The system solvable is always installed first */
297 assert(solv->decisionq.count == 0);
298 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
299 queue_push(&solv->decisionq_why, 0);
300 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
302 decisionstart = solv->decisionq.count;
305 /* if we needed to re-run, back up decisions to decisionstart */
306 while (solv->decisionq.count > decisionstart)
308 v = solv->decisionq.elements[--solv->decisionq.count];
309 --solv->decisionq_why.count;
311 solv->decisionmap[vv] = 0;
314 /* note that the ruleassertions queue is ordered */
315 for (ii = 0; ii < solv->ruleassertions.count; ii++)
317 ri = solv->ruleassertions.elements[ii];
318 r = solv->rules + ri;
320 if (havedisabled && ri >= solv->learntrules)
322 /* just started with learnt rule assertions. If we have disabled
323 * some rules, adapt the learnt rule status */
324 enabledisablelearntrules(solv);
328 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
331 /* do weak rules in phase 2 */
332 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
338 if (!solv->decisionmap[vv]) /* if not yet decided */
340 queue_push(&solv->decisionq, v);
341 queue_push(&solv->decisionq_why, r - solv->rules);
342 solv->decisionmap[vv] = v > 0 ? 1 : -1;
343 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
345 Solvable *s = solv->pool->solvables + vv;
347 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
349 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
354 /* check against previous decision: is there a conflict? */
355 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
357 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
363 * The rule (r) we're currently processing says something
364 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
368 if (ri >= solv->learntrules)
370 /* conflict with a learnt rule */
371 /* can happen when packages cannot be installed for multiple reasons. */
372 /* we disable the learnt rule in this case */
373 /* (XXX: we should really call analyze_unsolvable_rule here!) */
374 solver_disablerule(solv, r);
379 * find the decision which is the "opposite" of the rule
381 for (i = 0; i < solv->decisionq.count; i++)
382 if (solv->decisionq.elements[i] == -v)
384 assert(i < solv->decisionq.count); /* assert that we found it */
385 oldproblemcount = solv->problems.count;
388 * conflict with system solvable ?
390 if (v == -SYSTEMSOLVABLE)
394 queue_push(&solv->problems, solv->learnt_pool.count);
395 queue_push(&solv->learnt_pool, ri);
396 queue_push(&solv->learnt_pool, 0);
399 queue_push(&solv->problems, 0);
400 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
401 if (ri >= solv->jobrules && ri < solv->jobrules_end)
402 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
405 queue_push(&solv->problems, v);
406 queue_push(&solv->problems, 0);
407 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
408 solv->problems.count = oldproblemcount;
409 solver_disableproblem(solv, v);
411 break; /* start over */
414 assert(solv->decisionq_why.elements[i] > 0);
417 * conflict with an rpm rule ?
419 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
423 queue_push(&solv->problems, solv->learnt_pool.count);
424 queue_push(&solv->learnt_pool, ri);
425 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
426 queue_push(&solv->learnt_pool, 0);
429 queue_push(&solv->problems, 0);
430 assert(v > 0 || v == -SYSTEMSOLVABLE);
431 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
432 if (ri >= solv->jobrules && ri < solv->jobrules_end)
433 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
436 queue_push(&solv->problems, v);
437 queue_push(&solv->problems, 0);
438 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
439 solv->problems.count = oldproblemcount;
440 solver_disableproblem(solv, v);
442 break; /* start over */
446 * conflict with another job or update/feature rule
452 queue_push(&solv->problems, solv->learnt_pool.count);
453 queue_push(&solv->learnt_pool, ri);
454 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
455 queue_push(&solv->learnt_pool, 0);
458 queue_push(&solv->problems, 0);
460 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
463 * push all of our rules (can only be feature or job rules)
464 * asserting this literal on the problem stack
466 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
468 if (rr->d < 0 /* disabled */
469 || rr->w2) /* or no assertion */
471 if (rr->p != vv /* not affecting the literal */
474 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
477 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
478 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
481 if (i >= solv->jobrules && i < solv->jobrules_end)
482 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
483 queue_push(&solv->problems, v);
485 queue_push(&solv->problems, 0);
487 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
488 solv->problems.count = oldproblemcount;
490 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
491 solver_disableproblem(solv, solv->problems.elements[i]);
493 break; /* start over */
495 if (ii < solv->ruleassertions.count)
499 * phase 2: now do the weak assertions
501 for (ii = 0; ii < solv->ruleassertions.count; ii++)
503 ri = solv->ruleassertions.elements[ii];
504 r = solv->rules + ri;
505 if (r->d < 0 || r->w2) /* disabled or no assertion */
507 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
512 if (!solv->decisionmap[vv]) /* if not yet decided */
514 queue_push(&solv->decisionq, v);
515 queue_push(&solv->decisionq_why, r - solv->rules);
516 solv->decisionmap[vv] = v > 0 ? 1 : -1;
517 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
519 Solvable *s = solv->pool->solvables + vv;
521 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
523 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
527 /* check against previous decision: is there a conflict? */
528 if (v > 0 && solv->decisionmap[vv] > 0)
530 if (v < 0 && solv->decisionmap[vv] < 0)
533 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
534 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
536 if (ri >= solv->jobrules && ri < solv->jobrules_end)
537 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
540 solver_disableproblem(solv, v);
542 solver_reenablepolicyrules(solv, -v);
544 break; /* start over */
546 if (ii == solv->ruleassertions.count)
547 break; /* finished! */
552 /********************************************************************/
556 /*-------------------------------------------------------------------
559 * initial setup for all watches
563 makewatches(Solver *solv)
567 int nsolvables = solv->pool->nsolvables;
569 solv_free(solv->watches);
570 /* lower half for removals, upper half for installs */
571 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
573 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
574 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
576 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
579 if (!r->w2) /* assertions do not need watches */
582 /* see addwatches_rule(solv, r) */
583 r->n1 = solv->watches[nsolvables + r->w1];
584 solv->watches[nsolvables + r->w1] = r - solv->rules;
586 r->n2 = solv->watches[nsolvables + r->w2];
587 solv->watches[nsolvables + r->w2] = r - solv->rules;
592 /*-------------------------------------------------------------------
594 * add watches (for a new learned rule)
595 * sets up watches for a single rule
597 * see also makewatches() above.
601 addwatches_rule(Solver *solv, Rule *r)
603 int nsolvables = solv->pool->nsolvables;
605 r->n1 = solv->watches[nsolvables + r->w1];
606 solv->watches[nsolvables + r->w1] = r - solv->rules;
608 r->n2 = solv->watches[nsolvables + r->w2];
609 solv->watches[nsolvables + r->w2] = r - solv->rules;
613 /********************************************************************/
619 /* shortcuts to check if a literal (positive or negative) assignment
620 * evaluates to 'true' or 'false'
622 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
623 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
624 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
626 /*-------------------------------------------------------------------
630 * make decision and propagate to all rules
632 * Evaluate each term affected by the decision (linked through watches).
633 * If we find unit rules we make new decisions based on them.
635 * return : 0 = everything is OK
636 * rule = conflict found in this rule
640 propagate(Solver *solv, int level)
642 Pool *pool = solv->pool;
643 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
645 Id p, pkg, other_watch;
647 Id *decisionmap = solv->decisionmap;
649 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
651 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
653 /* foreach non-propagated decision */
654 while (solv->propagate_index < solv->decisionq.count)
657 * 'pkg' was just decided
658 * negate because our watches trigger if literal goes FALSE
660 pkg = -solv->decisionq.elements[solv->propagate_index++];
662 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
664 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
665 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
668 /* foreach rule where 'pkg' is now FALSE */
669 for (rp = watches + pkg; *rp; rp = next_rp)
671 r = solv->rules + *rp;
674 /* rule is disabled, goto next */
682 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
684 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
685 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
688 /* 'pkg' was just decided (was set to FALSE)
690 * now find other literal watch, check clause
691 * and advance on linked list
705 * This term is already true (through the other literal)
706 * so we have nothing to do
708 if (DECISIONMAP_TRUE(other_watch))
712 * The other literal is FALSE or UNDEF
718 /* Not a binary clause, try to move our watch.
720 * Go over all literals and find one that is
724 * (TRUE is also ok, in that case the rule is fulfilled)
726 if (r->p /* we have a 'p' */
727 && r->p != other_watch /* which is not watched */
728 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
732 else /* go find a 'd' to make 'true' */
735 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
737 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
739 if (p != other_watch /* which is not watched */
740 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
748 * if we found some p that is UNDEF or TRUE, move
751 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
754 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
756 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
772 watches[p] = r - solv->rules;
775 /* search failed, thus all unwatched literals are FALSE */
780 * unit clause found, set literal other_watch to TRUE
783 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
784 return r; /* eek, a conflict! */
786 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
788 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
789 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
793 decisionmap[other_watch] = level; /* install! */
795 decisionmap[-other_watch] = -level; /* remove! */
797 queue_push(&solv->decisionq, other_watch);
798 queue_push(&solv->decisionq_why, r - solv->rules);
800 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
803 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
805 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
808 } /* foreach rule involving 'pkg' */
810 } /* while we have non-decided decisions */
812 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
814 return 0; /* all is well */
818 /********************************************************************/
821 /*-------------------------------------------------------------------
828 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
830 Pool *pool = solv->pool;
834 Map seen; /* global? */
835 Id d, v, vv, *dp, why;
837 int num = 0, l1num = 0;
838 int learnt_why = solv->learnt_pool.count;
839 Id *decisionmap = solv->decisionmap;
841 queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
843 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
844 map_init(&seen, pool->nsolvables);
845 idx = solv->decisionq.count;
848 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
849 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
850 queue_push(&solv->learnt_pool, c - solv->rules);
851 d = c->d < 0 ? -c->d - 1 : c->d;
852 dp = d ? pool->whatprovidesdata + d : 0;
853 /* go through all literals of the rule */
865 if (DECISIONMAP_TRUE(v)) /* the one true literal */
868 if (MAPTST(&seen, vv))
870 l = solv->decisionmap[vv];
873 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
875 l1num++; /* need to do this one in level1 pass */
877 num++; /* need to do this one as well */
880 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
886 if (!num && !--l1num)
887 break; /* all level 1 literals done */
889 /* find the next literal to investigate */
890 /* (as num + l1num > 0, we know that we'll always find one) */
894 v = solv->decisionq.elements[--idx];
896 if (MAPTST(&seen, vv))
901 if (num && --num == 0)
903 *pr = -v; /* so that v doesn't get lost */
906 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
907 /* clear non-l1 bits from seen map */
908 for (i = 0; i < r.count; i++)
911 MAPCLR(&seen, v > 0 ? v : -v);
913 /* only level 1 marks left in seen map */
914 l1num++; /* as l1retry decrements it */
918 why = solv->decisionq_why.elements[idx];
919 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
921 c = solv->rules + why;
927 else if (r.count == 1 && r.elements[0] < 0)
930 *dr = pool_queuetowhatprovides(pool, &r);
931 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
933 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
934 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
935 for (i = 0; i < r.count; i++)
936 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
938 /* push end marker on learnt reasons stack */
939 queue_push(&solv->learnt_pool, 0);
943 solv->stats_learned++;
948 /*-------------------------------------------------------------------
952 * reset all solver decisions
953 * called after rules have been enabled/disabled
957 solver_reset(Solver *solv)
959 Pool *pool = solv->pool;
963 /* rewind all decisions */
964 for (i = solv->decisionq.count - 1; i >= 0; i--)
966 v = solv->decisionq.elements[i];
967 solv->decisionmap[v > 0 ? v : -v] = 0;
969 queue_empty(&solv->decisionq_why);
970 queue_empty(&solv->decisionq);
971 solv->recommends_index = -1;
972 solv->propagate_index = 0;
973 queue_empty(&solv->branches);
975 /* adapt learnt rule status to new set of enabled/disabled rules */
976 enabledisablelearntrules(solv);
978 /* redo all assertion rule decisions */
979 makeruledecisions(solv);
980 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
984 /*-------------------------------------------------------------------
986 * analyze_unsolvable_rule
988 * recursion helper used by analyze_unsolvable
992 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
994 Pool *pool = solv->pool;
996 Id why = r - solv->rules;
998 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
999 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1000 if (solv->learntrules && why >= solv->learntrules)
1002 if (MAPTST(rseen, why - solv->learntrules))
1004 MAPSET(rseen, why - solv->learntrules);
1005 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1006 if (solv->learnt_pool.elements[i] > 0)
1007 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1010 if (MAPTST(&solv->weakrulemap, why))
1011 if (!*lastweakp || why > *lastweakp)
1013 /* do not add rpm rules to problem */
1014 if (why < solv->rpmrules_end)
1016 /* turn rule into problem */
1017 if (why >= solv->jobrules && why < solv->jobrules_end)
1018 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1019 /* normalize dup/infarch rules */
1020 if (why > solv->infarchrules && why < solv->infarchrules_end)
1022 Id name = pool->solvables[-solv->rules[why].p].name;
1023 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1026 if (why > solv->duprules && why < solv->duprules_end)
1028 Id name = pool->solvables[-solv->rules[why].p].name;
1029 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1033 /* return if problem already countains our rule */
1034 if (solv->problems.count)
1036 for (i = solv->problems.count - 1; i >= 0; i--)
1037 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1039 else if (solv->problems.elements[i] == why)
1042 queue_push(&solv->problems, why);
1046 /*-------------------------------------------------------------------
1048 * analyze_unsolvable
1050 * We know that the problem is not solvable. Record all involved
1051 * rules (i.e. the "proof") into solv->learnt_pool.
1052 * Record the learnt pool index and all non-rpm rules into
1053 * solv->problems. (Our solutions to fix the problems are to
1054 * disable those rules.)
1056 * If the proof contains at least one weak rule, we disable the
1059 * Otherwise we return 0 if disablerules is not set or disable
1060 * _all_ of the problem rules and return 1.
1062 * return: 1 - disabled some rules, try again
1067 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1069 Pool *pool = solv->pool;
1071 Map seen; /* global to speed things up? */
1073 Id d, v, vv, *dp, why;
1075 Id *decisionmap = solv->decisionmap;
1076 int oldproblemcount;
1077 int oldlearntpoolcount;
1079 int record_proof = 1;
1081 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1082 solv->stats_unsolvable++;
1083 oldproblemcount = solv->problems.count;
1084 oldlearntpoolcount = solv->learnt_pool.count;
1086 /* make room for proof index */
1087 /* must update it later, as analyze_unsolvable_rule would confuse
1088 * it with a rule index if we put the real value in already */
1089 queue_push(&solv->problems, 0);
1092 map_init(&seen, pool->nsolvables);
1093 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1095 queue_push(&solv->learnt_pool, r - solv->rules);
1097 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1098 d = r->d < 0 ? -r->d - 1 : r->d;
1099 dp = d ? pool->whatprovidesdata + d : 0;
1110 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1112 vv = v > 0 ? v : -v;
1113 l = solv->decisionmap[vv];
1118 idx = solv->decisionq.count;
1121 v = solv->decisionq.elements[--idx];
1122 vv = v > 0 ? v : -v;
1123 if (!MAPTST(&seen, vv))
1125 why = solv->decisionq_why.elements[idx];
1128 queue_push(&solv->learnt_pool, why);
1129 r = solv->rules + why;
1130 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1131 d = r->d < 0 ? -r->d - 1 : r->d;
1132 dp = d ? pool->whatprovidesdata + d : 0;
1143 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1145 vv = v > 0 ? v : -v;
1146 l = solv->decisionmap[vv];
1154 queue_push(&solv->problems, 0); /* mark end of this problem */
1158 /* disable last weak rule */
1159 solv->problems.count = oldproblemcount;
1160 solv->learnt_pool.count = oldlearntpoolcount;
1161 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1162 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1165 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1166 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1167 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1168 solver_disablechoicerules(solv, solv->rules + lastweak);
1169 solver_disableproblem(solv, v);
1171 solver_reenablepolicyrules(solv, -v);
1176 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
1178 solv->problems.count = oldproblemcount;
1179 solv->learnt_pool.count = oldlearntpoolcount;
1187 queue_push(&solv->learnt_pool, 0);
1188 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1191 /* + 2: index + trailing zero */
1192 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1194 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1195 solver_disableproblem(solv, solv->problems.elements[i]);
1196 /* XXX: might want to enable all weak rules again */
1200 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1205 /********************************************************************/
1206 /* Decision revert */
1208 /*-------------------------------------------------------------------
1211 * revert decisionq to a level
1215 revert(Solver *solv, int level)
1217 Pool *pool = solv->pool;
1219 while (solv->decisionq.count)
1221 v = solv->decisionq.elements[solv->decisionq.count - 1];
1222 vv = v > 0 ? v : -v;
1223 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1225 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1226 solv->decisionmap[vv] = 0;
1227 solv->decisionq.count--;
1228 solv->decisionq_why.count--;
1229 solv->propagate_index = solv->decisionq.count;
1231 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1233 solv->branches.count--;
1234 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1235 solv->branches.count--;
1237 solv->recommends_index = -1;
1241 /*-------------------------------------------------------------------
1243 * watch2onhighest - put watch2 on literal with highest level
1247 watch2onhighest(Solver *solv, Rule *r)
1252 d = r->d < 0 ? -r->d - 1 : r->d;
1254 return; /* binary rule, both watches are set */
1255 dp = solv->pool->whatprovidesdata + d;
1256 while ((v = *dp++) != 0)
1258 l = solv->decisionmap[v < 0 ? -v : v];
1270 /*-------------------------------------------------------------------
1274 * add free decision (solvable to install) to decisionq
1275 * increase level and propagate decision
1276 * return if no conflict.
1278 * in conflict case, analyze conflict rule, add resulting
1279 * rule to learnt rule set, make decision from learnt
1280 * rule (always unit) and re-propagate.
1282 * returns the new solver level or 0 if unsolvable
1287 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1289 Pool *pool = solv->pool;
1294 assert(ruleid >= 0);
1299 solv->decisionmap[decision] = level;
1301 solv->decisionmap[-decision] = -level;
1302 queue_push(&solv->decisionq, decision);
1303 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1307 r = propagate(solv, level);
1311 return analyze_unsolvable(solv, r, disablerules);
1312 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1313 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1314 assert(l > 0 && l < level);
1315 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1317 revert(solv, level);
1318 r = solver_addrule(solv, p, d);
1320 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1321 queue_push(&solv->learnt_why, why);
1324 /* at least 2 literals, needs watches */
1325 watch2onhighest(solv, r);
1326 addwatches_rule(solv, r);
1330 /* learnt rule is an assertion */
1331 queue_push(&solv->ruleassertions, r - solv->rules);
1333 /* the new rule is unit by design */
1334 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1335 queue_push(&solv->decisionq, p);
1336 queue_push(&solv->decisionq_why, r - solv->rules);
1337 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1339 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1340 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1341 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1342 solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
1349 /*-------------------------------------------------------------------
1351 * select and install
1353 * install best package from the queue. We add an extra package, inst, if
1354 * provided. See comment in weak install section.
1356 * returns the new solver level or 0 if unsolvable
1361 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1363 Pool *pool = solv->pool;
1368 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1371 /* XXX: didn't we already do that? */
1372 /* XXX: shouldn't we prefer installed packages? */
1373 /* XXX: move to policy.c? */
1374 /* choose the supplemented one */
1375 for (i = 0; i < dq->count; i++)
1376 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1378 dq->elements[0] = dq->elements[i];
1385 /* multiple candidates, open a branch */
1386 for (i = 1; i < dq->count; i++)
1387 queue_push(&solv->branches, dq->elements[i]);
1388 queue_push(&solv->branches, -level);
1390 p = dq->elements[0];
1392 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1394 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1398 /********************************************************************/
1399 /* Main solver interface */
1402 /*-------------------------------------------------------------------
1405 * create solver structure
1407 * pool: all available solvables
1408 * installed: installed Solvables
1411 * Upon solving, rules are created to flag the Solvables
1412 * of the 'installed' Repo as installed.
1416 solver_create(Pool *pool)
1419 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1421 solv->installed = pool->installed;
1423 solv->allownamechange = 1;
1425 solv->dup_allowdowngrade = 1;
1426 solv->dup_allownamechange = 1;
1427 solv->dup_allowarchchange = 1;
1428 solv->dup_allowvendorchange = 1;
1430 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1432 queue_init(&solv->ruletojob);
1433 queue_init(&solv->decisionq);
1434 queue_init(&solv->decisionq_why);
1435 queue_init(&solv->problems);
1436 queue_init(&solv->orphaned);
1437 queue_init(&solv->learnt_why);
1438 queue_init(&solv->learnt_pool);
1439 queue_init(&solv->branches);
1440 queue_init(&solv->weakruleq);
1441 queue_init(&solv->ruleassertions);
1442 queue_init(&solv->addedmap_deduceq);
1444 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1446 map_init(&solv->recommendsmap, pool->nsolvables);
1447 map_init(&solv->suggestsmap, pool->nsolvables);
1448 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1449 solv->recommends_index = 0;
1451 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1453 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1454 memset(solv->rules, 0, sizeof(Rule));
1460 /*-------------------------------------------------------------------
1466 solver_free(Solver *solv)
1468 queue_free(&solv->job);
1469 queue_free(&solv->ruletojob);
1470 queue_free(&solv->decisionq);
1471 queue_free(&solv->decisionq_why);
1472 queue_free(&solv->learnt_why);
1473 queue_free(&solv->learnt_pool);
1474 queue_free(&solv->problems);
1475 queue_free(&solv->solutions);
1476 queue_free(&solv->orphaned);
1477 queue_free(&solv->branches);
1478 queue_free(&solv->weakruleq);
1479 queue_free(&solv->ruleassertions);
1480 queue_free(&solv->addedmap_deduceq);
1481 if (solv->cleandeps_updatepkgs)
1483 queue_free(solv->cleandeps_updatepkgs);
1484 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
1486 if (solv->cleandeps_mistakes)
1488 queue_free(solv->cleandeps_mistakes);
1489 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
1491 if (solv->update_targets)
1493 queue_free(solv->update_targets);
1494 solv->update_targets = solv_free(solv->update_targets);
1496 if (solv->installsuppdepq)
1498 queue_free(solv->installsuppdepq);
1499 solv->installsuppdepq = solv_free(solv->installsuppdepq);
1502 map_free(&solv->recommendsmap);
1503 map_free(&solv->suggestsmap);
1504 map_free(&solv->noupdate);
1505 map_free(&solv->weakrulemap);
1506 map_free(&solv->multiversion);
1508 map_free(&solv->updatemap);
1509 map_free(&solv->bestupdatemap);
1510 map_free(&solv->fixmap);
1511 map_free(&solv->dupmap);
1512 map_free(&solv->dupinvolvedmap);
1513 map_free(&solv->droporphanedmap);
1514 map_free(&solv->cleandepsmap);
1516 solv_free(solv->decisionmap);
1517 solv_free(solv->rules);
1518 solv_free(solv->watches);
1519 solv_free(solv->obsoletes);
1520 solv_free(solv->obsoletes_data);
1521 solv_free(solv->multiversionupdaters);
1522 solv_free(solv->choicerules_ref);
1523 solv_free(solv->bestrules_pkg);
1528 solver_get_flag(Solver *solv, int flag)
1532 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1533 return solv->allowdowngrade;
1534 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1535 return solv->allownamechange;
1536 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1537 return solv->allowarchchange;
1538 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1539 return solv->allowvendorchange;
1540 case SOLVER_FLAG_ALLOW_UNINSTALL:
1541 return solv->allowuninstall;
1542 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1543 return solv->noupdateprovide;
1544 case SOLVER_FLAG_SPLITPROVIDES:
1545 return solv->dosplitprovides;
1546 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1547 return solv->dontinstallrecommended;
1548 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1549 return solv->addalreadyrecommended;
1550 case SOLVER_FLAG_NO_INFARCHCHECK:
1551 return solv->noinfarchcheck;
1552 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1553 return solv->keepexplicitobsoletes;
1554 case SOLVER_FLAG_BEST_OBEY_POLICY:
1555 return solv->bestobeypolicy;
1556 case SOLVER_FLAG_NO_AUTOTARGET:
1557 return solv->noautotarget;
1565 solver_set_flag(Solver *solv, int flag, int value)
1567 int old = solver_get_flag(solv, flag);
1570 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1571 solv->allowdowngrade = value;
1573 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1574 solv->allownamechange = value;
1576 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1577 solv->allowarchchange = value;
1579 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1580 solv->allowvendorchange = value;
1582 case SOLVER_FLAG_ALLOW_UNINSTALL:
1583 solv->allowuninstall = value;
1585 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1586 solv->noupdateprovide = value;
1588 case SOLVER_FLAG_SPLITPROVIDES:
1589 solv->dosplitprovides = value;
1591 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1592 solv->dontinstallrecommended = value;
1594 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1595 solv->addalreadyrecommended = value;
1597 case SOLVER_FLAG_NO_INFARCHCHECK:
1598 solv->noinfarchcheck = value;
1600 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1601 solv->keepexplicitobsoletes = value;
1603 case SOLVER_FLAG_BEST_OBEY_POLICY:
1604 solv->bestobeypolicy = value;
1606 case SOLVER_FLAG_NO_AUTOTARGET:
1607 solv->noautotarget = value;
1616 cleandeps_check_mistakes(Solver *solv, int level)
1618 Pool *pool = solv->pool;
1622 int mademistake = 0;
1624 if (!solv->cleandepsmap.size)
1626 /* check for mistakes */
1627 for (i = solv->installed->start; i < solv->installed->end; i++)
1629 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1631 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1632 /* a mistake is when the featurerule is true but the updaterule is false */
1635 FOR_RULELITERALS(p, pp, r)
1636 if (p > 0 && solv->decisionmap[p] > 0)
1639 continue; /* feature rule is not true */
1640 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1643 FOR_RULELITERALS(p, pp, r)
1644 if (p > 0 && solv->decisionmap[p] > 0)
1647 continue; /* update rule is true */
1648 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1649 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1650 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1651 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1652 if (!solv->cleandeps_mistakes)
1654 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1655 queue_init(solv->cleandeps_mistakes);
1657 queue_push(solv->cleandeps_mistakes, i);
1658 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1659 solver_reenablepolicyrules_cleandeps(solv, i);
1668 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1672 for (i = j = 0; i < q->count; i++)
1675 for (cp2 = cp; *cp2; cp2++)
1678 q->elements[j++] = p;
1682 queue_truncate(q, j);
1685 /*-------------------------------------------------------------------
1689 * all rules have been set up, now actually run the solver
1694 solver_run_sat(Solver *solv, int disablerules, int doweak)
1696 Queue dq; /* local decisionqueue */
1697 Queue dqs; /* local decisionqueue for supplements */
1703 Pool *pool = solv->pool;
1705 int minimizationsteps;
1706 int installedpos = solv->installed ? solv->installed->start : 0;
1708 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
1710 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
1711 for (i = 1; i < solv->nrules; i++)
1712 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
1715 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
1717 /* start SAT algorithm */
1719 systemlevel = level + 1;
1720 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
1726 * here's the main loop:
1727 * 1) propagate new decisions (only needed once)
1729 * 3) try to keep installed packages
1730 * 4) fulfill all unresolved rules
1731 * 5) install recommended packages
1732 * 6) minimalize solution if we had choices
1733 * if we encounter a problem, we rewind to a safe level and restart
1737 minimizationsteps = 0;
1741 * initial propagation of the assertions
1745 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
1746 if ((r = propagate(solv, level)) != 0)
1748 if (analyze_unsolvable(solv, r, disablerules))
1751 break; /* unsolvable */
1756 * resolve jobs first
1758 if (level < systemlevel)
1760 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1761 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1764 if (r->d < 0) /* ignore disabled rules */
1767 FOR_RULELITERALS(l, pp, r)
1771 if (solv->decisionmap[-l] <= 0)
1776 if (solv->decisionmap[l] > 0)
1778 if (solv->decisionmap[l] == 0)
1784 /* prune to installed if not updating */
1785 if (dq.count > 1 && solv->installed && !solv->updatemap_all &&
1786 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1789 for (j = k = 0; j < dq.count; j++)
1791 Solvable *s = pool->solvables + dq.elements[j];
1792 if (s->repo == solv->installed)
1794 dq.elements[k++] = dq.elements[j];
1795 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq.elements[j] - solv->installed->start))
1797 k = 0; /* package wants to be updated, do not prune */
1806 level = selectandinstall(solv, level, &dq, disablerules, i);
1809 if (level <= olevel)
1813 break; /* unsolvable */
1814 systemlevel = level + 1;
1815 if (i < solv->jobrules_end)
1817 solv->decisioncnt_update = solv->decisionq.count;
1818 solv->decisioncnt_keep = solv->decisionq.count;
1822 * installed packages
1824 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
1826 Repo *installed = solv->installed;
1829 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
1830 /* we use two passes if we need to update packages
1831 * to create a better user experience */
1832 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
1834 int passlevel = level;
1836 solv->decisioncnt_keep = solv->decisionq.count;
1837 /* start with installedpos, the position that gave us problems last time */
1838 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
1843 if (i == installed->end)
1844 i = installed->start;
1845 s = pool->solvables + i;
1846 if (s->repo != installed)
1849 if (solv->decisionmap[i] > 0)
1851 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
1852 continue; /* updates first */
1853 r = solv->rules + solv->updaterules + (i - installed->start);
1855 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
1856 rr -= solv->installed->end - solv->installed->start;
1857 if (!rr->p) /* identical to update rule? */
1860 continue; /* orpaned package */
1862 /* XXX: noupdate check is probably no longer needed, as all jobs should
1863 * already be satisfied */
1864 /* Actually we currently still need it because of erase jobs */
1865 /* if noupdate is set we do not look at update candidates */
1867 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 != i))
1869 if (solv->multiversion.size && solv->multiversionupdaters
1870 && (d = solv->multiversionupdaters[i - installed->start]) != 0)
1872 /* special multiversion handling, make sure best version is chosen */
1874 while ((p = pool->whatprovidesdata[d++]) != 0)
1875 if (solv->decisionmap[p] >= 0)
1877 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
1878 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
1881 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
1883 if (p != i && solv->decisionmap[p] == 0)
1885 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
1886 if (!rr->p) /* update rule == feature rule? */
1887 rr = rr - solv->featurerules + solv->updaterules;
1896 /* update to best package */
1897 FOR_RULELITERALS(p, pp, rr)
1899 if (solv->decisionmap[p] > 0)
1901 dq.count = 0; /* already fulfilled */
1904 if (!solv->decisionmap[p])
1909 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
1910 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
1911 /* install best version */
1915 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
1922 if (level <= olevel)
1924 if (level == 1 || level < passlevel)
1925 break; /* trouble */
1927 n = installed->start; /* redo all */
1933 /* if still undecided keep package */
1934 if (solv->decisionmap[i] == 0)
1937 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
1940 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
1941 level = setpropagatelearn(solv, level, -i, disablerules, 0);
1948 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
1949 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
1953 if (level <= olevel)
1955 if (level == 1 || level < passlevel)
1956 break; /* trouble */
1958 n = installed->start; /* redo all */
1961 continue; /* retry with learnt rule */
1965 if (n < installed->end)
1967 installedpos = i; /* retry problem solvable next time */
1968 break; /* ran into trouble */
1970 installedpos = installed->start; /* reset installedpos */
1973 break; /* unsolvable */
1974 systemlevel = level + 1;
1976 continue; /* had trouble, retry */
1979 if (level < systemlevel)
1980 systemlevel = level;
1985 solv->decisioncnt_resolve = solv->decisionq.count;
1986 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
1987 for (i = 1, n = 1; n < solv->nrules; i++, n++)
1989 if (i == solv->nrules)
1991 r = solv->rules + i;
1992 if (r->d < 0) /* ignore disabled rules */
1997 /* binary or unary rule */
1998 /* need two positive undecided literals */
1999 if (r->p < 0 || r->w2 <= 0)
2001 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2003 queue_push(&dq, r->p);
2004 queue_push(&dq, r->w2);
2009 * all negative literals are installed
2010 * no positive literal is installed
2011 * i.e. the rule is not fulfilled and we
2012 * just need to decide on the positive literals
2016 if (solv->decisionmap[-r->p] <= 0)
2021 if (solv->decisionmap[r->p] > 0)
2023 if (solv->decisionmap[r->p] == 0)
2024 queue_push(&dq, r->p);
2026 dp = pool->whatprovidesdata + r->d;
2027 while ((p = *dp++) != 0)
2031 if (solv->decisionmap[-p] <= 0)
2036 if (solv->decisionmap[p] > 0)
2038 if (solv->decisionmap[p] == 0)
2045 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2047 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2048 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2050 /* dq.count < 2 cannot happen as this means that
2051 * the rule is unit */
2052 assert(dq.count > 1);
2054 /* prune to cleandeps packages */
2055 if (solv->cleandepsmap.size && solv->installed)
2057 Repo *installed = solv->installed;
2058 for (j = 0; j < dq.count; j++)
2059 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2063 dq.elements[0] = dq.elements[j];
2064 queue_truncate(&dq, 1);
2069 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2071 break; /* unsolvable */
2072 if (level < systemlevel || level == 1)
2073 break; /* trouble */
2074 /* something changed, so look at all rules again */
2078 if (n != solv->nrules) /* ran into trouble? */
2081 break; /* unsolvable */
2082 continue; /* start over */
2085 /* at this point we have a consistent system. now do the extras... */
2087 /* first decide leftover cleandeps packages */
2088 if (solv->cleandepsmap.size && solv->installed)
2090 for (p = solv->installed->start; p < solv->installed->end; p++)
2092 s = pool->solvables + p;
2093 if (s->repo != solv->installed)
2095 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2097 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2099 level = setpropagatelearn(solv, level, -p, 0, 0);
2104 if (p < solv->installed->end)
2108 solv->decisioncnt_weak = solv->decisionq.count;
2113 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2114 queue_empty(&dq); /* recommended packages */
2115 queue_empty(&dqs); /* supplemented packages */
2116 for (i = 1; i < pool->nsolvables; i++)
2118 if (solv->decisionmap[i] < 0)
2120 if (solv->decisionmap[i] > 0)
2122 /* installed, check for recommends */
2123 Id *recp, rec, pp, p;
2124 s = pool->solvables + i;
2125 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2127 /* XXX need to special case AND ? */
2130 recp = s->repo->idarraydata + s->recommends;
2131 while ((rec = *recp++) != 0)
2134 FOR_PROVIDES(p, pp, rec)
2136 if (solv->decisionmap[p] > 0)
2141 else if (solv->decisionmap[p] == 0)
2143 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))))
2145 queue_pushunique(&dq, p);
2153 s = pool->solvables + i;
2154 if (!s->supplements)
2156 if (!pool_installable(pool, s))
2158 if (!solver_is_supplementing(solv, s))
2160 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2162 queue_push(&dqs, i);
2166 /* filter out all packages obsoleted by installed packages */
2167 /* this is no longer needed if we have reverse obsoletes */
2168 if ((dqs.count || dq.count) && solv->installed)
2171 Id obs, *obsp, po, ppo;
2173 map_init(&obsmap, pool->nsolvables);
2174 for (p = solv->installed->start; p < solv->installed->end; p++)
2176 s = pool->solvables + p;
2177 if (s->repo != solv->installed || !s->obsoletes)
2179 if (solv->decisionmap[p] <= 0)
2181 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
2183 obsp = s->repo->idarraydata + s->obsoletes;
2184 /* foreach obsoletes */
2185 while ((obs = *obsp++) != 0)
2186 FOR_PROVIDES(po, ppo, obs)
2187 MAPSET(&obsmap, po);
2189 for (i = j = 0; i < dqs.count; i++)
2190 if (!MAPTST(&obsmap, dqs.elements[i]))
2191 dqs.elements[j++] = dqs.elements[i];
2193 for (i = j = 0; i < dq.count; i++)
2194 if (!MAPTST(&obsmap, dq.elements[i]))
2195 dq.elements[j++] = dq.elements[i];
2200 /* filter out all already supplemented packages if requested */
2201 if (!solv->addalreadyrecommended && dqs.count)
2203 int dosplitprovides_old = solv->dosplitprovides;
2204 /* turn off all new packages */
2205 for (i = 0; i < solv->decisionq.count; i++)
2207 p = solv->decisionq.elements[i];
2210 s = pool->solvables + p;
2211 if (s->repo && s->repo != solv->installed)
2212 solv->decisionmap[p] = -solv->decisionmap[p];
2214 solv->dosplitprovides = 0;
2215 /* filter out old supplements */
2216 for (i = j = 0; i < dqs.count; i++)
2218 p = dqs.elements[i];
2219 s = pool->solvables + p;
2220 if (!s->supplements)
2222 if (!solver_is_supplementing(solv, s))
2223 dqs.elements[j++] = p;
2224 else if (solv->installsuppdepq && solver_check_installsuppdepq(solv, s))
2225 dqs.elements[j++] = p;
2228 /* undo turning off */
2229 for (i = 0; i < solv->decisionq.count; i++)
2231 p = solv->decisionq.elements[i];
2234 s = pool->solvables + p;
2235 if (s->repo && s->repo != solv->installed)
2236 solv->decisionmap[p] = -solv->decisionmap[p];
2238 solv->dosplitprovides = dosplitprovides_old;
2241 /* multiversion doesn't mix well with supplements.
2242 * filter supplemented packages where we already decided
2243 * to install a different version (see bnc#501088) */
2244 if (dqs.count && solv->multiversion.size)
2246 for (i = j = 0; i < dqs.count; i++)
2248 p = dqs.elements[i];
2249 if (MAPTST(&solv->multiversion, p))
2252 s = pool->solvables + p;
2253 FOR_PROVIDES(p2, pp2, s->name)
2254 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2257 continue; /* ignore this package */
2259 dqs.elements[j++] = p;
2264 /* make dq contain both recommended and supplemented pkgs */
2267 for (i = 0; i < dqs.count; i++)
2268 queue_pushunique(&dq, dqs.elements[i]);
2274 int decisioncount = solv->decisionq.count;
2278 /* simple case, just one package. no need to choose to best version */
2281 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2283 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2284 level = setpropagatelearn(solv, level, p, 0, 0);
2287 continue; /* back to main loop */
2290 /* filter packages, this gives us the best versions */
2291 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2293 /* create map of result */
2294 map_init(&dqmap, pool->nsolvables);
2295 for (i = 0; i < dq.count; i++)
2296 MAPSET(&dqmap, dq.elements[i]);
2298 /* install all supplemented packages */
2299 for (i = 0; i < dqs.count; i++)
2301 p = dqs.elements[i];
2302 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2304 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2306 level = setpropagatelearn(solv, level, p, 0, 0);
2307 if (level <= olevel)
2310 if (i < dqs.count || solv->decisionq.count < decisioncount)
2318 /* install all recommended packages */
2319 /* more work as we want to created branches if multiple
2320 * choices are valid */
2321 for (i = 0; i < decisioncount; i++)
2324 p = solv->decisionq.elements[i];
2327 s = pool->solvables + p;
2328 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2332 recp = s->repo->idarraydata + s->recommends;
2333 while ((rec = *recp++) != 0)
2336 FOR_PROVIDES(p, pp, rec)
2338 if (solv->decisionmap[p] > 0)
2343 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2344 queue_pushunique(&dq, p);
2350 /* multiple candidates, open a branch */
2351 for (i = 1; i < dq.count; i++)
2352 queue_push(&solv->branches, dq.elements[i]);
2353 queue_push(&solv->branches, -level);
2356 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2358 level = setpropagatelearn(solv, level, p, 0, 0);
2359 if (level <= olevel || solv->decisionq.count < decisioncount)
2360 break; /* we had to revert some decisions */
2363 break; /* had a problem above, quit loop */
2368 continue; /* back to main loop so that all deps are checked */
2372 solv->decisioncnt_orphan = solv->decisionq.count;
2373 if (solv->dupmap_all && solv->installed)
2375 int installedone = 0;
2377 /* let's see if we can install some unsupported package */
2378 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2379 for (i = 0; i < solv->orphaned.count; i++)
2381 p = solv->orphaned.elements[i];
2382 if (solv->decisionmap[p])
2383 continue; /* already decided */
2384 if (solv->droporphanedmap_all)
2386 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2388 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2390 level = setpropagatelearn(solv, level, p, 0, 0);
2395 if (installedone || i < solv->orphaned.count)
2399 continue; /* back to main loop */
2401 for (i = 0; i < solv->orphaned.count; i++)
2403 p = solv->orphaned.elements[i];
2404 if (solv->decisionmap[p])
2405 continue; /* already decided */
2406 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2408 level = setpropagatelearn(solv, level, -p, 0, 0);
2412 if (i < solv->orphaned.count)
2416 continue; /* back to main loop */
2420 if (solv->installed && solv->cleandepsmap.size)
2422 if (cleandeps_check_mistakes(solv, level))
2424 level = 1; /* restart from scratch */
2425 systemlevel = level + 1;
2430 if (solv->solution_callback)
2432 solv->solution_callback(solv, solv->solution_callback_data);
2433 if (solv->branches.count)
2435 int i = solv->branches.count - 1;
2436 int l = -solv->branches.elements[i];
2440 if (solv->branches.elements[i - 1] < 0)
2442 p = solv->branches.elements[i];
2443 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2445 for (j = i + 1; j < solv->branches.count; j++)
2446 queue_push(&dq, solv->branches.elements[j]);
2447 solv->branches.count = i;
2449 revert(solv, level);
2451 for (j = 0; j < dq.count; j++)
2452 queue_push(&solv->branches, dq.elements[j]);
2454 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2456 level = setpropagatelearn(solv, level, p, disablerules, why);
2461 /* all branches done, we're finally finished */
2465 /* auto-minimization step */
2466 if (solv->branches.count)
2468 int l = 0, lasti = -1, lastl = -1;
2472 for (i = solv->branches.count - 1; i >= 0; i--)
2474 p = solv->branches.elements[i];
2477 else if (p > 0 && solv->decisionmap[p] > l + 1)
2485 /* kill old solvable so that we do not loop */
2486 p = solv->branches.elements[lasti];
2487 solv->branches.elements[lasti] = 0;
2488 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2489 minimizationsteps++;
2492 revert(solv, level);
2493 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2496 level = setpropagatelearn(solv, level, p, disablerules, why);
2499 continue; /* back to main loop */
2502 /* no minimization found, we're finally finished! */
2506 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2508 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2514 solv->decisioncnt_update = solv->decisionq.count;
2515 solv->decisioncnt_keep = solv->decisionq.count;
2516 solv->decisioncnt_resolve = solv->decisionq.count;
2517 solv->decisioncnt_weak = solv->decisionq.count;
2518 solv->decisioncnt_orphan = solv->decisionq.count;
2521 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2526 /*-------------------------------------------------------------------
2528 * remove disabled conflicts
2530 * purpose: update the decisionmap after some rules were disabled.
2531 * this is used to calculate the suggested/recommended package list.
2532 * Also returns a "removed" list to undo the discisionmap changes.
2536 removedisabledconflicts(Solver *solv, Queue *removed)
2538 Pool *pool = solv->pool;
2543 Id *decisionmap = solv->decisionmap;
2545 queue_empty(removed);
2546 for (i = 0; i < solv->decisionq.count; i++)
2548 p = solv->decisionq.elements[i];
2550 continue; /* conflicts only, please */
2551 why = solv->decisionq_why.elements[i];
2554 /* no rule involved, must be a orphan package drop */
2557 /* we never do conflicts on free decisions, so there
2558 * must have been an unit rule */
2560 r = solv->rules + why;
2561 if (r->d < 0 && decisionmap[-p])
2563 /* rule is now disabled, remove from decisionmap */
2564 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2565 queue_push(removed, -p);
2566 queue_push(removed, decisionmap[-p]);
2567 decisionmap[-p] = 0;
2570 if (!removed->count)
2572 /* we removed some confliced packages. some of them might still
2573 * be in conflict, so search for unit rules and re-conflict */
2575 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2577 if (i == solv->nrules)
2580 r = solv->rules + i;
2586 if (r->p < 0 && !decisionmap[-r->p])
2592 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2594 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2599 if (r->p < 0 && decisionmap[-r->p] == 0)
2601 if (new || DECISIONMAP_FALSE(r->p))
2603 dp = pool->whatprovidesdata + r->d;
2604 while ((p = *dp++) != 0)
2606 if (new && p == new)
2608 if (p < 0 && decisionmap[-p] == 0)
2617 else if (!DECISIONMAP_FALSE(p))
2627 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2628 decisionmap[-new] = -1;
2630 n = 0; /* redo all rules */
2636 undo_removedisabledconflicts(Solver *solv, Queue *removed)
2639 for (i = 0; i < removed->count; i += 2)
2640 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
2644 /*-------------------------------------------------------------------
2646 * weaken solvable dependencies
2650 weaken_solvable_deps(Solver *solv, Id p)
2655 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
2659 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2660 continue; /* conflict */
2661 queue_push(&solv->weakruleq, i);
2666 /********************************************************************/
2671 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
2674 Id how, what, select;
2676 for (i = 0; i < job->count; i += 2)
2678 how = job->elements[i];
2679 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
2681 what = job->elements[i + 1];
2682 select = how & SOLVER_SELECTMASK;
2683 if (!multiversionmap->size)
2684 map_grow(multiversionmap, pool->nsolvables);
2685 if (select == SOLVER_SOLVABLE_ALL)
2687 FOR_POOL_SOLVABLES(p)
2688 MAPSET(multiversionmap, p);
2690 else if (select == SOLVER_SOLVABLE_REPO)
2693 Repo *repo = pool_id2repo(pool, what);
2695 FOR_REPO_SOLVABLES(repo, p, s)
2696 MAPSET(multiversionmap, p);
2698 FOR_JOB_SELECT(p, pp, select, what)
2699 MAPSET(multiversionmap, p);
2704 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
2706 solver_calculate_multiversionmap(pool, job, multiversionmap);
2710 * add a rule created by a job, record job number and weak flag
2713 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
2715 solver_addrule(solv, p, d);
2716 queue_push(&solv->ruletojob, job);
2718 queue_push(&solv->weakruleq, solv->nrules - 1);
2722 add_cleandeps_package(Solver *solv, Id p)
2724 if (!solv->cleandeps_updatepkgs)
2726 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
2727 queue_init(solv->cleandeps_updatepkgs);
2729 queue_pushunique(solv->cleandeps_updatepkgs, p);
2733 add_update_target(Solver *solv, Id p, Id how)
2735 Pool *pool = solv->pool;
2736 Solvable *s = pool->solvables + p;
2737 Repo *installed = solv->installed;
2739 if (!solv->update_targets)
2741 solv->update_targets = solv_calloc(1, sizeof(Queue));
2742 queue_init(solv->update_targets);
2744 if (s->repo == installed)
2746 queue_push2(solv->update_targets, p, p);
2749 FOR_PROVIDES(pi, pip, s->name)
2751 Solvable *si = pool->solvables + pi;
2752 if (si->repo != installed || si->name != s->name)
2754 if (how & SOLVER_FORCEBEST)
2756 if (!solv->bestupdatemap.size)
2757 map_grow(&solv->bestupdatemap, installed->end - installed->start);
2758 MAPSET(&solv->bestupdatemap, pi - installed->start);
2760 if (how & SOLVER_CLEANDEPS)
2761 add_cleandeps_package(solv, pi);
2762 queue_push2(solv->update_targets, pi, p);
2763 /* check if it's ok to keep the installed package */
2764 if (s->evr == si->evr && solvable_identical(s, si))
2765 queue_push2(solv->update_targets, pi, pi);
2769 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2770 while ((obs = *obsp++) != 0)
2772 FOR_PROVIDES(pi, pip, obs)
2774 Solvable *si = pool->solvables + pi;
2775 if (si->repo != installed)
2777 if (si->name == s->name)
2778 continue; /* already handled above */
2779 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
2781 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
2783 if (how & SOLVER_FORCEBEST)
2785 if (!solv->bestupdatemap.size)
2786 map_grow(&solv->bestupdatemap, installed->end - installed->start);
2787 MAPSET(&solv->bestupdatemap, pi - installed->start);
2789 if (how & SOLVER_CLEANDEPS)
2790 add_cleandeps_package(solv, pi);
2791 queue_push2(solv->update_targets, pi, p);
2798 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
2808 transform_update_targets(Solver *solv)
2810 Repo *installed = solv->installed;
2811 Queue *update_targets = solv->update_targets;
2813 Id p, q, lastp, lastq;
2815 if (!update_targets->count)
2817 queue_free(update_targets);
2818 solv->update_targets = solv_free(update_targets);
2821 if (update_targets->count > 2)
2822 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
2823 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
2825 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
2827 if ((p = update_targets->elements[i]) != lastp)
2829 if (!solv->updatemap.size)
2830 map_grow(&solv->updatemap, installed->end - installed->start);
2831 MAPSET(&solv->updatemap, p - installed->start);
2832 update_targets->elements[j++] = 0; /* finish old set */
2833 update_targets->elements[p - installed->start] = j; /* start new set */
2837 if ((q = update_targets->elements[i + 1]) != lastq)
2839 update_targets->elements[j++] = q;
2843 queue_truncate(update_targets, j);
2844 queue_push(update_targets, 0); /* finish last set */
2849 addedmap2deduceq(Solver *solv, Map *addedmap)
2851 Pool *pool = solv->pool;
2856 queue_empty(&solv->addedmap_deduceq);
2857 for (i = 2, j = solv->rpmrules_end - 1; i < pool->nsolvables && j > 0; j--)
2859 r = solv->rules + j;
2862 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2865 if (!MAPTST(addedmap, p))
2867 /* should never happen, but... */
2868 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
2869 queue_push(&solv->addedmap_deduceq, -p);
2873 if (MAPTST(addedmap, i))
2874 queue_push(&solv->addedmap_deduceq, i);
2878 for (; i < pool->nsolvables; i++)
2879 if (MAPTST(addedmap, i))
2880 queue_push(&solv->addedmap_deduceq, i);
2882 for (i = 2; i < pool->nsolvables; i++)
2883 if (MAPTST(addedmap, i))
2888 deduceq2addedmap(Solver *solv, Map *addedmap)
2893 for (j = solv->rpmrules_end - 1; j > 0; j--)
2895 r = solv->rules + j;
2896 if (r->d < 0 && r->p)
2897 solver_enablerule(solv, r);
2900 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2903 MAPSET(addedmap, p);
2905 for (j = 0; j < solv->addedmap_deduceq.count; j++)
2907 p = solv->addedmap_deduceq.elements[j];
2909 MAPSET(addedmap, p);
2911 MAPCLR(addedmap, p);
2923 solver_solve(Solver *solv, Queue *job)
2925 Pool *pool = solv->pool;
2926 Repo *installed = solv->installed;
2928 int oldnrules, initialnrules;
2929 Map addedmap; /* '1' == have rpm-rules for solvable */
2930 Map installcandidatemap;
2931 Id how, what, select, name, weak, p, pp, d;
2935 int now, solve_start;
2937 int hasbestinstalljob = 0;
2939 solve_start = solv_timems(0);
2941 /* log solver options */
2942 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
2943 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
2944 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);
2945 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
2946 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors);
2947 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
2949 /* create whatprovides if not already there */
2950 if (!pool->whatprovides)
2951 pool_createwhatprovides(pool);
2953 /* create obsolete index */
2954 policy_create_obsolete_index(solv);
2957 queue_free(&solv->job);
2958 queue_init_clone(&solv->job, job);
2959 solv->pooljobcnt = pool->pooljobs.count;
2960 if (pool->pooljobs.count)
2961 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
2964 /* free old stuff */
2965 if (solv->update_targets)
2967 queue_free(solv->update_targets);
2968 solv->update_targets = solv_free(solv->update_targets);
2970 if (solv->cleandeps_updatepkgs)
2972 queue_free(solv->cleandeps_updatepkgs);
2973 solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
2975 queue_empty(&solv->ruleassertions);
2976 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
2977 solv->choicerules_ref = solv_free(solv->choicerules_ref);
2978 if (solv->noupdate.size)
2979 map_empty(&solv->noupdate);
2980 if (solv->multiversion.size)
2982 map_free(&solv->multiversion);
2983 map_init(&solv->multiversion, 0);
2985 solv->updatemap_all = 0;
2986 if (solv->updatemap.size)
2988 map_free(&solv->updatemap);
2989 map_init(&solv->updatemap, 0);
2991 solv->bestupdatemap_all = 0;
2992 if (solv->bestupdatemap.size)
2994 map_free(&solv->bestupdatemap);
2995 map_init(&solv->bestupdatemap, 0);
2997 solv->fixmap_all = 0;
2998 if (solv->fixmap.size)
3000 map_free(&solv->fixmap);
3001 map_init(&solv->fixmap, 0);
3003 solv->dupmap_all = 0;
3004 if (solv->dupmap.size)
3006 map_free(&solv->dupmap);
3007 map_init(&solv->dupmap, 0);
3009 if (solv->dupinvolvedmap.size)
3011 map_free(&solv->dupinvolvedmap);
3012 map_init(&solv->dupinvolvedmap, 0);
3014 solv->droporphanedmap_all = 0;
3015 if (solv->droporphanedmap.size)
3017 map_free(&solv->droporphanedmap);
3018 map_init(&solv->droporphanedmap, 0);
3020 if (solv->cleandepsmap.size)
3022 map_free(&solv->cleandepsmap);
3023 map_init(&solv->cleandepsmap, 0);
3026 queue_empty(&solv->weakruleq);
3027 solv->watches = solv_free(solv->watches);
3028 queue_empty(&solv->ruletojob);
3029 if (solv->decisionq.count)
3030 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3031 queue_empty(&solv->decisionq);
3032 queue_empty(&solv->decisionq_why);
3033 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3034 queue_empty(&solv->learnt_why);
3035 queue_empty(&solv->learnt_pool);
3036 queue_empty(&solv->branches);
3037 solv->propagate_index = 0;
3038 queue_empty(&solv->problems);
3039 queue_empty(&solv->solutions);
3040 queue_empty(&solv->orphaned);
3041 solv->stats_learned = solv->stats_unsolvable = 0;
3042 if (solv->recommends_index)
3044 map_empty(&solv->recommendsmap);
3045 map_empty(&solv->suggestsmap);
3046 solv->recommends_index = 0;
3048 solv->multiversionupdaters = solv_free(solv->multiversionupdaters);
3052 * create basic rule set of all involved packages
3053 * use addedmap bitmap to make sure we don't create rules twice
3056 /* create multiversion map if needed */
3057 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3059 map_init(&addedmap, pool->nsolvables);
3060 MAPSET(&addedmap, SYSTEMSOLVABLE);
3062 map_init(&installcandidatemap, pool->nsolvables);
3065 now = solv_timems(0);
3067 * create rules for all package that could be involved with the solving
3068 * so called: rpm rules
3071 initialnrules = solv->rpmrules_end ? solv->rpmrules_end : 1;
3072 if (initialnrules > 1)
3073 deduceq2addedmap(solv, &addedmap);
3074 if (solv->nrules != initialnrules)
3075 solver_shrinkrules(solv, initialnrules);
3076 solv->nrules = initialnrules;
3077 solv->rpmrules_end = 0;
3081 /* check for update/verify jobs as they need to be known early */
3082 for (i = 0; i < job->count; i += 2)
3084 how = job->elements[i];
3085 what = job->elements[i + 1];
3086 select = how & SOLVER_SELECTMASK;
3087 switch (how & SOLVER_JOBMASK)
3090 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3091 solv->fixmap_all = 1;
3092 FOR_JOB_SELECT(p, pp, select, what)
3094 s = pool->solvables + p;
3095 if (s->repo != installed)
3097 if (!solv->fixmap.size)
3098 map_grow(&solv->fixmap, installed->end - installed->start);
3099 MAPSET(&solv->fixmap, p - installed->start);
3103 if (select == SOLVER_SOLVABLE_ALL)
3105 solv->updatemap_all = 1;
3106 if (how & SOLVER_FORCEBEST)
3107 solv->bestupdatemap_all = 1;
3108 if (how & SOLVER_CLEANDEPS)
3110 FOR_REPO_SOLVABLES(installed, p, s)
3111 add_cleandeps_package(solv, p);
3114 else if (select == SOLVER_SOLVABLE_REPO)
3116 Repo *repo = pool_id2repo(pool, what);
3119 if (repo == installed && !(how & SOLVER_TARGETED))
3121 solv->updatemap_all = 1;
3122 if (how & SOLVER_FORCEBEST)
3123 solv->bestupdatemap_all = 1;
3124 if (how & SOLVER_CLEANDEPS)
3126 FOR_REPO_SOLVABLES(installed, p, s)
3127 add_cleandeps_package(solv, p);
3131 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3133 /* targeted update */
3134 FOR_REPO_SOLVABLES(repo, p, s)
3135 add_update_target(solv, p, how);
3139 if (!(how & SOLVER_TARGETED))
3142 FOR_JOB_SELECT(p, pp, select, what)
3144 s = pool->solvables + p;
3145 if (s->repo != installed)
3147 if (!solv->updatemap.size)
3148 map_grow(&solv->updatemap, installed->end - installed->start);
3149 MAPSET(&solv->updatemap, p - installed->start);
3150 if (how & SOLVER_FORCEBEST)
3152 if (!solv->bestupdatemap.size)
3153 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3154 MAPSET(&solv->bestupdatemap, p - installed->start);
3156 if (how & SOLVER_CLEANDEPS)
3157 add_cleandeps_package(solv, p);
3160 if (!targeted || solv->noautotarget)
3163 FOR_JOB_SELECT(p, pp, select, what)
3164 add_update_target(solv, p, how);
3172 if (solv->update_targets)
3173 transform_update_targets(solv);
3175 oldnrules = solv->nrules;
3176 FOR_REPO_SOLVABLES(installed, p, s)
3177 solver_addrpmrulesforsolvable(solv, s, &addedmap);
3178 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3179 oldnrules = solv->nrules;
3180 FOR_REPO_SOLVABLES(installed, p, s)
3181 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
3182 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3186 * create rules for all packages involved in the job
3187 * (to be installed or removed)
3190 oldnrules = solv->nrules;
3191 for (i = 0; i < job->count; i += 2)
3193 how = job->elements[i];
3194 what = job->elements[i + 1];
3195 select = how & SOLVER_SELECTMASK;
3197 switch (how & SOLVER_JOBMASK)
3199 case SOLVER_INSTALL:
3200 FOR_JOB_SELECT(p, pp, select, what)
3202 MAPSET(&installcandidatemap, p);
3203 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3206 case SOLVER_DISTUPGRADE:
3207 if (select == SOLVER_SOLVABLE_ALL)
3209 solv->dupmap_all = 1;
3210 solv->updatemap_all = 1;
3211 if (how & SOLVER_FORCEBEST)
3212 solv->bestupdatemap_all = 1;
3214 if (!solv->dupmap_all)
3221 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3225 * add rules for suggests, enhances
3227 oldnrules = solv->nrules;
3228 solver_addrpmrulesforweak(solv, &addedmap);
3229 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3232 * first pass done, we now have all the rpm rules we need.
3233 * unify existing rules before going over all job rules and
3235 * at this point the system is always solvable,
3236 * as an empty system (remove all packages) is a valid solution
3239 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3241 int possible = 0, installable = 0;
3242 for (i = 1; i < pool->nsolvables; i++)
3244 if (pool_installable(pool, pool->solvables + i))
3246 if (MAPTST(&addedmap, i))
3249 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3252 if (solv->nrules > initialnrules)
3253 solver_unifyrules(solv); /* remove duplicate rpm rules */
3254 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
3256 if (solv->nrules > initialnrules)
3257 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3259 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3260 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
3262 /* create dup maps if needed. We need the maps early to create our
3265 solver_createdupmaps(solv);
3268 * create feature rules
3270 * foreach installed:
3271 * create assertion (keep installed, if no update available)
3273 * create update rule (A|update1(A)|update2(A)|...)
3275 * those are used later on to keep a version of the installed packages in
3279 solv->featurerules = solv->nrules; /* mark start of feature rules */
3282 /* foreach possibly installed solvable */
3283 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3285 if (s->repo != installed)
3287 solver_addrule(solv, 0, 0); /* create dummy rule */
3290 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3292 /* make sure we accounted for all rules */
3293 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3295 solv->featurerules_end = solv->nrules;
3298 * Add update rules for installed solvables
3300 * almost identical to feature rules
3301 * except that downgrades/archchanges/vendorchanges are not allowed
3304 solv->updaterules = solv->nrules;
3307 { /* foreach installed solvables */
3308 /* we create all update rules, but disable some later on depending on the job */
3309 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3313 if (s->repo != installed)
3315 solver_addrule(solv, 0, 0); /* create dummy rule */
3318 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3320 * check for and remove duplicate
3322 r = solv->rules + solv->nrules - 1; /* r: update rule */
3323 sr = r - (installed->end - installed->start); /* sr: feature rule */
3324 /* it's orphaned if there is no feature rule or the feature rule
3325 * consists just of the installed package */
3326 if (!sr->p || (sr->p == i && !sr->d && !sr->w2))
3327 queue_push(&solv->orphaned, i);
3330 assert(solv->dupmap_all && !sr->p);
3333 if (!solver_rulecmp(solv, r, sr))
3334 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3336 solver_disablerule(solv, sr); /* disable feature rule */
3338 /* consistency check: we added a rule for _every_ installed solvable */
3339 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3341 solv->updaterules_end = solv->nrules;
3345 * now add all job rules
3348 solv->jobrules = solv->nrules;
3349 for (i = 0; i < job->count; i += 2)
3351 oldnrules = solv->nrules;
3353 if (i && i == solv->pooljobcnt)
3354 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3355 how = job->elements[i];
3356 what = job->elements[i + 1];
3357 weak = how & SOLVER_WEAK;
3358 select = how & SOLVER_SELECTMASK;
3359 switch (how & SOLVER_JOBMASK)
3361 case SOLVER_INSTALL:
3362 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3363 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3364 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3365 if (select == SOLVER_SOLVABLE)
3373 FOR_JOB_SELECT(p, pp, select, what)
3377 /* no candidate found, make this an impossible rule */
3378 queue_push(&q, -SYSTEMSOLVABLE);
3380 p = queue_shift(&q); /* get first candidate */
3381 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3383 /* force install of namespace supplements hack */
3384 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3386 Reldep *rd = GETRELDEP(pool, what);
3387 if (rd->flags == REL_NAMESPACE)
3390 if (!solv->installsuppdepq)
3392 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3393 queue_init(solv->installsuppdepq);
3395 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3398 solver_addjobrule(solv, p, d, i, weak);
3399 if (how & SOLVER_FORCEBEST)
3400 hasbestinstalljob = 1;
3403 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3404 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3405 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3406 /* specific solvable: by id or by nevra */
3407 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3408 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3410 FOR_POOL_SOLVABLES(p)
3411 solver_addjobrule(solv, -p, 0, i, weak);
3413 else if (select == SOLVER_SOLVABLE_REPO)
3415 Repo *repo = pool_id2repo(pool, what);
3417 FOR_REPO_SOLVABLES(repo, p, s)
3418 solver_addjobrule(solv, -p, 0, i, weak);
3420 FOR_JOB_SELECT(p, pp, select, what)
3422 s = pool->solvables + p;
3423 if (installed && s->repo == installed)
3424 name = !name ? s->name : -1;
3425 solver_addjobrule(solv, -p, 0, i, weak);
3427 /* special case for "erase a specific solvable": we also
3428 * erase all other solvables with that name, so that they
3429 * don't get picked up as replacement.
3430 * name is > 0 if exactly one installed solvable matched.
3432 /* XXX: look also at packages that obsolete this package? */
3437 FOR_PROVIDES(p, pp, name)
3439 s = pool->solvables + p;
3440 if (s->name != name)
3442 /* keep other versions installed */
3443 if (s->repo == installed)
3445 /* keep installcandidates of other jobs */
3446 if (MAPTST(&installcandidatemap, p))
3448 /* don't add the same rule twice */
3449 for (j = oldnrules; j < k; j++)
3450 if (solv->rules[j].p == -p)
3453 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
3459 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3462 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3464 case SOLVER_WEAKENDEPS:
3465 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3466 if (select != SOLVER_SOLVABLE)
3468 s = pool->solvables + what;
3469 weaken_solvable_deps(solv, what);
3471 case SOLVER_MULTIVERSION:
3472 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3475 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3476 if (select == SOLVER_SOLVABLE_ALL)
3478 FOR_POOL_SOLVABLES(p)
3479 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3481 else if (select == SOLVER_SOLVABLE_REPO)
3483 Repo *repo = pool_id2repo(pool, what);
3485 FOR_REPO_SOLVABLES(repo, p, s)
3486 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3488 FOR_JOB_SELECT(p, pp, select, what)
3489 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3491 case SOLVER_DISTUPGRADE:
3492 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3494 case SOLVER_DROP_ORPHANED:
3495 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3496 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3497 solv->droporphanedmap_all = 1;
3498 FOR_JOB_SELECT(p, pp, select, what)
3500 s = pool->solvables + p;
3501 if (!installed || s->repo != installed)
3503 if (!solv->droporphanedmap.size)
3504 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3505 MAPSET(&solv->droporphanedmap, p - installed->start);
3508 case SOLVER_USERINSTALLED:
3509 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3512 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3520 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3523 if (solv->nrules == oldnrules)
3524 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3525 for (j = oldnrules; j < solv->nrules; j++)
3527 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3528 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3532 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3533 solv->jobrules_end = solv->nrules;
3535 /* now create infarch and dup rules */
3536 if (!solv->noinfarchcheck)
3538 solver_addinfarchrules(solv, &addedmap);
3539 if (pool->obsoleteusescolors)
3541 /* currently doesn't work well with infarch rules, so make
3543 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3544 queue_push(&solv->weakruleq, i);
3548 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3551 solver_addduprules(solv, &addedmap);
3553 solv->duprules = solv->duprules_end = solv->nrules;
3555 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3556 solver_addbestrules(solv, hasbestinstalljob);
3558 solv->bestrules = solv->bestrules_end = solv->nrules;
3561 solver_freedupmaps(solv); /* no longer needed */
3564 solver_addchoicerules(solv);
3566 solv->choicerules = solv->choicerules_end = solv->nrules;
3570 for (i = solv->featurerules; i < solv->nrules; i++)
3571 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3573 /* all rules created
3574 * --------------------------------------------------------------
3575 * prepare for solving
3578 /* free unneeded memory */
3579 map_free(&addedmap);
3580 map_free(&installcandidatemap);
3583 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);
3584 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3586 /* create weak map */
3587 map_init(&solv->weakrulemap, solv->nrules);
3588 for (i = 0; i < solv->weakruleq.count; i++)
3590 p = solv->weakruleq.elements[i];
3591 MAPSET(&solv->weakrulemap, p);
3594 /* enable cleandepsmap creation if we have updatepkgs */
3595 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
3596 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3598 if (solv->cleandeps_mistakes)
3600 queue_free(solv->cleandeps_mistakes);
3601 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3604 /* all new rules are learnt after this point */
3605 solv->learntrules = solv->nrules;
3607 /* create watches chains */
3610 /* create assertion index. it is only used to speed up
3611 * makeruledecsions() a bit */
3612 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3613 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3614 queue_push(&solv->ruleassertions, i);
3616 /* disable update rules that conflict with our job */
3617 solver_disablepolicyrules(solv);
3619 /* make initial decisions based on assertion rules */
3620 makeruledecisions(solv);
3621 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3624 * ********************************************
3626 * ********************************************
3629 now = solv_timems(0);
3630 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3631 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3634 * prepare solution queue if there were problems
3636 solver_prepare_solutions(solv);
3638 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);
3639 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3641 /* return number of problems */
3642 return solv->problems.count ? solv->problems.count / 2 : 0;
3646 solver_create_transaction(Solver *solv)
3648 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
3651 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3653 queue_free(orphanedq);
3654 queue_init_clone(orphanedq, &solv->orphaned);
3657 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
3659 Pool *pool = solv->pool;
3660 Queue redoq, disabledq;
3666 if (!recommendationsq && !suggestionsq)
3669 map_init(&obsmap, pool->nsolvables);
3670 if (solv->installed)
3672 Id obs, *obsp, p, po, ppo;
3673 for (p = solv->installed->start; p < solv->installed->end; p++)
3675 s = pool->solvables + p;
3676 if (s->repo != solv->installed || !s->obsoletes)
3678 if (solv->decisionmap[p] <= 0)
3680 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
3682 obsp = s->repo->idarraydata + s->obsoletes;
3683 /* foreach obsoletes */
3684 while ((obs = *obsp++) != 0)
3685 FOR_PROVIDES(po, ppo, obs)
3686 MAPSET(&obsmap, po);
3691 queue_init(&disabledq);
3693 /* disable all erase jobs (including weak "keep uninstalled" rules) */
3694 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
3696 if (r->d < 0) /* disabled ? */
3698 if (r->p >= 0) /* install job? */
3700 queue_push(&disabledq, i);
3701 solver_disablerule(solv, r);
3707 enabledisablelearntrules(solv);
3708 removedisabledconflicts(solv, &redoq);
3712 * find recommended packages
3714 if (recommendationsq)
3716 Id rec, *recp, p, pp;
3718 queue_empty(recommendationsq);
3719 /* create map of all recommened packages */
3720 solv->recommends_index = -1;
3721 MAPZERO(&solv->recommendsmap);
3723 /* put all packages the solver already chose in the map */
3724 if (solv->decisioncnt_weak)
3726 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
3729 why = solv->decisionq_why.elements[i];
3731 continue; /* forced by unit rule */
3732 p = solv->decisionq.elements[i];
3735 MAPSET(&solv->recommendsmap, p);
3739 for (i = 0; i < solv->decisionq.count; i++)
3741 p = solv->decisionq.elements[i];
3744 s = pool->solvables + p;
3747 recp = s->repo->idarraydata + s->recommends;
3748 while ((rec = *recp++) != 0)
3750 FOR_PROVIDES(p, pp, rec)
3751 if (solv->decisionmap[p] > 0)
3757 FOR_PROVIDES(p, pp, rec)
3758 if (solv->decisionmap[p] > 0)
3759 MAPSET(&solv->recommendsmap, p);
3761 continue; /* p != 0: already fulfilled */
3763 FOR_PROVIDES(p, pp, rec)
3764 MAPSET(&solv->recommendsmap, p);
3768 for (i = 1; i < pool->nsolvables; i++)
3770 if (solv->decisionmap[i] < 0)
3772 if (solv->decisionmap[i] > 0 && noselected)
3774 if (MAPTST(&obsmap, i))
3776 s = pool->solvables + i;
3777 if (!MAPTST(&solv->recommendsmap, i))
3779 if (!s->supplements)
3781 if (!pool_installable(pool, s))
3783 if (!solver_is_supplementing(solv, s))
3786 queue_push(recommendationsq, i);
3788 /* we use MODE_SUGGEST here so that repo prio is ignored */
3789 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
3793 * find suggested packages
3798 Id sug, *sugp, p, pp;
3800 queue_empty(suggestionsq);
3801 /* create map of all suggests that are still open */
3802 solv->recommends_index = -1;
3803 MAPZERO(&solv->suggestsmap);
3804 for (i = 0; i < solv->decisionq.count; i++)
3806 p = solv->decisionq.elements[i];
3809 s = pool->solvables + p;
3812 sugp = s->repo->idarraydata + s->suggests;
3813 while ((sug = *sugp++) != 0)
3815 FOR_PROVIDES(p, pp, sug)
3816 if (solv->decisionmap[p] > 0)
3822 FOR_PROVIDES(p, pp, sug)
3823 if (solv->decisionmap[p] > 0)
3824 MAPSET(&solv->suggestsmap, p);
3826 continue; /* already fulfilled */
3828 FOR_PROVIDES(p, pp, sug)
3829 MAPSET(&solv->suggestsmap, p);
3833 for (i = 1; i < pool->nsolvables; i++)
3835 if (solv->decisionmap[i] < 0)
3837 if (solv->decisionmap[i] > 0 && noselected)
3839 if (MAPTST(&obsmap, i))
3841 s = pool->solvables + i;
3842 if (!MAPTST(&solv->suggestsmap, i))
3846 if (!pool_installable(pool, s))
3848 if (!solver_is_enhancing(solv, s))
3851 queue_push(suggestionsq, i);
3853 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
3856 /* undo removedisabledconflicts */
3858 undo_removedisabledconflicts(solv, &redoq);
3861 /* undo job rule disabling */
3862 for (i = 0; i < disabledq.count; i++)
3863 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
3864 queue_free(&disabledq);
3869 /***********************************************************************/
3870 /* disk usage computations */
3872 /*-------------------------------------------------------------------
3874 * calculate DU changes
3878 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
3882 solver_create_state_maps(solv, &installedmap, 0);
3883 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
3884 map_free(&installedmap);
3888 /*-------------------------------------------------------------------
3890 * calculate changes in install size
3894 solver_calc_installsizechange(Solver *solv)
3899 solver_create_state_maps(solv, &installedmap, 0);
3900 change = pool_calc_installsizechange(solv->pool, &installedmap);
3901 map_free(&installedmap);
3906 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
3908 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
3912 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
3914 Pool *pool = solv->pool;
3917 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
3918 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
3919 for (i = 0; i < res->count; i++)
3920 if (res->elements[i] != -1)
3922 Solvable *s = pool->solvables + pkgs->elements[i];
3923 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
3924 res->elements[i] = -1;
3926 map_free(&installedmap);
3929 /*-------------------------------------------------------------------
3931 * decision introspection
3935 solver_get_decisionlevel(Solver *solv, Id p)
3937 return solv->decisionmap[p];
3941 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
3943 queue_free(decisionq);
3944 queue_init_clone(decisionq, &solv->decisionq);
3948 solver_get_lastdecisionblocklevel(Solver *solv)
3951 if (solv->decisionq.count == 0)
3953 p = solv->decisionq.elements[solv->decisionq.count - 1];
3956 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
3960 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
3965 queue_empty(decisionq);
3966 for (i = 0; i < solv->decisionq.count; i++)
3968 p = solv->decisionq.elements[i];
3971 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3974 if (i == solv->decisionq.count)
3976 for (i = 0; i < solv->decisionq.count; i++)
3978 p = solv->decisionq.elements[i];
3981 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
3982 queue_push(decisionq, p);
3989 solver_describe_decision(Solver *solv, Id p, Id *infop)
3996 if (!solv->decisionmap[p])
3997 return SOLVER_REASON_UNRELATED;
3998 pp = solv->decisionmap[p] < 0 ? -p : p;
3999 for (i = 0; i < solv->decisionq.count; i++)
4000 if (solv->decisionq.elements[i] == pp)
4002 if (i == solv->decisionq.count) /* just in case... */
4003 return SOLVER_REASON_UNRELATED;
4004 why = solv->decisionq_why.elements[i];
4009 return SOLVER_REASON_UNIT_RULE;
4012 if (i < solv->decisioncnt_update)
4017 *infop = SYSTEMSOLVABLE;
4018 return SOLVER_REASON_KEEP_INSTALLED;
4022 return SOLVER_REASON_RESOLVE_JOB;
4024 if (i < solv->decisioncnt_keep)
4026 if (why == 0 && pp < 0)
4027 return SOLVER_REASON_CLEANDEPS_ERASE;
4030 if (why >= solv->updaterules && why < solv->updaterules_end)
4031 *infop = why - solv->updaterules;
4032 else if (why >= solv->featurerules && why < solv->featurerules_end)
4033 *infop = why - solv->featurerules;
4035 return SOLVER_REASON_UPDATE_INSTALLED;
4037 if (i < solv->decisioncnt_resolve)
4039 if (why == 0 && pp < 0)
4040 return SOLVER_REASON_CLEANDEPS_ERASE;
4043 if (why >= solv->updaterules && why < solv->updaterules_end)
4044 *infop = why - solv->updaterules;
4045 else if (why >= solv->featurerules && why < solv->featurerules_end)
4046 *infop = why - solv->featurerules;
4048 return SOLVER_REASON_KEEP_INSTALLED;
4050 if (i < solv->decisioncnt_weak)
4054 return SOLVER_REASON_RESOLVE;
4056 if (solv->decisionq.count < solv->decisioncnt_orphan)
4057 return SOLVER_REASON_WEAKDEP;
4058 return SOLVER_REASON_RESOLVE_ORPHAN;
4063 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4065 Pool *pool = solv->pool;
4067 int level = solv->decisionmap[p];
4074 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4075 if (solv->decisionq.elements[decisionno] == p)
4077 if (decisionno == solv->decisionq.count)
4079 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4082 /* 1) list all packages that recommend us */
4083 for (i = 1; i < pool->nsolvables; i++)
4085 Id *recp, rec, pp2, p2;
4086 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4088 s = pool->solvables + i;
4091 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4093 recp = s->repo->idarraydata + s->recommends;
4094 while ((rec = *recp++) != 0)
4097 FOR_PROVIDES(p2, pp2, rec)
4103 /* if p2 is already installed, this recommends is ignored */
4104 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4110 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4111 queue_push2(whyq, p2, rec);
4115 /* 2) list all supplements */
4116 s = pool->solvables + p;
4117 if (s->supplements && level > 0)
4119 Id *supp, sup, pp2, p2;
4120 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4121 * everything above our level in the decisionmap */
4122 for (i = decisionno; i < solv->decisionq.count; i++ )
4124 p2 = solv->decisionq.elements[i];
4126 solv->decisionmap[p2] = -solv->decisionmap[p2];
4128 supp = s->repo->idarraydata + s->supplements;
4129 while ((sup = *supp++) != 0)
4130 if (solver_dep_fulfilled(solv, sup))
4133 /* let's see if this is an easy supp */
4134 FOR_PROVIDES(p2, pp2, sup)
4136 if (!solv->addalreadyrecommended && solv->installed)
4138 if (pool->solvables[p2].repo == solv->installed)
4141 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4143 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4144 queue_push2(whyq, p2, sup);
4150 /* hard case, just note dependency with no package */
4151 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4152 queue_push2(whyq, 0, sup);
4155 for (i = decisionno; i < solv->decisionq.count; i++)
4157 p2 = solv->decisionq.elements[i];
4159 solv->decisionmap[p2] = -solv->decisionmap[p2];
4165 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4168 how &= SOLVER_SELECTMASK;
4170 if (how == SOLVER_SOLVABLE_ALL)
4172 FOR_POOL_SOLVABLES(p)
4173 queue_push(pkgs, p);
4175 else if (how == SOLVER_SOLVABLE_REPO)
4177 Repo *repo = pool_id2repo(pool, what);
4180 FOR_REPO_SOLVABLES(repo, p, s)
4181 queue_push(pkgs, p);
4185 FOR_JOB_SELECT(p, pp, how, what)
4186 queue_push(pkgs, p);
4191 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4194 Id select = how & SOLVER_SELECTMASK;
4195 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4197 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4199 if (!pool->installed)
4201 FOR_JOB_SELECT(p, pp, select, what)
4202 if (pool->solvables[p].repo == pool->installed)
4205 FOR_JOB_SELECT(p, pp, select, what)
4207 Solvable *s = pool->solvables + p;
4208 FOR_PROVIDES(pi, pip, s->name)
4210 Solvable *si = pool->solvables + pi;
4211 if (si->repo != pool->installed || si->name != s->name)
4217 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4218 while ((obs = *obsp++) != 0)
4220 FOR_PROVIDES(pi, pip, obs)
4222 Solvable *si = pool->solvables + pi;
4223 if (si->repo != pool->installed)
4225 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4227 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4238 solver_select2str(Pool *pool, Id select, Id what)
4242 select &= SOLVER_SELECTMASK;
4243 if (select == SOLVER_SOLVABLE)
4244 return pool_solvid2str(pool, what);
4245 if (select == SOLVER_SOLVABLE_NAME)
4246 return pool_dep2str(pool, what);
4247 if (select == SOLVER_SOLVABLE_PROVIDES)
4249 s = pool_dep2str(pool, what);
4250 b = pool_alloctmpspace(pool, 11 + strlen(s));
4251 sprintf(b, "providing %s", s);
4254 if (select == SOLVER_SOLVABLE_ONE_OF)
4258 while ((p = pool->whatprovidesdata[what++]) != 0)
4260 s = pool_solvid2str(pool, p);
4262 b = pool_tmpappend(pool, b, ", ", s);
4264 b = pool_tmpjoin(pool, s, 0, 0);
4265 pool_freetmpspace(pool, s);
4267 return b ? b : "nothing";
4269 if (select == SOLVER_SOLVABLE_REPO)
4271 b = pool_alloctmpspace(pool, 20);
4272 sprintf(b, "repo #%d", what);
4275 if (select == SOLVER_SOLVABLE_ALL)
4276 return "all packages";
4277 return "unknown job select";
4281 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
4283 Id select = how & SOLVER_SELECTMASK;
4284 const char *strstart = 0, *strend = 0;
4288 switch (how & SOLVER_JOBMASK)
4291 return "do nothing";
4292 case SOLVER_INSTALL:
4293 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
4294 strstart = "keep ", strend = "installed";
4295 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
4296 strstart = "install ";
4297 else if (select == SOLVER_SOLVABLE_PROVIDES)
4298 strstart = "install a package ";
4300 strstart = "install one of ";
4303 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
4304 strstart = "keep ", strend = "unstalled";
4305 else if (select == SOLVER_SOLVABLE_PROVIDES)
4306 strstart = "deinstall all packages ";
4308 strstart = "deinstall ";
4311 strstart = "update ";
4313 case SOLVER_WEAKENDEPS:
4314 strstart = "weaken deps of ";
4316 case SOLVER_MULTIVERSION:
4317 strstart = "multi version ";
4320 strstart = "update ";
4322 case SOLVER_DISTUPGRADE:
4323 strstart = "dist upgrade ";
4326 strstart = "verify ";
4328 case SOLVER_DROP_ORPHANED:
4329 strstart = "deinstall ", strend = "if orphaned";
4331 case SOLVER_USERINSTALLED:
4332 strstart = "regard ", strend = "as userinstalled";
4335 strstart = "unknown job ";
4338 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
4340 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
4343 s = pool_tmpappend(pool, s, " ", 0);
4344 if (how & SOLVER_WEAK)
4345 s = pool_tmpappend(pool, s, ",weak", 0);
4346 if (how & SOLVER_ESSENTIAL)
4347 s = pool_tmpappend(pool, s, ",essential", 0);
4348 if (how & SOLVER_CLEANDEPS)
4349 s = pool_tmpappend(pool, s, ",cleandeps", 0);
4350 if (how & SOLVER_SETEV)
4351 s = pool_tmpappend(pool, s, ",setev", 0);
4352 if (how & SOLVER_SETEVR)
4353 s = pool_tmpappend(pool, s, ",setevr", 0);
4354 if (how & SOLVER_SETARCH)
4355 s = pool_tmpappend(pool, s, ",setarch", 0);
4356 if (how & SOLVER_SETVENDOR)
4357 s = pool_tmpappend(pool, s, ",setvendor", 0);
4358 if (how & SOLVER_SETREPO)
4359 s = pool_tmpappend(pool, s, ",setrepo", 0);
4360 if (how & SOLVER_NOAUTOSET)
4361 s = pool_tmpappend(pool, s, ",noautoset", 0);
4362 if (s[o + 1] != ',')
4363 s = pool_tmpappend(pool, s, ",?", 0);
4365 return pool_tmpappend(pool, s, "]", 0);