2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
26 #define RULES_BLOCK 63
30 solver_dep_installed(Solver *solv, Id dep)
32 /* disable for now, splitprovides don't work anyway and it breaks
35 Pool *pool = solv->pool;
40 Reldep *rd = GETRELDEP(pool, dep);
41 if (rd->flags == REL_AND)
43 if (!solver_dep_installed(solv, rd->name))
45 return solver_dep_installed(solv, rd->evr);
47 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
48 return solver_dep_installed(solv, rd->evr);
50 FOR_PROVIDES(p, pp, dep)
52 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
60 /* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
62 dep_possible(Solver *solv, Id dep, Map *m)
64 Pool *pool = solv->pool;
69 Reldep *rd = GETRELDEP(pool, dep);
70 if (rd->flags == REL_AND)
72 if (!dep_possible(solv, rd->name, m))
74 return dep_possible(solv, rd->evr, m);
76 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
77 return solver_dep_installed(solv, rd->evr);
79 FOR_PROVIDES(p, pp, dep)
87 /*-----------------------------------------------------------------*/
94 printruleelement(Solver *solv, Rule *r, Id v)
96 Pool *pool = solv->pool;
100 s = pool->solvables + -v;
101 printf(" !%s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), -v);
105 s = pool->solvables + v;
106 printf(" %s-%s.%s [%d]", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), v);
115 if (solv->decisionmap[s - pool->solvables] > 0)
116 printf(" Install.level%d", solv->decisionmap[s - pool->solvables]);
117 if (solv->decisionmap[s - pool->solvables] < 0)
118 printf(" Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
120 printf(" (disabled)");
130 printrule(Solver *solv, Rule *r)
135 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
136 printf("Rule #%d:\n", (int)(r - solv->rules));
138 printf("Rule:\n"); /* r is any rule */
143 else if (r->d == ID_NULL)
150 v = solv->pool->whatprovidesdata[r->d + i - 1];
153 printruleelement(solv, r, v);
155 printf(" next: %d %d\n", r->n1, r->n2);
159 /*-----------------------------------------------------------------*/
165 static Pool *unifyrules_sortcmp_data;
168 * compare rules for unification sort
172 unifyrules_sortcmp(const void *ap, const void *bp)
174 Pool *pool = unifyrules_sortcmp_data;
175 Rule *a = (Rule *)ap;
176 Rule *b = (Rule *)bp;
182 return x; /* p differs */
185 if (a->d == 0 && b->d == 0)
186 return a->w2 - b->w2; /* assertion: return w2 diff */
188 if (a->d == 0) /* a is assertion, b not */
190 x = a->w2 - pool->whatprovidesdata[b->d];
194 if (b->d == 0) /* b is assertion, a not */
196 x = pool->whatprovidesdata[a->d] - b->w2;
200 /* compare whatprovidesdata */
201 ad = pool->whatprovidesdata + a->d;
202 bd = pool->whatprovidesdata + b->d;
204 if ((x = *ad++ - *bd++) != 0)
215 unifyrules(Solver *solv)
220 if (solv->nrules <= 1) /* nothing to unify */
223 if (solv->pool->verbose > 3)
224 printf ("----- unifyrules -----\n");
226 /* sort rules first */
227 unifyrules_sortcmp_data = solv->pool;
228 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
235 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
237 if (jr && !unifyrules_sortcmp(ir, jr))
238 continue; /* prune! */
239 jr = solv->rules + j++; /* keep! */
244 /* reduced count from nrules to j rules */
245 if (solv->pool->verbose) printf("pruned rules from %d to %d\n", solv->nrules, j);
247 /* adapt rule buffer */
249 solv->rules = (Rule *)xrealloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
251 if (solv->pool->verbose)
258 for (i = 1; i < solv->nrules; i++)
265 dp = solv->pool->whatprovidesdata + r->d;
270 printf(" binary: %d\n", binr);
271 printf(" normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
274 if (solv->pool->verbose > 3)
275 printf ("----- unifyrules end -----\n");
285 hashrule(Solver *solv, Id p, Id d, int n)
287 unsigned int x = (unsigned int)p;
291 return (x * 37) ^ (unsigned int)d;
292 dp = solv->pool->whatprovidesdata + d;
294 x = (x * 37) ^ (unsigned int)*dp++;
302 * p = direct literal; always < 0 for installed rpm rules
303 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
306 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
308 * p < 0 : pkg id of A
309 * d > 0 : Offset in whatprovidesdata (list of providers of b)
311 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
312 * p < 0 : pkg id of A
313 * d < 0 : Id of solvable (e.g. B1)
315 * d == 0: unary rule, assertion => (A) or (-A)
317 * Install: p > 0, d = 0 (A) user requested install
318 * Remove: p < 0, d = 0 (-A) user requested remove
319 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
320 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
321 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
322 * ? p > 0, d < 0 (A|-B)
323 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
327 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
328 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
329 * every other : w1 = p, w2 = whatprovidesdata[d];
330 * Disabled rule: w1 = 0
332 * always returns a rule for non-rpm rules
336 addrule(Solver *solv, Id p, Id d)
341 int n = 0; /* number of literals in rule - 1
342 0 = direct assertion (single literal)
346 /* it often happenes that requires lead to adding the same rpm rule
347 * multiple times, so we prune those duplicates right away to make
348 * the work for unifyrules a bit easier */
350 if (solv->nrules && !solv->jobrules)
352 r = solv->rules + solv->nrules - 1; /* get the last added rule */
353 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
359 /* always a binary rule */
361 return 0; /* ignore self conflict */
366 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, n++)
368 return 0; /* rule is self-fulfilling */
373 if (n == 0 && !solv->jobrules)
375 /* this is a rpm rule assertion, we do not have to allocate it */
376 /* it can be identified by a level of 1 and a zero reason */
377 /* we must not drop those rules from the decisionq when rewinding! */
380 if (solv->decisionmap[-p] > 0 || solv->decisionmap[-p] < -1)
382 if (solv->decisionmap[-p])
383 return 0; /* already got that one */
384 queue_push(&solv->decisionq, p);
385 queue_push(&solv->decisionq_why, 0);
386 solv->decisionmap[-p] = -1;
391 /* smallest literal first so we can find dups */
395 n = 1; /* re-set n, was used as temp var */
398 /* check if the last added rule is exactly the same as what we're looking for. */
399 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
402 if (r && n > 1 && r->d && r->p == p)
407 dp2 = solv->pool->whatprovidesdata + r->d;
408 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, dp2++)
419 /* check and extend rule buffer */
420 if ((solv->nrules & RULES_BLOCK) == 0)
422 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
425 r = solv->rules + solv->nrules++; /* point to rule space */
430 /* direct assertion, no watch needed */
446 r->w2 = solv->pool->whatprovidesdata[d];
451 if (solv->pool->verbose > 3)
453 printf (" Add rule: ");
461 disablerule(Solver *solv, Rule *r)
467 enablerule(Solver *solv, Rule *r)
469 if (r->d == 0 || r->w2 != r->p)
472 r->w1 = solv->pool->whatprovidesdata[r->d];
476 /**********************************************************************************/
478 /* a problem is an item on the solver's problem list. It can either be >0, in that
479 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
480 * consisting of multiple job rules.
484 disableproblem(Solver *solv, Id v)
492 disablerule(solv, solv->rules + v);
496 jp = solv->ruletojob.elements;
497 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
499 disablerule(solv, r);
503 enableproblem(Solver *solv, Id v)
511 enablerule(solv, solv->rules + v);
515 jp = solv->ruletojob.elements;
516 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
522 printproblem(Solver *solv, Id v)
529 printrule(solv, solv->rules + v);
533 printf("JOB %d\n", v);
534 jp = solv->ruletojob.elements;
535 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
547 /************************************************************************/
549 /* go through system and job rules and add direct assertions
550 * to the decisionqueue. If we find a conflict, disable rules and
551 * add them to problem queue.
552 * (disablerules is always true for the cases when we get called)
555 makeruledecisions(Solver *solv)
562 if (solv->pool->verbose > 3)
563 printf ("----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
565 decisionstart = solv->decisionq.count;
566 /* rpm rules don't have assertions, so we can start with the job
568 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
570 if (!r->w1 || r->w2) /* disabled or no assertion */
574 if (solv->decisionmap[vv] == 0)
576 queue_push(&solv->decisionq, v);
577 queue_push(&solv->decisionq_why, r - solv->rules);
578 solv->decisionmap[vv] = v > 0 ? 1 : -1;
579 if (solv->pool->verbose > 3)
581 Solvable *s = solv->pool->solvables + vv;
583 printf("removing %s-%s.%s\n", id2str(solv->pool, s->name), id2str(solv->pool, s->evr), id2str(solv->pool, s->arch));
585 printf("installing %s-%s.%s\n", id2str(solv->pool, s->name), id2str(solv->pool, s->evr), id2str(solv->pool, s->arch));
589 if (v > 0 && solv->decisionmap[vv] > 0)
591 if (v < 0 && solv->decisionmap[vv] < 0)
593 /* found a conflict! */
594 if (ri >= solv->learntrules)
596 /* cannot happen, as this would mean that the problem
597 * was not solvable, so we wouldn't have created the
598 * learnt rule at all */
601 /* if we are weak, just disable ourself */
602 if (ri >= solv->weakrules)
604 printf("conflict, but I am weak, disabling ");
606 disablerule(solv, r);
611 queue_push(&solv->problems, solv->learnt_pool.count);
612 queue_push(&solv->learnt_pool, ri);
613 queue_push(&solv->learnt_pool, 0);
615 /* only job and system rules left */
616 for (i = 0; i < solv->decisionq.count; i++)
617 if (solv->decisionq.elements[i] == -v)
619 if (i == solv->decisionq.count)
621 if (solv->decisionq_why.elements[i] == 0)
623 /* conflict with rpm rule, need only disable our rule */
624 printf("conflict with rpm rule, disabling rule #%d\n", ri);
625 if (ri < solv->systemrules)
626 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
627 queue_push(&solv->problems, v);
628 disableproblem(solv, v);
629 queue_push(&solv->problems, 0);
632 /* conflict with another job or system rule */
633 printf("conflicting system/job rules over literal %d\n", vv);
634 /* push all of our rules asserting this literal on the problem stack */
635 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
637 if (!rr->w1 || rr->w2)
639 if (rr->p != v && rr->p != -v)
641 printf(" - disabling rule #%d\n", i);
643 if (i < solv->systemrules)
644 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
645 queue_push(&solv->problems, v);
646 disableproblem(solv, v);
648 queue_push(&solv->problems, 0);
651 while (solv->decisionq.count > decisionstart)
653 v = solv->decisionq.elements[--solv->decisionq.count];
654 --solv->decisionq_why.count;
656 solv->decisionmap[vv] = 0;
658 ri = solv->jobrules - 1;
659 r = solv->rules + ri;
662 if (solv->pool->verbose > 3)
663 printf ("----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
667 * we have enabled or disabled some of our rules. We now reenable all
668 * of our learnt rules but the ones that were learnt from rules that
672 enabledisablelearntrules(Solver *solv)
674 Pool *pool = solv->pool;
680 printf("enabledisablelearntrules called\n");
681 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
683 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
684 while ((why = *whyp++) != 0)
686 if (why < 0 || why >= i)
687 abort(); /* cannot reference newer learnt rules */
688 if (!solv->rules[why].w1)
691 /* why != 0: we found a disabled rule, disable the learnt rule */
696 printf("disabling learnt ");
699 disablerule(solv, r);
701 else if (!why && !r->w1)
705 printf("re-enabling learnt ");
714 /* FIXME: bad code ahead, replace as soon as possible */
716 disableupdaterules(Solver *solv, Queue *job, int jobidx)
718 Pool *pool = solv->pool;
720 Id how, what, p, *pp;
726 installed = solv->installed;
732 how = job->elements[jobidx];
735 case SOLVER_INSTALL_SOLVABLE:
736 case SOLVER_ERASE_SOLVABLE:
737 case SOLVER_ERASE_SOLVABLE_NAME:
738 case SOLVER_ERASE_SOLVABLE_PROVIDES:
744 /* go through all enabled job rules */
745 MAPZERO(&solv->noupdate);
746 for (i = solv->jobrules; i < solv->systemrules; i++)
749 if (!r->w1) /* disabled? */
751 j = solv->ruletojob.elements[i - solv->jobrules];
755 how = job->elements[j];
756 what = job->elements[j + 1];
759 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
760 s = pool->solvables + what;
761 FOR_PROVIDES(p, pp, s->name)
763 if (pool->solvables[p].name != s->name)
765 if (pool->solvables[p].repo == installed)
766 MAPSET(&solv->noupdate, p - installed->start);
769 case SOLVER_ERASE_SOLVABLE:
770 s = pool->solvables + what;
771 if (s->repo == installed)
772 MAPSET(&solv->noupdate, what - installed->start);
774 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
775 case SOLVER_ERASE_SOLVABLE_PROVIDES:
776 FOR_PROVIDES(p, pp, what)
778 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
780 if (pool->solvables[p].repo == installed)
781 MAPSET(&solv->noupdate, p - installed->start);
789 /* fixup update rule status */
790 if (solv->allowuninstall)
791 return; /* no update rules at all */
795 /* we just disabled job #jobidx. enable all update rules
796 * that aren't disabled by the remaining job rules */
797 how = job->elements[jobidx];
798 what = job->elements[jobidx + 1];
801 case SOLVER_INSTALL_SOLVABLE:
802 s = pool->solvables + what;
803 FOR_PROVIDES(p, pp, s->name)
805 if (pool->solvables[p].name != s->name)
807 if (pool->solvables[p].repo != installed)
809 if (MAPTST(&solv->noupdate, p - installed->start))
811 r = solv->rules + solv->systemrules + (p - installed->start);
817 printf("@@@ re-enabling ");
822 case SOLVER_ERASE_SOLVABLE:
823 s = pool->solvables + what;
824 if (s->repo != installed)
826 if (MAPTST(&solv->noupdate, what - installed->start))
828 r = solv->rules + solv->systemrules + (what - installed->start);
834 printf("@@@ re-enabling ");
838 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
839 case SOLVER_ERASE_SOLVABLE_PROVIDES:
840 FOR_PROVIDES(p, pp, what)
842 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
844 if (pool->solvables[p].repo != installed)
846 if (MAPTST(&solv->noupdate, p - installed->start))
848 r = solv->rules + solv->systemrules + (p - installed->start);
854 printf("@@@ re-enabling ");
865 for (i = 0; i < installed->nsolvables; i++)
867 r = solv->rules + solv->systemrules + i;
868 if (r->w1 && MAPTST(&solv->noupdate, i))
869 disablerule(solv, r); /* was enabled, need to disable */
875 * add (install) rules for solvable
876 * for unfulfilled requirements, conflicts, obsoletes,....
877 * add a negative assertion for solvables that are not installable
881 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
883 Pool *pool = solv->pool;
884 Repo *installed = solv->installed;
898 if (solv->pool->verbose > 3)
899 printf ("----- addrpmrulesforsolvable -----\n");
901 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
902 queue_push(&q, s - pool->solvables); /* push solvable Id */
908 * s: Pointer to solvable
912 if (MAPTST(m, n)) /* continue if already done */
916 s = pool->solvables + n; /* s = Solvable in question */
919 if (installed /* Installed system available */
920 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
921 && s->repo == installed) /* solvable is installed? */
923 dontfix = 1; /* dont care about broken rpm deps */
926 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
929 printf("package %s-%s.%s [%d] is not installable\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables));
930 addrule(solv, -n, 0); /* uninstallable */
933 /*-----------------------------------------
934 * check requires of s
939 reqp = s->repo->idarraydata + s->requires;
940 while ((req = *reqp++) != 0) /* go throw all requires */
942 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
945 dp = GET_PROVIDESP(req, p); /* get providers of req; p is a dummy only */
947 if (*dp == SYSTEMSOLVABLE) /* always installed */
952 /* the strategy here is to not insist on dependencies
953 * that are already broken. so if we find one provider
954 * that was already installed, we know that the
955 * dependency was not broken before so we enforce it */
956 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
958 if (pool->solvables[p].repo == installed)
959 break; /* provider was installed */
961 if (!p) /* previously broken dependency */
964 printf("ignoring broken requires %s of installed package %s-%s.%s\n", dep2str(pool, req), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
971 /* nothing provides req! */
973 printf("package %s-%s.%s [%d] is not installable (%s)\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables), dep2str(pool, req));
974 addrule(solv, -n, 0); /* mark requestor as uninstallable */
978 if (pool->verbose > 2)
980 printf(" %s-%s.%s requires %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
981 for (i = 0; dp[i]; i++)
982 printf(" provided by %s-%s.%s\n", id2str(pool, pool->solvables[dp[i]].name), id2str(pool, pool->solvables[dp[i]].evr), id2str(pool, pool->solvables[dp[i]].arch));
985 /* add 'requires' dependency */
986 /* rule: (-requestor|provider1|provider2|...|providerN) */
987 addrule(solv, -n, dp - pool->whatprovidesdata);
989 /* descend the dependency tree */
990 for (; *dp; dp++) /* loop through all providers */
996 } /* while, requirements of n */
998 } /* if, requirements */
1000 /* that's all we check for src packages */
1001 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1004 /*-----------------------------------------
1005 * check conflicts of s
1010 conp = s->repo->idarraydata + s->conflicts;
1011 while ((con = *conp++) != 0)
1013 FOR_PROVIDES(p, pp, con)
1015 /* dontfix: dont care about conflicts with already installed packs */
1016 if (dontfix && pool->solvables[p].repo == installed)
1018 /* rule: -n|-p: either solvable _or_ provider of conflict */
1019 addrule(solv, -n, -p);
1024 /*-----------------------------------------
1025 * check obsoletes if not installed
1027 if (!installed || pool->solvables[n].repo != installed)
1028 { /* not installed */
1031 obsp = s->repo->idarraydata + s->obsoletes;
1032 while ((obs = *obsp++) != 0)
1034 FOR_PROVIDES(p, pp, obs)
1035 addrule(solv, -n, -p);
1038 FOR_PROVIDES(p, pp, s->name)
1040 if (s->name == pool->solvables[p].name)
1041 addrule(solv, -n, -p);
1045 /*-----------------------------------------
1046 * add recommends to the rule list
1050 recp = s->repo->idarraydata + s->recommends;
1051 while ((rec = *recp++) != 0)
1053 FOR_PROVIDES(p, pp, rec)
1060 sugp = s->repo->idarraydata + s->suggests;
1061 while ((sug = *sugp++) != 0)
1063 FOR_PROVIDES(p, pp, sug)
1070 if (solv->pool->verbose > 3)
1071 printf ("----- addrpmrulesforsolvable end -----\n");
1076 addrpmrulesforweak(Solver *solv, Map *m)
1078 Pool *pool = solv->pool;
1083 if (solv->pool->verbose > 3)
1084 printf ("----- addrpmrulesforweak -----\n");
1085 for (i = n = 1; n < pool->nsolvables; i++, n++)
1087 if (i == pool->nsolvables)
1091 s = pool->solvables + i;
1092 if (!pool_installable(pool, s))
1097 supp = s->repo->idarraydata + s->supplements;
1098 while ((sup = *supp++) != ID_NULL)
1099 if (dep_possible(solv, sup, m))
1102 if (!sup && s->freshens)
1104 supp = s->repo->idarraydata + s->freshens;
1105 while ((sup = *supp++) != ID_NULL)
1106 if (dep_possible(solv, sup, m))
1109 if (!sup && s->enhances)
1111 supp = s->repo->idarraydata + s->enhances;
1112 while ((sup = *supp++) != ID_NULL)
1113 if (dep_possible(solv, sup, m))
1118 addrpmrulesforsolvable(solv, s, m);
1121 if (solv->pool->verbose > 3)
1122 printf ("----- addrpmrulesforweak end -----\n");
1126 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1128 Pool *pool = solv->pool;
1133 if (solv->pool->verbose > 3)
1134 printf ("----- addrpmrulesforupdaters -----\n");
1136 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1137 policy_findupdatepackages(solv, s, &qs, allowall);
1138 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1139 addrpmrulesforsolvable(solv, s, m);
1140 for (i = 0; i < qs.count; i++)
1141 if (!MAPTST(m, qs.elements[i]))
1142 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1145 if (solv->pool->verbose > 3)
1146 printf ("----- addrpmrulesforupdaters -----\n");
1151 * add rule for update
1152 * (A|A1|A2|A3...) An = update candidates for A
1154 * s = (installed) solvable
1158 addupdaterule(Solver *solv, Solvable *s, int allowall)
1160 /* installed packages get a special upgrade allowed rule */
1161 Pool *pool = solv->pool;
1166 if (solv->pool->verbose > 3)
1167 printf ("----- addupdaterule -----\n");
1169 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1170 policy_findupdatepackages(solv, s, &qs, allowall);
1171 if (qs.count == 0) /* no updaters found */
1174 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1176 addrule(solv, s - pool->solvables, d); /* allow update of s */
1177 if (solv->pool->verbose > 3)
1178 printf ("----- addupdaterule end -----\n");
1182 /*-----------------------------------------------------------------*/
1189 * initial setup for all watches
1193 makewatches(Solver *solv)
1197 int nsolvables = solv->pool->nsolvables;
1199 xfree(solv->watches);
1200 /* lower half for removals, upper half for installs */
1201 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
1203 /* do it reverse so rpm rules get triggered first */
1204 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1206 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1209 if (!r->w1 /* rule is disabled */
1210 || !r->w2) /* rule is assertion */
1213 /* see addwatches(solv, r) */
1214 r->n1 = solv->watches[nsolvables + r->w1];
1215 solv->watches[nsolvables + r->w1] = r - solv->rules;
1217 r->n2 = solv->watches[nsolvables + r->w2];
1218 solv->watches[nsolvables + r->w2] = r - solv->rules;
1224 * add watches (for rule)
1228 addwatches(Solver *solv, Rule *r)
1230 int nsolvables = solv->pool->nsolvables;
1232 r->n1 = solv->watches[nsolvables + r->w1];
1233 solv->watches[nsolvables + r->w1] = r - solv->rules;
1235 r->n2 = solv->watches[nsolvables + r->w2];
1236 solv->watches[nsolvables + r->w2] = r - solv->rules;
1240 /*-----------------------------------------------------------------*/
1241 /* rule propagation */
1243 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1248 * propagate decision to all rules
1252 propagate(Solver *solv, int level)
1254 Pool *pool = solv->pool;
1259 Id *decisionmap = solv->decisionmap;
1260 Id *watches = solv->watches + pool->nsolvables;
1262 if (solv->pool->verbose > 3)
1263 printf ("----- propagate -----\n");
1265 while (solv->propagate_index < solv->decisionq.count)
1267 /* negate because our watches trigger if literal goes FALSE */
1268 pkg = -solv->decisionq.elements[solv->propagate_index++];
1269 if (pool->verbose > 3)
1271 printf("popagate for decision %d level %d\n", -pkg, level);
1272 printruleelement(solv, 0, -pkg);
1275 for (rp = watches + pkg; *rp; rp = nrp)
1277 r = solv->rules + *rp;
1279 if (pool->verbose > 3)
1281 printf(" watch triggered ");
1295 /* if clause is TRUE, nothing to do */
1296 if (DECISIONMAP_TRUE(ow))
1301 /* not a binary clause, check if we need to move our watch */
1302 /* search for a literal that is not ow and not false */
1303 /* (true is also ok, in that case the rule is fulfilled) */
1304 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1307 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1308 if (p != ow && !DECISIONMAP_TRUE(-p))
1312 /* p is free to watch, move watch to p */
1313 if (pool->verbose > 3)
1316 printf(" -> move w%d to %s-%s.%s\n", (pkg == r->w1 ? 1 : 2), id2str(pool, pool->solvables[p].name), id2str(pool, pool->solvables[p].evr), id2str(pool, pool->solvables[p].arch));
1318 printf(" -> move w%d to !%s-%s.%s\n", (pkg == r->w1 ? 1 : 2), id2str(pool, pool->solvables[-p].name), id2str(pool, pool->solvables[-p].evr), id2str(pool, pool->solvables[-p].arch));
1332 watches[p] = r - solv->rules;
1336 /* unit clause found, set other watch to TRUE */
1337 if (DECISIONMAP_TRUE(-ow))
1338 return r; /* eek, a conflict! */
1339 if (pool->verbose > 2)
1345 decisionmap[ow] = level;
1347 decisionmap[-ow] = -level;
1348 queue_push(&solv->decisionq, ow);
1349 queue_push(&solv->decisionq_why, r - solv->rules);
1350 if (pool->verbose > 3)
1352 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1354 printf(" -> decided to install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1356 printf(" -> decided to conflict %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1360 if (solv->pool->verbose > 3)
1361 printf ("----- propagate end-----\n");
1363 return 0; /* all is well */
1367 /*-----------------------------------------------------------------*/
1376 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1378 Pool *pool = solv->pool;
1381 Map seen; /* global? */
1385 int learnt_why = solv->learnt_pool.count;
1386 Id *decisionmap = solv->decisionmap;
1390 if (pool->verbose > 1) printf("ANALYZE at %d ----------------------\n", level);
1391 map_init(&seen, pool->nsolvables);
1392 idx = solv->decisionq.count;
1395 if (pool->verbose > 1)
1397 if (c - solv->rules >= solv->learntrules)
1399 else if (c - solv->rules >= solv->weakrules)
1401 else if (c - solv->rules >= solv->systemrules)
1403 else if (c - solv->rules >= solv->jobrules)
1407 queue_push(&solv->learnt_pool, c - solv->rules);
1408 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1419 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1421 vv = v > 0 ? v : -v;
1422 if (MAPTST(&seen, vv))
1424 l = solv->decisionmap[vv];
1431 for (j = 0; j < solv->decisionq.count; j++)
1432 if (solv->decisionq.elements[j] == v)
1434 if (j == solv->decisionq.count)
1436 queue_push(&rulq, -(j + 1));
1438 continue; /* initial setting */
1442 num++; /* need to do this one as well */
1446 if (pool->verbose > 3)
1448 printf("PUSH %d ", v);
1449 printruleelement(solv, 0, v);
1455 if (pool->verbose > 3)
1456 printf("num = %d\n", num);
1461 v = solv->decisionq.elements[--idx];
1462 vv = v > 0 ? v : -v;
1463 if (MAPTST(&seen, vv))
1466 c = solv->rules + solv->decisionq_why.elements[idx];
1474 else if (r.count == 1 && r.elements[0] < 0)
1475 *dr = r.elements[0];
1477 *dr = pool_queuetowhatprovides(pool, &r);
1478 if (pool->verbose > 1)
1480 printf("learned rule for level %d (am %d)\n", rlevel, level);
1481 printruleelement(solv, 0, -v);
1482 for (i = 0; i < r.count; i++)
1485 printruleelement(solv, 0, v);
1489 queue_push(&solv->learnt_pool, 0);
1490 if (pool->verbose > 3)
1492 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1494 printf("learnt_why ");
1495 printrule(solv, solv->rules + solv->learnt_pool.elements[i]);
1506 * reset the solver decisions to right after the rpm rules.
1507 * called after rules have been enabled/disabled
1511 reset_solver(Solver *solv)
1516 enabledisablelearntrules(solv);
1518 /* redo all direct rpm rule decisions */
1519 /* we break at the first decision with a why attached, this is
1520 * either a job/system rule assertion or a propagated decision */
1521 for (i = 0; i < solv->decisionq.count; i++)
1523 v = solv->decisionq.elements[i];
1524 solv->decisionmap[v > 0 ? v : -v] = 0;
1526 for (i = 0; i < solv->decisionq_why.count; i++)
1527 if (solv->decisionq_why.elements[i])
1531 v = solv->decisionq.elements[i];
1532 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1535 if (solv->pool->verbose > 1)
1536 printf("decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1538 solv->decisionq_why.count = i;
1539 solv->decisionq.count = i;
1540 solv->recommends_index = -1;
1541 solv->propagate_index = 0;
1543 /* redo all job/system decisions */
1544 makeruledecisions(solv);
1545 if (solv->pool->verbose > 1)
1546 printf("decisions so far: %d\n", solv->decisionq.count);
1547 /* recreate watch chains */
1553 * analyze_unsolvable_rule
1557 analyze_unsolvable_rule(Solver *solv, Rule *r)
1560 Id why = r - solv->rules;
1561 if (solv->pool->verbose > 1)
1563 if (why >= solv->jobrules && why < solv->systemrules)
1565 if (why >= solv->systemrules && why < solv->weakrules)
1566 printf("SYSTEM %d ", why - solv->systemrules);
1567 if (why >= solv->weakrules && why < solv->learntrules)
1569 if (solv->learntrules && why >= solv->learntrules)
1573 if (solv->learntrules && why >= solv->learntrules)
1575 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1576 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1579 /* do not add rpm rules to problem */
1580 if (why < solv->jobrules)
1582 /* turn rule into problem */
1583 if (why >= solv->jobrules && why < solv->systemrules)
1584 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1585 /* return if problem already countains our rule */
1586 if (solv->problems.count)
1588 for (i = solv->problems.count - 1; i >= 0; i--)
1589 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1591 else if (solv->problems.elements[i] == why)
1594 queue_push(&solv->problems, why);
1599 * analyze_unsolvable
1601 * return: 1 - disabled some rules, try again
1606 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1608 Pool *pool = solv->pool;
1610 Map seen; /* global to speed things up? */
1613 Id *decisionmap = solv->decisionmap;
1614 int oldproblemcount;
1617 if (pool->verbose > 1)
1618 printf("ANALYZE UNSOLVABLE ----------------------\n");
1619 oldproblemcount = solv->problems.count;
1621 /* make room for proof index */
1622 /* must update it later, as analyze_unsolvable_rule would confuse
1623 * it with a rule index if we put the real value in already */
1624 queue_push(&solv->problems, 0);
1627 map_init(&seen, pool->nsolvables);
1628 analyze_unsolvable_rule(solv, r);
1629 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1640 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1642 vv = v > 0 ? v : -v;
1643 l = solv->decisionmap[vv];
1648 idx = solv->decisionq.count;
1651 v = solv->decisionq.elements[--idx];
1652 vv = v > 0 ? v : -v;
1653 if (!MAPTST(&seen, vv))
1655 why = solv->decisionq_why.elements[idx];
1658 if (pool->verbose > 3)
1661 printruleelement(solv, 0, v);
1665 r = solv->rules + why;
1666 analyze_unsolvable_rule(solv, r);
1667 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1678 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1680 vv = v > 0 ? v : -v;
1681 l = solv->decisionmap[vv];
1688 queue_push(&solv->problems, 0); /* mark end of this problem */
1691 if (solv->weakrules != solv->learntrules)
1693 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1695 why = solv->problems.elements[i];
1696 if (why < solv->weakrules || why >= solv->learntrules)
1698 if (!lastweak || lastweak < why)
1704 /* disable last weak rule */
1705 solv->problems.count = oldproblemcount;
1706 r = solv->rules + lastweak;
1707 printf("disabling weak ");
1709 disablerule(solv, r);
1715 solv->problems.elements[oldproblemcount] = solv->learnt_pool.count;
1716 queue_push(&solv->learnt_pool, cr - solv->rules);
1717 queue_push(&solv->learnt_pool, 0);
1721 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1722 disableproblem(solv, solv->problems.elements[i]);
1727 printf("UNSOLVABLE\n");
1732 /*-----------------------------------------------------------------*/
1733 /* Decision revert */
1737 * revert decision at level
1741 revert(Solver *solv, int level)
1744 while (solv->decisionq.count)
1746 v = solv->decisionq.elements[solv->decisionq.count - 1];
1747 vv = v > 0 ? v : -v;
1748 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1750 if (solv->pool->verbose > 3)
1751 printf("reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1752 solv->decisionmap[vv] = 0;
1753 solv->decisionq.count--;
1754 solv->decisionq_why.count--;
1755 solv->propagate_index = solv->decisionq.count;
1757 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1759 solv->branches.count--;
1760 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1761 solv->branches.count--;
1763 solv->recommends_index = -1;
1768 * watch2onhighest - put watch2 on literal with highest level
1772 watch2onhighest(Solver *solv, Rule *r)
1778 return; /* binary rule, both watches are set */
1779 dp = solv->pool->whatprovidesdata + r->d;
1780 while ((v = *dp++) != 0)
1782 l = solv->decisionmap[v < 0 ? -v : v];
1797 * add free decision to decision q, increase level
1798 * propagate decision, return if no conflict.
1799 * in conflict case, analyze conflict rule, add resulting
1800 * rule to learnt rule set, make decision from learnt
1801 * rule (always unit) and re-propagate.
1805 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1815 solv->decisionmap[decision] = level;
1817 solv->decisionmap[-decision] = -level;
1818 queue_push(&solv->decisionq, decision);
1819 queue_push(&solv->decisionq_why, 0);
1823 r = propagate(solv, level);
1827 return analyze_unsolvable(solv, r, disablerules);
1828 printf("conflict with rule #%d\n", (int)(r - solv->rules));
1829 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1830 if (l >= level || l <= 0)
1832 printf("reverting decisions (level %d -> %d)\n", level, l);
1834 revert(solv, level);
1835 r = addrule(solv, p, d); /* p requires d */
1838 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules)
1840 printf("%d %d\n", solv->learnt_why.count, (int)(r - solv->rules) - solv->learntrules);
1843 queue_push(&solv->learnt_why, why);
1846 /* at least 2 literals, needs watches */
1847 watch2onhighest(solv, r);
1848 addwatches(solv, r);
1850 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1851 queue_push(&solv->decisionq, p);
1852 queue_push(&solv->decisionq_why, r - solv->rules);
1853 if (solv->pool->verbose > 1)
1855 printf("decision: ");
1856 printruleelement(solv, 0, p);
1857 printf("new rule: ");
1866 * install best package from the queue. We add an extra package, inst, if
1867 * provided. See comment in weak install section.
1870 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1872 Pool *pool = solv->pool;
1876 if (dq->count > 1 || inst)
1877 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1882 /* choose the supplemented one */
1883 for (i = 0; i < dq->count; i++)
1884 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1888 for (i = 1; i < dq->count; i++)
1889 queue_push(&solv->branches, dq->elements[i]);
1890 queue_push(&solv->branches, -level);
1894 p = dq->elements[i];
1896 if (pool->verbose > 3)
1898 Solvable *s = pool->solvables + p;
1899 printf("installing %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
1902 return setpropagatelearn(solv, level, p, disablerules);
1906 /*-----------------------------------------------------------------*/
1907 /* Main solver interface */
1912 * create solver structure
1914 * pool: all available solvables
1915 * installed: installed Solvables
1918 * Upon solving, rules are created to flag the Solvables
1919 * of the 'installed' Repo as installed.
1923 solver_create(Pool *pool, Repo *installed)
1926 solv = (Solver *)xcalloc(1, sizeof(Solver));
1928 solv->installed = installed;
1930 queue_init(&solv->ruletojob);
1931 queue_init(&solv->decisionq);
1932 queue_init(&solv->decisionq_why);
1933 queue_init(&solv->problems);
1934 queue_init(&solv->suggestions);
1935 queue_init(&solv->learnt_why);
1936 queue_init(&solv->learnt_pool);
1937 queue_init(&solv->branches);
1939 map_init(&solv->recommendsmap, pool->nsolvables);
1940 map_init(&solv->suggestsmap, pool->nsolvables);
1941 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
1942 solv->recommends_index = 0;
1944 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
1945 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
1946 memset(solv->rules, 0, sizeof(Rule));
1958 solver_free(Solver *solv)
1960 queue_free(&solv->ruletojob);
1961 queue_free(&solv->decisionq);
1962 queue_free(&solv->decisionq_why);
1963 queue_free(&solv->learnt_why);
1964 queue_free(&solv->learnt_pool);
1965 queue_free(&solv->problems);
1966 queue_free(&solv->suggestions);
1967 queue_free(&solv->branches);
1969 map_free(&solv->recommendsmap);
1970 map_free(&solv->suggestsmap);
1971 map_free(&solv->noupdate);
1972 xfree(solv->decisionmap);
1974 xfree(solv->watches);
1975 xfree(solv->weaksystemrules);
1976 xfree(solv->obsoletes);
1977 xfree(solv->obsoletes_data);
1982 /*-------------------------------------------------------*/
1987 * all rules have been set up, now actually run the solver
1992 run_solver(Solver *solv, int disablerules, int doweak)
2000 Pool *pool = solv->pool;
2003 if (pool->verbose > 3)
2005 printf("number of rules: %d\n", solv->nrules);
2006 for (i = 0; i < solv->nrules; i++)
2007 printrule(solv, solv->rules + i);
2010 /* create watches chains */
2013 if (pool->verbose) printf("initial decisions: %d\n", solv->decisionq.count);
2014 if (pool->verbose > 3)
2015 printdecisions(solv);
2017 /* start SAT algorithm */
2019 systemlevel = level + 1;
2020 if (pool->verbose) printf("solving...\n");
2031 if (pool->verbose) printf("propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2032 if ((r = propagate(solv, level)) != 0)
2034 if (analyze_unsolvable(solv, r, disablerules))
2042 * installed packages
2045 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2047 if (!solv->updatesystem)
2049 /* try to keep as many packages as possible */
2050 if (pool->verbose) printf("installing system packages\n");
2051 for (i = solv->installed->start, n = 0; ; i++)
2053 if (n == solv->installed->nsolvables)
2055 if (i == solv->installed->end)
2056 i = solv->installed->start;
2057 s = pool->solvables + i;
2058 if (s->repo != solv->installed)
2061 if (solv->decisionmap[i] != 0)
2063 if (pool->verbose > 3)
2064 printf("keeping %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2066 level = setpropagatelearn(solv, level, i, disablerules);
2072 if (level <= olevel)
2076 if (solv->weaksystemrules)
2078 if (pool->verbose) printf("installing weak system packages\n");
2079 for (i = solv->installed->start; i < solv->installed->end; i++)
2081 if (pool->solvables[i].repo != solv->installed)
2083 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2085 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2086 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2089 if (solv->weaksystemrules[i - solv->installed->start])
2091 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2092 while ((p = *dp++) != 0)
2094 if (solv->decisionmap[p] > 0)
2096 if (solv->decisionmap[p] == 0)
2100 continue; /* update package already installed */
2102 if (!dq.count && solv->decisionmap[i] != 0)
2105 /* FIXME: i is handled a bit different because we do not want
2106 * to have it pruned just because it is not recommened.
2107 * we should not prune installed packages instead */
2108 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2114 if (level <= olevel)
2117 if (i < solv->installed->end)
2120 systemlevel = level;
2127 if (pool->verbose) printf("deciding unresolved rules\n");
2128 for (i = 1, n = 1; ; i++, n++)
2130 if (n == solv->nrules)
2132 if (i == solv->nrules)
2134 r = solv->rules + i;
2140 /* binary or unary rule */
2141 /* need two positive undecided literals */
2142 if (r->p < 0 || r->w2 <= 0)
2144 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2146 queue_push(&dq, r->p);
2147 queue_push(&dq, r->w2);
2152 * all negative literals are installed
2153 * no positive literal is installed
2154 * i.e. the rule is not fulfilled and we
2155 * just need to decide on the positive literals
2159 if (solv->decisionmap[-r->p] <= 0)
2164 if (solv->decisionmap[r->p] > 0)
2166 if (solv->decisionmap[r->p] == 0)
2167 queue_push(&dq, r->p);
2169 dp = pool->whatprovidesdata + r->d;
2170 while ((p = *dp++) != 0)
2174 if (solv->decisionmap[-p] <= 0)
2179 if (solv->decisionmap[p] > 0)
2181 if (solv->decisionmap[p] == 0)
2190 /* cannot happen as this means that
2191 * the rule is unit */
2195 if (pool->verbose > 2)
2199 level = selectandinstall(solv, level, &dq, 0, disablerules);
2205 if (level < systemlevel)
2208 } /* for(), decide */
2210 if (n != solv->nrules) /* continue if level < systemlevel */
2213 if (doweak && !solv->problems.count)
2217 if (pool->verbose) printf("installing recommended packages\n");
2219 for (i = 1; i < pool->nsolvables; i++)
2221 if (solv->decisionmap[i] < 0)
2223 if (solv->decisionmap[i] > 0)
2225 Id *recp, rec, *pp, p;
2226 s = pool->solvables + i;
2227 /* installed, check for recommends */
2228 /* XXX need to special case AND ? */
2231 recp = s->repo->idarraydata + s->recommends;
2232 while ((rec = *recp++) != 0)
2235 FOR_PROVIDES(p, pp, rec)
2237 if (solv->decisionmap[p] > 0)
2242 else if (solv->decisionmap[p] == 0)
2244 queue_pushunique(&dq, p);
2252 s = pool->solvables + i;
2253 if (!s->supplements && !s->freshens)
2255 if (!pool_installable(pool, s))
2257 if (solver_is_supplementing(solv, s))
2258 queue_pushunique(&dq, i);
2264 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2266 s = pool->solvables + p;
2267 if (pool->verbose > 0)
2268 printf("installing recommended %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2269 level = setpropagatelearn(solv, level, p, 0);
2274 if (solv->solution_callback)
2276 solv->solution_callback(solv, solv->solution_callback_data);
2277 if (solv->branches.count)
2279 int i = solv->branches.count - 1;
2280 int l = -solv->branches.elements[i];
2282 if (solv->branches.elements[i - 1] < 0)
2284 p = solv->branches.elements[i];
2285 if (pool->verbose > 0)
2287 s = pool->solvables + p;
2288 printf("branching with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2291 for (j = i + 1; j < solv->branches.count; j++)
2292 queue_push(&dq, solv->branches.elements[j]);
2293 solv->branches.count = i;
2295 revert(solv, level);
2297 for (j = 0; j < dq.count; j++)
2298 queue_push(&solv->branches, dq.elements[j]);
2300 level = setpropagatelearn(solv, level, p, disablerules);
2308 /* all branches done, we're finally finished */
2312 /* minimization step */
2313 if (solv->branches.count)
2315 int l = 0, lasti = -1, lastl = -1;
2317 for (i = solv->branches.count - 1; i >= 0; i--)
2319 p = solv->branches.elements[i];
2322 else if (p > 0 && solv->decisionmap[p] > l + 1)
2330 /* kill old solvable so that we do not loop */
2331 p = solv->branches.elements[lasti];
2332 solv->branches.elements[lasti] = 0;
2333 s = pool->solvables + p;
2334 if (pool->verbose > 0)
2335 printf("minimizing %d -> %d with %s-%s.%s\n", solv->decisionmap[p], l, id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2338 revert(solv, level);
2340 level = setpropagatelearn(solv, level, p, disablerules);
2357 * at this point, all rules that led to conflicts are disabled.
2358 * we re-enable all rules of a problem set but rule "sug", then
2359 * continue to disable more rules until there as again a solution.
2362 /* FIXME: think about conflicting assertions */
2365 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2367 Pool *pool = solv->pool;
2376 printf("refine_suggestion start\n");
2377 for (i = 0; problem[i]; i++)
2379 if (problem[i] == sug)
2381 printproblem(solv, problem[i]);
2384 queue_init(&disabled);
2385 queue_empty(refined);
2386 queue_push(refined, sug);
2388 /* re-enable all problem rules with the exception of "sug" */
2392 for (i = 0; problem[i]; i++)
2393 if (problem[i] != sug)
2394 enableproblem(solv, problem[i]);
2397 disableupdaterules(solv, job, -(sug + 1));
2401 /* re-enable as many weak rules as possible */
2402 for (i = solv->weakrules; i < solv->learntrules; i++)
2404 r = solv->rules + i;
2406 enablerule(solv, r);
2409 queue_empty(&solv->problems);
2410 revert(solv, 1); /* XXX move to reset_solver? */
2413 run_solver(solv, 0, 0);
2414 if (!solv->problems.count)
2417 printf("no more problems!\n");
2418 if (pool->verbose > 3)
2419 printdecisions(solv);
2420 break; /* great, no more problems */
2422 disabledcnt = disabled.count;
2423 /* skip over proof index */
2424 for (i = 1; i < solv->problems.count - 1; i++)
2426 /* ignore solutions in refined */
2427 v = solv->problems.elements[i];
2429 break; /* end of problem reached */
2430 for (j = 0; problem[j]; j++)
2431 if (problem[j] != sug && problem[j] == v)
2435 queue_push(&disabled, v);
2437 if (disabled.count == disabledcnt)
2439 /* no solution found, this was an invalid suggestion! */
2441 printf("no solution found!\n");
2445 if (disabled.count == disabledcnt + 1)
2447 /* just one suggestion, add it to refined list */
2448 v = disabled.elements[disabledcnt];
2449 queue_push(refined, v);
2450 disableproblem(solv, v);
2452 disableupdaterules(solv, job, -(v + 1));
2456 /* more than one solution, disable all */
2457 /* do not push anything on refine list */
2458 if (pool->verbose > 1)
2460 printf("more than one solution found:\n");
2461 for (i = disabledcnt; i < disabled.count; i++)
2462 printproblem(solv, disabled.elements[i]);
2464 for (i = disabledcnt; i < disabled.count; i++)
2465 disableproblem(solv, disabled.elements[i]);
2468 /* all done, get us back into the same state as before */
2469 /* enable refined rules again */
2470 for (i = 0; i < disabled.count; i++)
2471 enableproblem(solv, disabled.elements[i]);
2472 /* disable problem rules again */
2473 for (i = 0; problem[i]; i++)
2474 disableproblem(solv, problem[i]);
2476 printf("refine_suggestion end\n");
2480 problems_to_solutions(Solver *solv, Queue *job)
2482 Pool *pool = solv->pool;
2490 if (!solv->problems.count)
2492 queue_clone(&problems, &solv->problems);
2493 queue_init(&solution);
2494 queue_init(&solutions);
2495 /* copy over proof index */
2496 queue_push(&solutions, problems.elements[0]);
2497 problem = problems.elements + 1;
2498 for (i = 1; i < problems.count; i++)
2500 Id v = problems.elements[i];
2503 /* mark end of this problem */
2504 queue_push(&solutions, 0);
2505 queue_push(&solutions, 0);
2506 if (i + 1 == problems.count)
2508 /* copy over proof of next problem */
2509 queue_push(&solutions, problems.elements[i + 1]);
2511 problem = problems.elements + i + 1;
2514 refine_suggestion(solv, job, problem, v, &solution);
2515 if (!solution.count)
2516 continue; /* this solution didn't work out */
2518 for (j = 0; j < solution.count; j++)
2520 why = solution.elements[j];
2522 printproblem(solv, why);
2526 queue_push(&solutions, 0);
2527 queue_push(&solutions, -why);
2529 else if (why >= solv->systemrules && why < solv->weakrules)
2532 p = solv->installed->start + (why - solv->systemrules);
2533 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2535 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2538 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2540 if (solv->decisionmap[*dp] > 0)
2547 queue_push(&solutions, p);
2548 queue_push(&solutions, rp);
2553 /* mark end of this solution */
2554 queue_push(&solutions, 0);
2555 queue_push(&solutions, 0);
2557 queue_free(&solution);
2558 queue_free(&problems);
2559 /* copy queue over to solutions */
2560 queue_free(&solv->problems);
2561 queue_clone(&solv->problems, &solutions);
2562 queue_free(&solutions);
2573 printdecisions(Solver *solv)
2575 Pool *pool = solv->pool;
2576 Repo *installed = solv->installed;
2577 Id p, *obsoletesmap;
2581 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2584 for (i = 0; i < solv->decisionq.count; i++)
2588 n = solv->decisionq.elements[i];
2591 if (n == SYSTEMSOLVABLE)
2593 s = pool->solvables + n;
2594 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2596 FOR_PROVIDES(p, pp, s->name)
2597 if (s->name == pool->solvables[p].name)
2599 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2601 obsoletesmap[p] = n;
2606 for (i = 0; i < solv->decisionq.count; i++)
2611 n = solv->decisionq.elements[i];
2614 if (n == SYSTEMSOLVABLE)
2616 s = pool->solvables + n;
2617 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2621 obsp = s->repo->idarraydata + s->obsoletes;
2622 while ((obs = *obsp++) != 0)
2623 FOR_PROVIDES(p, pp, obs)
2625 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2627 obsoletesmap[p] = n;
2634 /* print solvables to be erased */
2638 for (i = installed->start; i < installed->end; i++)
2640 s = pool->solvables + i;
2641 if (s->repo != installed)
2643 if (solv->decisionmap[i] >= 0)
2645 if (obsoletesmap[i])
2647 printf("erase %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2651 /* print solvables to be installed */
2653 for (i = 0; i < solv->decisionq.count; i++)
2656 p = solv->decisionq.elements[i];
2659 if (p == SYSTEMSOLVABLE)
2661 s = pool->solvables + p;
2662 if (installed && s->repo == installed)
2665 if (!obsoletesmap[p])
2667 printf("install %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2671 printf("update %s-%s.%s (obsoletes", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2672 for (j = installed->start; j < installed->end; j++)
2674 if (obsoletesmap[j] != p)
2676 s = pool->solvables + j;
2677 printf(" %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2684 xfree(obsoletesmap);
2686 if (solv->suggestions.count)
2688 printf("\nsuggested packages:\n");
2689 for (i = 0; i < solv->suggestions.count; i++)
2691 s = pool->solvables + solv->suggestions.elements[i];
2692 printf("- %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2698 printconflicts(Solver *solv, Solvable *s, Id pc)
2700 Pool *pool = solv->pool;
2701 Solvable *sc = pool->solvables + pc;
2702 Id p, *pp, con, *conp, obs, *obsp;
2707 conp = s->repo->idarraydata + s->conflicts;
2708 while ((con = *conp++) != 0)
2710 FOR_PROVIDES(p, pp, con)
2714 printf("packags %s-%s.%s conflicts with %s, which is provided by %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, con), id2str(pool, sc->name), id2str(pool, sc->evr), id2str(pool, sc->arch));
2719 if (s->obsoletes && (!solv->installed || s->repo != solv->installed))
2721 obsp = s->repo->idarraydata + s->obsoletes;
2722 while ((obs = *obsp++) != 0)
2724 FOR_PROVIDES(p, pp, obs)
2728 printf("packags %s-%s.%s obsolets %s, which is provided by %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, obs), id2str(pool, sc->name), id2str(pool, sc->evr), id2str(pool, sc->arch));
2737 printprobleminfo(Solver *solv, Queue *job, Id idx)
2739 Pool *pool = solv->pool;
2744 rn = solv->learnt_pool.elements[idx];
2747 p = rn; /* fake a negative assertion rule */
2752 r = solv->rules + rn;
2756 if (!r || r->w2 == 0)
2762 if (p == -SYSTEMSOLVABLE)
2766 /* we tried to deinstall the system solvable. must be a job. */
2767 if (rn < solv->jobrules || rn >= solv->systemrules)
2769 ji = solv->ruletojob.elements[rn - solv->jobrules];
2770 what = job->elements[ji + 1];
2771 switch (job->elements[ji])
2773 case SOLVER_INSTALL_SOLVABLE_NAME:
2774 printf("no solvable exists with name %s\n", dep2str(pool, what));
2776 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2777 printf("no solvable provides %s\n", dep2str(pool, what));
2780 printf("unknown job\n");
2785 if (rn >= solv->jobrules)
2792 /* negative assertion, i.e. package is not installable */
2793 s = pool->solvables + (-p);
2796 reqp = s->repo->idarraydata + s->requires;
2797 while ((req = *reqp++) != 0)
2799 if (req == SOLVABLE_PREREQMARKER)
2801 dp = GET_PROVIDESP(req, p);
2804 printf("package %s-%s.%s requires %s, but no package provides it\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
2809 printf("package %s-%s.%s is not installable\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2813 if (rn >= solv->learntrules)
2815 /* learnt rule, ignore for now */
2816 printf("some learnt rule...\n");
2820 if (rn >= solv->systemrules)
2822 /* system rule, ignore for now */
2823 printf("some system rule...\n");
2827 if (rn >= solv->jobrules)
2829 /* job rule, ignore for now */
2830 printf("some job rule...\n");
2834 /* only rpm rules left... */
2839 if (d == 0 && r->w2 < 0)
2843 sp = pool->solvables + (-p);
2844 sd = pool->solvables + (-d);
2845 if (sp->name == sd->name)
2847 printf("cannot install both %s-%s.%s and %s-%s.%s\n", id2str(pool, sp->name), id2str(pool, sp->evr), id2str(pool, sp->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2851 printconflicts(solv, pool->solvables + (-p), -d);
2852 printconflicts(solv, pool->solvables + (-d), -p);
2857 /* find requires of p that corresponds with our rule */
2859 s = pool->solvables + (-p);
2860 reqp = s->repo->idarraydata + s->requires;
2861 while ((req = *reqp++) != 0)
2863 if (req == SOLVABLE_PREREQMARKER)
2865 dp = GET_PROVIDESP(req, p);
2868 if (*dp == r->w2 && dp[1] == 0)
2871 else if (dp - pool->whatprovidesdata == d)
2876 printf("req not found\n");
2879 printf("package %s-%s.%s requires %s, but none of its providers can be installed\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), dep2str(pool, req));
2884 printsolutions(Solver *solv, Queue *job)
2886 Pool *pool = solv->pool;
2892 printf("Encountered problems! Here are the solutions:\n\n");
2894 for (i = 0; i < solv->problems.count; )
2896 printf("Problem %d:\n", pcnt++);
2897 printf("====================================\n");
2898 printprobleminfo(solv, job, solv->problems.elements[i++]);
2902 if (solv->problems.elements[i] == 0 && solv->problems.elements[i + 1] == 0)
2904 /* end of solutions for this problems reached */
2910 p = solv->problems.elements[i];
2911 rp = solv->problems.elements[i + 1];
2913 if (p == 0 && rp == 0)
2915 /* end of this solution reached */
2921 /* job, p is index into job queue */
2922 what = job->elements[rp];
2923 switch (job->elements[rp - 1])
2925 case SOLVER_INSTALL_SOLVABLE:
2926 s = pool->solvables + what;
2927 if (solv->installed && s->repo == solv->installed)
2928 printf("- do not keep %s-%s.%s installed\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2930 printf("- do not install %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2932 case SOLVER_ERASE_SOLVABLE:
2933 s = pool->solvables + what;
2934 if (solv->installed && s->repo == solv->installed)
2935 printf("- do not deinstall %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2937 printf("- do not forbid installation of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
2939 case SOLVER_INSTALL_SOLVABLE_NAME:
2940 printf("- do not install %s\n", id2str(pool, what));
2942 case SOLVER_ERASE_SOLVABLE_NAME:
2943 printf("- do not deinstall %s\n", id2str(pool, what));
2945 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2946 printf("- do not install a solvable providing %s\n", dep2str(pool, what));
2948 case SOLVER_ERASE_SOLVABLE_PROVIDES:
2949 printf("- do not deinstall all solvables providing %s\n", dep2str(pool, what));
2951 case SOLVER_INSTALL_SOLVABLE_UPDATE:
2952 s = pool->solvables + what;
2953 printf("- do not install most recent version of %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool
2957 printf("- do something different\n");
2963 /* policy, replace p with rp */
2964 s = pool->solvables + p;
2965 sd = rp ? pool->solvables + rp : 0;
2969 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr) > 0)
2971 printf("- allow downgrade of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2974 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
2976 printf("- allow architecture change of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2979 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
2982 printf("- allow vendor change from '%s' (%s-%s.%s) to '%s' (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->vendor), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2984 printf("- allow vendor change from '%s' (%s-%s.%s) to no vendor (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2988 printf("- allow replacement of %s-%s.%s with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
2992 printf("- allow deinstallation of %s-%s.%s [%d]\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), (Id)(s - pool->solvables));
3002 /* for each installed solvable find which packages with *different* names
3003 * obsolete the solvable.
3004 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3008 create_obsolete_index(Solver *solv)
3010 Pool *pool = solv->pool;
3012 Repo *installed = solv->installed;
3013 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3016 if (!installed || !installed->nsolvables)
3018 /* create reverse obsoletes map for installed solvables */
3019 solv->obsoletes = obsoletes = xcalloc(installed->end - installed->start, sizeof(Id));
3020 for (i = 1; i < pool->nsolvables; i++)
3022 s = pool->solvables + i;
3023 if (s->repo == installed)
3027 if (!pool_installable(pool, s))
3029 obsp = s->repo->idarraydata + s->obsoletes;
3030 while ((obs = *obsp++) != 0)
3031 FOR_PROVIDES(p, pp, obs)
3033 if (pool->solvables[p].repo != installed)
3035 if (pool->solvables[p].name == s->name)
3037 obsoletes[p - installed->start]++;
3041 for (i = 0; i < installed->nsolvables; i++)
3044 n += obsoletes[i] + 1;
3047 solv->obsoletes_data = obsoletes_data = xcalloc(n + 1, sizeof(Id));
3048 if (pool->verbose) printf("obsoletes data: %d entries\n", n + 1);
3049 for (i = pool->nsolvables - 1; i > 0; i--)
3051 s = pool->solvables + i;
3052 if (s->repo == installed)
3056 if (!pool_installable(pool, s))
3058 obsp = s->repo->idarraydata + s->obsoletes;
3059 while ((obs = *obsp++) != 0)
3060 FOR_PROVIDES(p, pp, obs)
3062 if (pool->solvables[p].repo != installed)
3064 if (pool->solvables[p].name == s->name)
3066 p -= installed->start;
3067 if (obsoletes_data[obsoletes[p]] != i)
3068 obsoletes_data[--obsoletes[p]] = i;
3074 /*-----------------------------------------------------------------*/
3084 solve(Solver *solv, Queue *job)
3086 Pool *pool = solv->pool;
3087 Repo *installed = solv->installed;
3090 Map addedmap; /* '1' == have rule for solvable */
3091 Id how, what, p, *pp, d;
3095 /* create obsolete index if needed */
3096 if (solv->noupdateprovide)
3097 create_obsolete_index(solv);
3100 * create basic rule set of all involved packages
3101 * use addedmap bitmap to make sure we don't create rules twice
3105 map_init(&addedmap, pool->nsolvables);
3109 * always install our system solvable
3111 MAPSET(&addedmap, SYSTEMSOLVABLE);
3112 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3113 queue_push(&solv->decisionq_why, 0);
3114 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3117 * create rules for all package that could be involved with the solving
3118 * so called: rpm rules
3123 oldnrules = solv->nrules;
3124 if (pool->verbose > 3)
3125 printf ("*** create rpm rules for installed solvables ***\n");
3126 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3127 if (s->repo == installed)
3128 addrpmrulesforsolvable(solv, s, &addedmap);
3130 printf("added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3131 if (pool->verbose > 3)
3132 printf ("*** create rpm rules for updaters of installed solvables ***\n");
3133 oldnrules = solv->nrules;
3134 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3135 if (s->repo == installed)
3136 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3138 printf("added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3141 if (solv->pool->verbose > 3)
3142 printf ("*** create rpm rules for packages involved with a job ***\n");
3143 oldnrules = solv->nrules;
3144 for (i = 0; i < job->count; i += 2)
3146 how = job->elements[i];
3147 what = job->elements[i + 1];
3151 case SOLVER_INSTALL_SOLVABLE:
3152 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3154 case SOLVER_INSTALL_SOLVABLE_NAME:
3155 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3156 FOR_PROVIDES(p, pp, what)
3158 /* if by name, ensure that the name matches */
3159 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3161 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3164 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3165 /* dont allow downgrade */
3166 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3171 printf("added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3173 if (solv->pool->verbose > 3)
3174 printf ("*** create rpm rules for recommended/suggested packages ***\n");
3176 oldnrules = solv->nrules;
3177 addrpmrulesforweak(solv, &addedmap);
3179 printf("added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3184 int possible = 0, installable = 0;
3185 for (i = 1; i < pool->nsolvables; i++)
3187 if (pool_installable(pool, pool->solvables + i))
3189 if (MAPTST(&addedmap, i))
3192 printf("%d of %d installable solvables considered for solving\n", possible, installable);
3197 * first pass done, we now have all the rpm rules we need.
3198 * unify existing rules before going over all job rules and
3200 * at this point the system is always solvable,
3201 * as an empty system (remove all packages) is a valid solution
3204 unifyrules(solv); /* remove duplicate rpm rules */
3206 if (pool->verbose) printf("decisions so far: %d\n", solv->decisionq.count);
3207 if (pool->verbose > 3)
3208 printdecisions (solv);
3211 * now add all job rules
3214 if (solv->pool->verbose > 3)
3215 printf ("*** Add JOB rules ***\n");
3217 solv->jobrules = solv->nrules;
3219 for (i = 0; i < job->count; i += 2)
3221 how = job->elements[i];
3222 what = job->elements[i + 1];
3225 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3226 s = pool->solvables + what;
3228 printf("job: install solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3229 addrule(solv, what, 0); /* install by Id */
3230 queue_push(&solv->ruletojob, i);
3232 case SOLVER_ERASE_SOLVABLE:
3233 s = pool->solvables + what;
3235 printf("job: erase solvable %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3236 addrule(solv, -what, 0); /* remove by Id */
3237 queue_push(&solv->ruletojob, i);
3239 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3240 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3241 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_NAME)
3242 printf("job: install name %s\n", id2str(pool, what));
3243 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3244 printf("job: install provides %s\n", dep2str(pool, what));
3246 FOR_PROVIDES(p, pp, what)
3248 /* if by name, ensure that the name matches */
3249 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3255 /* no provider, make this an impossible rule */
3256 queue_push(&q, -SYSTEMSOLVABLE);
3259 p = queue_shift(&q); /* get first provider */
3261 d = 0; /* single provider ? -> make assertion */
3263 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3264 addrule(solv, p, d); /* add 'requires' rule */
3265 queue_push(&solv->ruletojob, i);
3267 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3268 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3269 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_NAME)
3270 printf("job: erase name %s\n", id2str(pool, what));
3271 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3272 printf("job: erase provides %s\n", dep2str(pool, what));
3273 FOR_PROVIDES(p, pp, what)
3275 /* if by name, ensure that the name matches */
3276 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3278 addrule(solv, -p, 0); /* add 'remove' rule */
3279 queue_push(&solv->ruletojob, i);
3282 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3283 s = pool->solvables + what;
3285 printf("job: update %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
3286 addupdaterule(solv, s, 0);
3287 queue_push(&solv->ruletojob, i);
3292 if (solv->ruletojob.count != solv->nrules - solv->jobrules)
3296 * now add system rules
3300 if (solv->pool->verbose > 3)
3301 printf ("*** Add system rules ***\n");
3304 solv->systemrules = solv->nrules;
3307 * create rules for updating installed solvables
3311 if (installed && !solv->allowuninstall)
3312 { /* loop over all installed solvables */
3313 /* we create all update rules, but disable some later on depending on the job */
3314 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3315 if (s->repo == installed)
3316 addupdaterule(solv, s, 0); /* allowall = 0 */
3318 addupdaterule(solv, 0, 0); /* create dummy rule; allowall = 0 */
3319 /* consistency check: we added a rule for _every_ system solvable */
3320 if (solv->nrules - solv->systemrules != installed->end - installed->start)
3324 /* create special weak system rules */
3325 /* those are used later on to keep a version of the installed packages in
3327 if (installed && installed->nsolvables)
3329 solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id));
3330 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3331 if (s->repo == installed)
3333 policy_findupdatepackages(solv, s, &q, 1);
3335 solv->weaksystemrules[i - installed->start] = pool_queuetowhatprovides(pool, &q);
3339 /* free unneeded memory */
3340 map_free(&addedmap);
3343 solv->weakrules = solv->nrules;
3345 /* try real hard to keep packages installed */
3348 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3349 if (s->repo == installed)
3351 /* FIXME: can't work with refine_suggestion! */
3352 /* need to always add the rule but disable it */
3353 if (MAPTST(&solv->noupdate, i - installed->start))
3355 d = solv->weaksystemrules[i - installed->start];
3356 addrule(solv, i, d);
3360 /* all new rules are learnt after this point */
3361 solv->learntrules = solv->nrules;
3368 disableupdaterules(solv, job, -1);
3369 makeruledecisions(solv);
3371 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
3373 run_solver(solv, 1, 1);
3375 /* find suggested packages */
3376 if (!solv->problems.count)
3378 Id sug, *sugp, p, *pp;
3380 /* create map of all suggests that are still open */
3381 solv->recommends_index = -1;
3382 MAPZERO(&solv->suggestsmap);
3383 for (i = 0; i < solv->decisionq.count; i++)
3385 p = solv->decisionq.elements[i];
3388 s = pool->solvables + p;
3391 sugp = s->repo->idarraydata + s->suggests;
3392 while ((sug = *sugp++) != 0)
3394 FOR_PROVIDES(p, pp, sug)
3395 if (solv->decisionmap[p] > 0)
3398 continue; /* already fulfilled */
3399 FOR_PROVIDES(p, pp, sug)
3400 MAPSET(&solv->suggestsmap, p);
3404 for (i = 1; i < pool->nsolvables; i++)
3406 if (solv->decisionmap[i] != 0)
3408 s = pool->solvables + i;
3409 if (!MAPTST(&solv->suggestsmap, i))
3413 if (!pool_installable(pool, s))
3415 if (!solver_is_enhancing(solv, s))
3418 queue_push(&solv->suggestions, i);
3420 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3423 if (solv->problems.count)
3424 problems_to_solutions(solv, job);