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 [%d]", solvable2str(pool, s), -v);
105 s = pool->solvables + v;
106 printf(" %s [%d]", solvable2str(pool, s), 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]);
128 printrule(Solver *solv, Rule *r)
133 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
134 printf("Rule #%d:", (int)(r - solv->rules));
136 printf("Rule:"); /* r is any rule */
138 printf(" (disabled)");
144 else if (r->d == ID_NULL)
151 v = solv->pool->whatprovidesdata[r->d + i - 1];
154 printruleelement(solv, r, v);
156 printf(" next: %d %d\n", r->n1, r->n2);
160 printruleclass(Solver *solv, Rule *r)
162 if (r - solv->rules >= solv->learntrules)
164 else if (r - solv->rules >= solv->weakrules)
166 else if (r - solv->rules >= solv->systemrules)
168 else if (r - solv->rules >= solv->jobrules)
174 /*-----------------------------------------------------------------*/
180 static Pool *unifyrules_sortcmp_data;
183 * compare rules for unification sort
187 unifyrules_sortcmp(const void *ap, const void *bp)
189 Pool *pool = unifyrules_sortcmp_data;
190 Rule *a = (Rule *)ap;
191 Rule *b = (Rule *)bp;
197 return x; /* p differs */
200 if (a->d == 0 && b->d == 0)
201 return a->w2 - b->w2; /* assertion: return w2 diff */
203 if (a->d == 0) /* a is assertion, b not */
205 x = a->w2 - pool->whatprovidesdata[b->d];
209 if (b->d == 0) /* b is assertion, a not */
211 x = pool->whatprovidesdata[a->d] - b->w2;
215 /* compare whatprovidesdata */
216 ad = pool->whatprovidesdata + a->d;
217 bd = pool->whatprovidesdata + b->d;
219 if ((x = *ad++ - *bd++) != 0)
230 unifyrules(Solver *solv)
235 if (solv->nrules <= 1) /* nothing to unify */
238 if (solv->pool->verbose > 3)
239 printf ("----- unifyrules -----\n");
241 /* sort rules first */
242 unifyrules_sortcmp_data = solv->pool;
243 qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
250 for (i = j = 1, ir = solv->rules + 1; i < solv->nrules; i++, ir++)
252 if (jr && !unifyrules_sortcmp(ir, jr))
253 continue; /* prune! */
254 jr = solv->rules + j++; /* keep! */
259 /* reduced count from nrules to j rules */
260 if (solv->pool->verbose) printf("pruned rules from %d to %d\n", solv->nrules, j);
262 /* adapt rule buffer */
264 solv->rules = (Rule *)xrealloc(solv->rules, ((solv->nrules + RULES_BLOCK) & ~RULES_BLOCK) * sizeof(Rule));
266 if (solv->pool->verbose)
273 for (i = 1; i < solv->nrules; i++)
280 dp = solv->pool->whatprovidesdata + r->d;
285 printf(" binary: %d\n", binr);
286 printf(" normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
289 if (solv->pool->verbose > 3)
290 printf ("----- unifyrules end -----\n");
300 hashrule(Solver *solv, Id p, Id d, int n)
302 unsigned int x = (unsigned int)p;
306 return (x * 37) ^ (unsigned int)d;
307 dp = solv->pool->whatprovidesdata + d;
309 x = (x * 37) ^ (unsigned int)*dp++;
317 * p = direct literal; always < 0 for installed rpm rules
318 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
321 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
323 * p < 0 : pkg id of A
324 * d > 0 : Offset in whatprovidesdata (list of providers of b)
326 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
327 * p < 0 : pkg id of A
328 * d < 0 : Id of solvable (e.g. B1)
330 * d == 0: unary rule, assertion => (A) or (-A)
332 * Install: p > 0, d = 0 (A) user requested install
333 * Remove: p < 0, d = 0 (-A) user requested remove
334 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
335 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
336 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
337 * ? p > 0, d < 0 (A|-B)
338 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
342 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
343 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
344 * every other : w1 = p, w2 = whatprovidesdata[d];
345 * Disabled rule: w1 = 0
347 * always returns a rule for non-rpm rules
351 addrule(Solver *solv, Id p, Id d)
356 int n = 0; /* number of literals in rule - 1
357 0 = direct assertion (single literal)
361 /* it often happenes that requires lead to adding the same rpm rule
362 * multiple times, so we prune those duplicates right away to make
363 * the work for unifyrules a bit easier */
365 if (solv->nrules && !solv->jobrules)
367 r = solv->rules + solv->nrules - 1; /* get the last added rule */
368 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
374 /* always a binary rule */
376 return 0; /* ignore self conflict */
381 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, n++)
383 return 0; /* rule is self-fulfilling */
388 if (n == 0 && !solv->jobrules)
390 /* this is a rpm rule assertion, we do not have to allocate it */
391 /* it can be identified by a level of 1 and a zero reason */
392 /* we must not drop those rules from the decisionq when rewinding! */
395 if (solv->decisionmap[-p] > 0 || solv->decisionmap[-p] < -1)
397 if (solv->decisionmap[-p])
398 return 0; /* already got that one */
399 queue_push(&solv->decisionq, p);
400 queue_push(&solv->decisionq_why, 0);
401 solv->decisionmap[-p] = -1;
406 /* smallest literal first so we can find dups */
410 n = 1; /* re-set n, was used as temp var */
413 /* check if the last added rule is exactly the same as what we're looking for. */
414 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
417 if (r && n > 1 && r->d && r->p == p)
422 dp2 = solv->pool->whatprovidesdata + r->d;
423 for (dp = solv->pool->whatprovidesdata + d; *dp; dp++, dp2++)
434 /* check and extend rule buffer */
435 if ((solv->nrules & RULES_BLOCK) == 0)
437 solv->rules = (Rule *)xrealloc(solv->rules, (solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
440 r = solv->rules + solv->nrules++; /* point to rule space */
445 /* direct assertion, no watch needed */
461 r->w2 = solv->pool->whatprovidesdata[d];
466 if (solv->pool->verbose > 3)
468 printf (" Add rule: ");
476 disablerule(Solver *solv, Rule *r)
482 enablerule(Solver *solv, Rule *r)
484 if (r->d == 0 || r->w2 != r->p)
487 r->w1 = solv->pool->whatprovidesdata[r->d];
491 /**********************************************************************************/
493 /* a problem is an item on the solver's problem list. It can either be >0, in that
494 * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
495 * consisting of multiple job rules.
499 disableproblem(Solver *solv, Id v)
507 disablerule(solv, solv->rules + v);
511 jp = solv->ruletojob.elements;
512 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
514 disablerule(solv, r);
518 enableproblem(Solver *solv, Id v)
526 enablerule(solv, solv->rules + v);
530 jp = solv->ruletojob.elements;
531 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
537 printproblem(Solver *solv, Id v)
544 printrule(solv, solv->rules + v);
548 printf("JOB %d\n", v);
549 jp = solv->ruletojob.elements;
550 for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
562 /************************************************************************/
564 /* go through system and job rules and add direct assertions
565 * to the decisionqueue. If we find a conflict, disable rules and
566 * add them to problem queue.
567 * (disablerules is always true for the cases when we get called)
570 makeruledecisions(Solver *solv)
577 if (solv->pool->verbose > 3)
578 printf ("----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
580 decisionstart = solv->decisionq.count;
581 /* rpm rules don't have assertions, so we can start with the job
583 for (ri = solv->jobrules, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
585 if (!r->w1 || r->w2) /* disabled or no assertion */
589 if (solv->decisionmap[vv] == 0)
591 queue_push(&solv->decisionq, v);
592 queue_push(&solv->decisionq_why, r - solv->rules);
593 solv->decisionmap[vv] = v > 0 ? 1 : -1;
594 if (solv->pool->verbose > 3)
596 Solvable *s = solv->pool->solvables + vv;
598 printf("removing %s\n", solvable2str(solv->pool, s));
600 printf("installing %s\n", solvable2str(solv->pool, s));
604 if (v > 0 && solv->decisionmap[vv] > 0)
606 if (v < 0 && solv->decisionmap[vv] < 0)
608 /* found a conflict! */
609 if (ri >= solv->learntrules)
611 /* cannot happen, as this would mean that the problem
612 * was not solvable, so we wouldn't have created the
613 * learnt rule at all */
616 /* if we are weak, just disable ourself */
617 if (ri >= solv->weakrules)
619 printf("conflict, but I am weak, disabling ");
621 disablerule(solv, r);
625 /* only job and system rules left */
626 for (i = 0; i < solv->decisionq.count; i++)
627 if (solv->decisionq.elements[i] == -v)
629 if (i == solv->decisionq.count)
631 if (solv->decisionq_why.elements[i] == 0)
633 /* conflict with rpm rule, need only disable our rule */
634 if (v < 0 && v != -SYSTEMSOLVABLE)
637 queue_push(&solv->problems, solv->learnt_pool.count);
638 queue_push(&solv->learnt_pool, ri);
639 queue_push(&solv->learnt_pool, v != -SYSTEMSOLVABLE ? -v : v);
640 queue_push(&solv->learnt_pool, 0);
641 printf("conflict with rpm rule, disabling rule #%d\n", ri);
642 if (ri < solv->systemrules)
643 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
646 queue_push(&solv->problems, v);
647 disableproblem(solv, v);
648 queue_push(&solv->problems, 0);
652 queue_push(&solv->problems, solv->learnt_pool.count);
653 queue_push(&solv->learnt_pool, ri);
654 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
655 queue_push(&solv->learnt_pool, 0);
657 /* conflict with another job or system rule */
658 printf("conflicting system/job rules over literal %d\n", vv);
659 /* push all of our rules asserting this literal on the problem stack */
660 for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
662 if (!rr->w1 || rr->w2)
664 if (rr->p != vv && rr->p != -vv)
666 printf(" - disabling rule #%d\n", i);
668 if (i < solv->systemrules)
669 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
670 queue_push(&solv->problems, v);
671 disableproblem(solv, v);
673 queue_push(&solv->problems, 0);
676 while (solv->decisionq.count > decisionstart)
678 v = solv->decisionq.elements[--solv->decisionq.count];
679 --solv->decisionq_why.count;
681 solv->decisionmap[vv] = 0;
683 ri = solv->jobrules - 1;
684 r = solv->rules + ri;
687 if (solv->pool->verbose > 3)
688 printf ("----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
692 * we have enabled or disabled some of our rules. We now reenable all
693 * of our learnt rules but the ones that were learnt from rules that
697 enabledisablelearntrules(Solver *solv)
699 Pool *pool = solv->pool;
705 printf("enabledisablelearntrules called\n");
706 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
708 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
709 while ((why = *whyp++) != 0)
711 if (why < 0 || why >= i)
712 abort(); /* cannot reference newer learnt rules */
713 if (!solv->rules[why].w1)
716 /* why != 0: we found a disabled rule, disable the learnt rule */
721 printf("disabling learnt ");
724 disablerule(solv, r);
726 else if (!why && !r->w1)
730 printf("re-enabling learnt ");
739 /* FIXME: bad code ahead, replace as soon as possible */
741 disableupdaterules(Solver *solv, Queue *job, int jobidx)
743 Pool *pool = solv->pool;
745 Id how, what, p, *pp;
751 installed = solv->installed;
757 how = job->elements[jobidx];
760 case SOLVER_INSTALL_SOLVABLE:
761 case SOLVER_ERASE_SOLVABLE:
762 case SOLVER_ERASE_SOLVABLE_NAME:
763 case SOLVER_ERASE_SOLVABLE_PROVIDES:
769 /* go through all enabled job rules */
770 MAPZERO(&solv->noupdate);
771 for (i = solv->jobrules; i < solv->systemrules; i++)
774 if (!r->w1) /* disabled? */
776 j = solv->ruletojob.elements[i - solv->jobrules];
780 how = job->elements[j];
781 what = job->elements[j + 1];
784 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
785 s = pool->solvables + what;
786 FOR_PROVIDES(p, pp, s->name)
788 if (pool->solvables[p].name != s->name)
790 if (pool->solvables[p].repo == installed)
791 MAPSET(&solv->noupdate, p - installed->start);
794 case SOLVER_ERASE_SOLVABLE:
795 s = pool->solvables + what;
796 if (s->repo == installed)
797 MAPSET(&solv->noupdate, what - installed->start);
799 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
800 case SOLVER_ERASE_SOLVABLE_PROVIDES:
801 FOR_PROVIDES(p, pp, what)
803 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
805 if (pool->solvables[p].repo == installed)
806 MAPSET(&solv->noupdate, p - installed->start);
814 /* fixup update rule status */
815 if (solv->allowuninstall)
816 return; /* no update rules at all */
820 /* we just disabled job #jobidx. enable all update rules
821 * that aren't disabled by the remaining job rules */
822 how = job->elements[jobidx];
823 what = job->elements[jobidx + 1];
826 case SOLVER_INSTALL_SOLVABLE:
827 s = pool->solvables + what;
828 FOR_PROVIDES(p, pp, s->name)
830 if (pool->solvables[p].name != s->name)
832 if (pool->solvables[p].repo != installed)
834 if (MAPTST(&solv->noupdate, p - installed->start))
836 r = solv->rules + solv->systemrules + (p - installed->start);
842 printf("@@@ re-enabling ");
847 case SOLVER_ERASE_SOLVABLE:
848 s = pool->solvables + what;
849 if (s->repo != installed)
851 if (MAPTST(&solv->noupdate, what - installed->start))
853 r = solv->rules + solv->systemrules + (what - installed->start);
859 printf("@@@ re-enabling ");
863 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
864 case SOLVER_ERASE_SOLVABLE_PROVIDES:
865 FOR_PROVIDES(p, pp, what)
867 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
869 if (pool->solvables[p].repo != installed)
871 if (MAPTST(&solv->noupdate, p - installed->start))
873 r = solv->rules + solv->systemrules + (p - installed->start);
879 printf("@@@ re-enabling ");
890 for (i = 0; i < installed->nsolvables; i++)
892 r = solv->rules + solv->systemrules + i;
893 if (r->w1 && MAPTST(&solv->noupdate, i))
894 disablerule(solv, r); /* was enabled, need to disable */
900 * add (install) rules for solvable
901 * for unfulfilled requirements, conflicts, obsoletes,....
902 * add a negative assertion for solvables that are not installable
906 addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
908 Pool *pool = solv->pool;
909 Repo *installed = solv->installed;
923 if (solv->pool->verbose > 3)
924 printf ("----- addrpmrulesforsolvable -----\n");
926 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
927 queue_push(&q, s - pool->solvables); /* push solvable Id */
933 * s: Pointer to solvable
937 if (MAPTST(m, n)) /* continue if already done */
941 s = pool->solvables + n; /* s = Solvable in question */
944 if (installed /* Installed system available */
945 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
946 && s->repo == installed) /* solvable is installed? */
948 dontfix = 1; /* dont care about broken rpm deps */
951 if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
954 printf("package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
955 addrule(solv, -n, 0); /* uninstallable */
958 /*-----------------------------------------
959 * check requires of s
964 reqp = s->repo->idarraydata + s->requires;
965 while ((req = *reqp++) != 0) /* go throw all requires */
967 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
970 dp = pool_whatprovides(pool, req);
972 if (*dp == SYSTEMSOLVABLE) /* always installed */
977 /* the strategy here is to not insist on dependencies
978 * that are already broken. so if we find one provider
979 * that was already installed, we know that the
980 * dependency was not broken before so we enforce it */
981 for (i = 0; (p = dp[i]) != 0; i++) /* for all providers */
983 if (pool->solvables[p].repo == installed)
984 break; /* provider was installed */
986 if (!p) /* previously broken dependency */
989 printf("ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
996 /* nothing provides req! */
998 printf("package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
999 addrule(solv, -n, 0); /* mark requestor as uninstallable */
1003 if (pool->verbose > 2)
1005 printf(" %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
1006 for (i = 0; dp[i]; i++)
1007 printf(" provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
1010 /* add 'requires' dependency */
1011 /* rule: (-requestor|provider1|provider2|...|providerN) */
1012 addrule(solv, -n, dp - pool->whatprovidesdata);
1014 /* descend the dependency tree */
1015 for (; *dp; dp++) /* loop through all providers */
1017 if (!MAPTST(m, *dp))
1018 queue_push(&q, *dp);
1021 } /* while, requirements of n */
1023 } /* if, requirements */
1025 /* that's all we check for src packages */
1026 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1029 /*-----------------------------------------
1030 * check conflicts of s
1035 conp = s->repo->idarraydata + s->conflicts;
1036 while ((con = *conp++) != 0)
1038 FOR_PROVIDES(p, pp, con)
1040 /* dontfix: dont care about conflicts with already installed packs */
1041 if (dontfix && pool->solvables[p].repo == installed)
1043 /* rule: -n|-p: either solvable _or_ provider of conflict */
1044 addrule(solv, -n, -p);
1049 /*-----------------------------------------
1050 * check obsoletes if not installed
1052 if (!installed || pool->solvables[n].repo != installed)
1053 { /* not installed */
1056 obsp = s->repo->idarraydata + s->obsoletes;
1057 while ((obs = *obsp++) != 0)
1059 FOR_PROVIDES(p, pp, obs)
1060 addrule(solv, -n, -p);
1063 FOR_PROVIDES(p, pp, s->name)
1065 if (s->name == pool->solvables[p].name)
1066 addrule(solv, -n, -p);
1070 /*-----------------------------------------
1071 * add recommends to the rule list
1075 recp = s->repo->idarraydata + s->recommends;
1076 while ((rec = *recp++) != 0)
1078 FOR_PROVIDES(p, pp, rec)
1085 sugp = s->repo->idarraydata + s->suggests;
1086 while ((sug = *sugp++) != 0)
1088 FOR_PROVIDES(p, pp, sug)
1095 if (solv->pool->verbose > 3)
1096 printf ("----- addrpmrulesforsolvable end -----\n");
1101 addrpmrulesforweak(Solver *solv, Map *m)
1103 Pool *pool = solv->pool;
1108 if (solv->pool->verbose > 3)
1109 printf ("----- addrpmrulesforweak -----\n");
1110 for (i = n = 1; n < pool->nsolvables; i++, n++)
1112 if (i == pool->nsolvables)
1116 s = pool->solvables + i;
1117 if (!pool_installable(pool, s))
1122 supp = s->repo->idarraydata + s->supplements;
1123 while ((sup = *supp++) != ID_NULL)
1124 if (dep_possible(solv, sup, m))
1127 if (!sup && s->freshens)
1129 supp = s->repo->idarraydata + s->freshens;
1130 while ((sup = *supp++) != ID_NULL)
1131 if (dep_possible(solv, sup, m))
1134 if (!sup && s->enhances)
1136 supp = s->repo->idarraydata + s->enhances;
1137 while ((sup = *supp++) != ID_NULL)
1138 if (dep_possible(solv, sup, m))
1143 addrpmrulesforsolvable(solv, s, m);
1146 if (solv->pool->verbose > 3)
1147 printf ("----- addrpmrulesforweak end -----\n");
1151 addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
1153 Pool *pool = solv->pool;
1158 if (solv->pool->verbose > 3)
1159 printf ("----- addrpmrulesforupdaters -----\n");
1161 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1162 policy_findupdatepackages(solv, s, &qs, allowall);
1163 if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
1164 addrpmrulesforsolvable(solv, s, m);
1165 for (i = 0; i < qs.count; i++)
1166 if (!MAPTST(m, qs.elements[i]))
1167 addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1170 if (solv->pool->verbose > 3)
1171 printf ("----- addrpmrulesforupdaters -----\n");
1176 * add rule for update
1177 * (A|A1|A2|A3...) An = update candidates for A
1179 * s = (installed) solvable
1183 addupdaterule(Solver *solv, Solvable *s, int allowall)
1185 /* installed packages get a special upgrade allowed rule */
1186 Pool *pool = solv->pool;
1191 if (solv->pool->verbose > 3)
1192 printf ("----- addupdaterule -----\n");
1194 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1195 policy_findupdatepackages(solv, s, &qs, allowall);
1196 if (qs.count == 0) /* no updaters found */
1199 d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
1201 addrule(solv, s - pool->solvables, d); /* allow update of s */
1202 if (solv->pool->verbose > 3)
1203 printf ("----- addupdaterule end -----\n");
1207 /*-----------------------------------------------------------------*/
1214 * initial setup for all watches
1218 makewatches(Solver *solv)
1222 int nsolvables = solv->pool->nsolvables;
1224 xfree(solv->watches);
1225 /* lower half for removals, upper half for installs */
1226 solv->watches = (Id *)xcalloc(2 * nsolvables, sizeof(Id));
1228 /* do it reverse so rpm rules get triggered first */
1229 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
1231 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
1234 if (!r->w1 /* rule is disabled */
1235 || !r->w2) /* rule is assertion */
1238 /* see addwatches(solv, r) */
1239 r->n1 = solv->watches[nsolvables + r->w1];
1240 solv->watches[nsolvables + r->w1] = r - solv->rules;
1242 r->n2 = solv->watches[nsolvables + r->w2];
1243 solv->watches[nsolvables + r->w2] = r - solv->rules;
1249 * add watches (for rule)
1253 addwatches(Solver *solv, Rule *r)
1255 int nsolvables = solv->pool->nsolvables;
1257 r->n1 = solv->watches[nsolvables + r->w1];
1258 solv->watches[nsolvables + r->w1] = r - solv->rules;
1260 r->n2 = solv->watches[nsolvables + r->w2];
1261 solv->watches[nsolvables + r->w2] = r - solv->rules;
1265 /*-----------------------------------------------------------------*/
1266 /* rule propagation */
1268 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
1273 * propagate decision to all rules
1277 propagate(Solver *solv, int level)
1279 Pool *pool = solv->pool;
1284 Id *decisionmap = solv->decisionmap;
1285 Id *watches = solv->watches + pool->nsolvables;
1287 if (solv->pool->verbose > 3)
1288 printf ("----- propagate -----\n");
1290 while (solv->propagate_index < solv->decisionq.count)
1292 /* negate because our watches trigger if literal goes FALSE */
1293 pkg = -solv->decisionq.elements[solv->propagate_index++];
1294 if (pool->verbose > 3)
1296 printf("popagate for decision %d level %d\n", -pkg, level);
1297 printruleelement(solv, 0, -pkg);
1300 for (rp = watches + pkg; *rp; rp = nrp)
1302 r = solv->rules + *rp;
1304 if (pool->verbose > 3)
1306 printf(" watch triggered ");
1320 /* if clause is TRUE, nothing to do */
1321 if (DECISIONMAP_TRUE(ow))
1326 /* not a binary clause, check if we need to move our watch */
1327 /* search for a literal that is not ow and not false */
1328 /* (true is also ok, in that case the rule is fulfilled) */
1329 if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
1332 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
1333 if (p != ow && !DECISIONMAP_TRUE(-p))
1337 /* p is free to watch, move watch to p */
1338 if (pool->verbose > 3)
1341 printf(" -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
1343 printf(" -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
1357 watches[p] = r - solv->rules;
1361 /* unit clause found, set other watch to TRUE */
1362 if (DECISIONMAP_TRUE(-ow))
1363 return r; /* eek, a conflict! */
1364 if (pool->verbose > 2)
1370 decisionmap[ow] = level;
1372 decisionmap[-ow] = -level;
1373 queue_push(&solv->decisionq, ow);
1374 queue_push(&solv->decisionq_why, r - solv->rules);
1375 if (pool->verbose > 3)
1377 Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
1379 printf(" -> decided to install %s\n", solvable2str(pool, s));
1381 printf(" -> decided to conflict %s\n", solvable2str(pool, s));
1385 if (solv->pool->verbose > 3)
1386 printf ("----- propagate end-----\n");
1388 return 0; /* all is well */
1392 /*-----------------------------------------------------------------*/
1401 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *why)
1403 Pool *pool = solv->pool;
1406 Map seen; /* global? */
1410 int learnt_why = solv->learnt_pool.count;
1411 Id *decisionmap = solv->decisionmap;
1415 if (pool->verbose > 1) printf("ANALYZE at %d ----------------------\n", level);
1416 map_init(&seen, pool->nsolvables);
1417 idx = solv->decisionq.count;
1420 if (pool->verbose > 1)
1421 printruleclass(solv, c);
1422 queue_push(&solv->learnt_pool, c - solv->rules);
1423 dp = c->d ? pool->whatprovidesdata + c->d : 0;
1434 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1436 vv = v > 0 ? v : -v;
1437 if (MAPTST(&seen, vv))
1439 l = solv->decisionmap[vv];
1446 for (j = 0; j < solv->decisionq.count; j++)
1447 if (solv->decisionq.elements[j] == v)
1449 if (j == solv->decisionq.count)
1451 queue_push(&rulq, -(j + 1));
1453 continue; /* initial setting */
1457 num++; /* need to do this one as well */
1461 if (pool->verbose > 3)
1463 printf("PUSH %d ", v);
1464 printruleelement(solv, 0, v);
1470 if (pool->verbose > 3)
1471 printf("num = %d\n", num);
1476 v = solv->decisionq.elements[--idx];
1477 vv = v > 0 ? v : -v;
1478 if (MAPTST(&seen, vv))
1481 c = solv->rules + solv->decisionq_why.elements[idx];
1489 else if (r.count == 1 && r.elements[0] < 0)
1490 *dr = r.elements[0];
1492 *dr = pool_queuetowhatprovides(pool, &r);
1493 if (pool->verbose > 1)
1495 printf("learned rule for level %d (am %d)\n", rlevel, level);
1496 printruleelement(solv, 0, -v);
1497 for (i = 0; i < r.count; i++)
1500 printruleelement(solv, 0, v);
1504 queue_push(&solv->learnt_pool, 0);
1505 if (pool->verbose > 3)
1507 for (i = learnt_why; solv->learnt_pool.elements[i]; i++)
1509 printf("learnt_why ");
1510 printrule(solv, solv->rules + solv->learnt_pool.elements[i]);
1521 * reset the solver decisions to right after the rpm rules.
1522 * called after rules have been enabled/disabled
1526 reset_solver(Solver *solv)
1531 enabledisablelearntrules(solv);
1533 /* redo all direct rpm rule decisions */
1534 /* we break at the first decision with a why attached, this is
1535 * either a job/system rule assertion or a propagated decision */
1536 for (i = 0; i < solv->decisionq.count; i++)
1538 v = solv->decisionq.elements[i];
1539 solv->decisionmap[v > 0 ? v : -v] = 0;
1541 for (i = 0; i < solv->decisionq_why.count; i++)
1542 if (solv->decisionq_why.elements[i])
1546 v = solv->decisionq.elements[i];
1547 solv->decisionmap[v > 0 ? v : -v] = v > 0 ? 1 : -1;
1550 if (solv->pool->verbose > 1)
1551 printf("decisions done reduced from %d to %d\n", solv->decisionq.count, i);
1553 solv->decisionq_why.count = i;
1554 solv->decisionq.count = i;
1555 solv->recommends_index = -1;
1556 solv->propagate_index = 0;
1558 /* redo all job/system decisions */
1559 makeruledecisions(solv);
1560 if (solv->pool->verbose > 1)
1561 printf("decisions so far: %d\n", solv->decisionq.count);
1562 /* recreate watch chains */
1568 * analyze_unsolvable_rule
1572 analyze_unsolvable_rule(Solver *solv, Rule *r)
1575 Id why = r - solv->rules;
1576 if (solv->pool->verbose > 1)
1577 printruleclass(solv, r);
1578 if (solv->learntrules && why >= solv->learntrules)
1580 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1581 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i]);
1584 /* do not add rpm rules to problem */
1585 if (why < solv->jobrules)
1587 /* turn rule into problem */
1588 if (why >= solv->jobrules && why < solv->systemrules)
1589 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1590 /* return if problem already countains our rule */
1591 if (solv->problems.count)
1593 for (i = solv->problems.count - 1; i >= 0; i--)
1594 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1596 else if (solv->problems.elements[i] == why)
1599 queue_push(&solv->problems, why);
1604 * analyze_unsolvable
1606 * return: 1 - disabled some rules, try again
1611 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1613 Pool *pool = solv->pool;
1615 Map seen; /* global to speed things up? */
1618 Id *decisionmap = solv->decisionmap;
1619 int oldproblemcount;
1620 int oldlearntpoolcount;
1623 if (pool->verbose > 1)
1624 printf("ANALYZE UNSOLVABLE ----------------------\n");
1625 oldproblemcount = solv->problems.count;
1626 oldlearntpoolcount = solv->learnt_pool.count;
1628 /* make room for proof index */
1629 /* must update it later, as analyze_unsolvable_rule would confuse
1630 * it with a rule index if we put the real value in already */
1631 queue_push(&solv->problems, 0);
1634 map_init(&seen, pool->nsolvables);
1635 queue_push(&solv->learnt_pool, r - solv->rules);
1636 analyze_unsolvable_rule(solv, r);
1637 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1648 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1650 vv = v > 0 ? v : -v;
1651 l = solv->decisionmap[vv];
1656 idx = solv->decisionq.count;
1659 v = solv->decisionq.elements[--idx];
1660 vv = v > 0 ? v : -v;
1661 if (!MAPTST(&seen, vv))
1663 why = solv->decisionq_why.elements[idx];
1666 /* level 1 and no why, must be an rpm assertion */
1667 if (pool->verbose > 3)
1670 printruleelement(solv, 0, v);
1672 /* this is the only positive rpm assertion */
1673 if (v == SYSTEMSOLVABLE)
1677 queue_push(&solv->learnt_pool, v);
1680 r = solv->rules + why;
1681 queue_push(&solv->learnt_pool, why);
1682 analyze_unsolvable_rule(solv, r);
1683 dp = r->d ? pool->whatprovidesdata + r->d : 0;
1694 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1696 vv = v > 0 ? v : -v;
1697 l = solv->decisionmap[vv];
1704 queue_push(&solv->problems, 0); /* mark end of this problem */
1707 if (solv->weakrules != solv->learntrules)
1709 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1711 why = solv->problems.elements[i];
1712 if (why < solv->weakrules || why >= solv->learntrules)
1714 if (!lastweak || lastweak < why)
1720 /* disable last weak rule */
1721 solv->problems.count = oldproblemcount;
1722 solv->learnt_pool.count = oldlearntpoolcount;
1723 r = solv->rules + lastweak;
1724 printf("disabling weak ");
1726 disablerule(solv, r);
1732 queue_push(&solv->learnt_pool, 0);
1733 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1737 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1738 disableproblem(solv, solv->problems.elements[i]);
1743 printf("UNSOLVABLE\n");
1748 /*-----------------------------------------------------------------*/
1749 /* Decision revert */
1753 * revert decision at level
1757 revert(Solver *solv, int level)
1760 while (solv->decisionq.count)
1762 v = solv->decisionq.elements[solv->decisionq.count - 1];
1763 vv = v > 0 ? v : -v;
1764 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1766 if (solv->pool->verbose > 3)
1767 printf("reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1768 solv->decisionmap[vv] = 0;
1769 solv->decisionq.count--;
1770 solv->decisionq_why.count--;
1771 solv->propagate_index = solv->decisionq.count;
1773 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1775 solv->branches.count--;
1776 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1777 solv->branches.count--;
1779 solv->recommends_index = -1;
1784 * watch2onhighest - put watch2 on literal with highest level
1788 watch2onhighest(Solver *solv, Rule *r)
1794 return; /* binary rule, both watches are set */
1795 dp = solv->pool->whatprovidesdata + r->d;
1796 while ((v = *dp++) != 0)
1798 l = solv->decisionmap[v < 0 ? -v : v];
1813 * add free decision to decision q, increase level
1814 * propagate decision, return if no conflict.
1815 * in conflict case, analyze conflict rule, add resulting
1816 * rule to learnt rule set, make decision from learnt
1817 * rule (always unit) and re-propagate.
1821 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
1831 solv->decisionmap[decision] = level;
1833 solv->decisionmap[-decision] = -level;
1834 queue_push(&solv->decisionq, decision);
1835 queue_push(&solv->decisionq_why, 0);
1839 r = propagate(solv, level);
1843 return analyze_unsolvable(solv, r, disablerules);
1844 printf("conflict with rule #%d\n", (int)(r - solv->rules));
1845 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1846 if (l >= level || l <= 0)
1848 printf("reverting decisions (level %d -> %d)\n", level, l);
1850 revert(solv, level);
1851 r = addrule(solv, p, d); /* p requires d */
1854 if (solv->learnt_why.count != (r - solv->rules) - solv->learntrules)
1856 printf("%d %d\n", solv->learnt_why.count, (int)(r - solv->rules) - solv->learntrules);
1859 queue_push(&solv->learnt_why, why);
1862 /* at least 2 literals, needs watches */
1863 watch2onhighest(solv, r);
1864 addwatches(solv, r);
1866 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1867 queue_push(&solv->decisionq, p);
1868 queue_push(&solv->decisionq_why, r - solv->rules);
1869 if (solv->pool->verbose > 1)
1871 printf("decision: ");
1872 printruleelement(solv, 0, p);
1873 printf("new rule: ");
1882 * install best package from the queue. We add an extra package, inst, if
1883 * provided. See comment in weak install section.
1886 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
1888 Pool *pool = solv->pool;
1892 if (dq->count > 1 || inst)
1893 policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
1898 /* choose the supplemented one */
1899 for (i = 0; i < dq->count; i++)
1900 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1904 for (i = 1; i < dq->count; i++)
1905 queue_push(&solv->branches, dq->elements[i]);
1906 queue_push(&solv->branches, -level);
1910 p = dq->elements[i];
1912 if (pool->verbose > 3)
1913 printf("installing %s\n", solvable2str(pool, pool->solvables + p));
1915 return setpropagatelearn(solv, level, p, disablerules);
1919 /*-----------------------------------------------------------------*/
1920 /* Main solver interface */
1925 * create solver structure
1927 * pool: all available solvables
1928 * installed: installed Solvables
1931 * Upon solving, rules are created to flag the Solvables
1932 * of the 'installed' Repo as installed.
1936 solver_create(Pool *pool, Repo *installed)
1939 solv = (Solver *)xcalloc(1, sizeof(Solver));
1941 solv->installed = installed;
1943 queue_init(&solv->ruletojob);
1944 queue_init(&solv->decisionq);
1945 queue_init(&solv->decisionq_why);
1946 queue_init(&solv->problems);
1947 queue_init(&solv->suggestions);
1948 queue_init(&solv->learnt_why);
1949 queue_init(&solv->learnt_pool);
1950 queue_init(&solv->branches);
1952 map_init(&solv->recommendsmap, pool->nsolvables);
1953 map_init(&solv->suggestsmap, pool->nsolvables);
1954 map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
1955 solv->recommends_index = 0;
1957 solv->decisionmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
1958 solv->rules = (Rule *)xmalloc((solv->nrules + (RULES_BLOCK + 1)) * sizeof(Rule));
1959 memset(solv->rules, 0, sizeof(Rule));
1971 solver_free(Solver *solv)
1973 queue_free(&solv->ruletojob);
1974 queue_free(&solv->decisionq);
1975 queue_free(&solv->decisionq_why);
1976 queue_free(&solv->learnt_why);
1977 queue_free(&solv->learnt_pool);
1978 queue_free(&solv->problems);
1979 queue_free(&solv->suggestions);
1980 queue_free(&solv->branches);
1982 map_free(&solv->recommendsmap);
1983 map_free(&solv->suggestsmap);
1984 map_free(&solv->noupdate);
1985 xfree(solv->decisionmap);
1987 xfree(solv->watches);
1988 xfree(solv->weaksystemrules);
1989 xfree(solv->obsoletes);
1990 xfree(solv->obsoletes_data);
1995 /*-------------------------------------------------------*/
2000 * all rules have been set up, now actually run the solver
2005 run_solver(Solver *solv, int disablerules, int doweak)
2013 Pool *pool = solv->pool;
2016 if (pool->verbose > 3)
2018 printf("number of rules: %d\n", solv->nrules);
2019 for (i = 0; i < solv->nrules; i++)
2020 printrule(solv, solv->rules + i);
2023 /* create watches chains */
2026 if (pool->verbose) printf("initial decisions: %d\n", solv->decisionq.count);
2027 if (pool->verbose > 3)
2028 printdecisions(solv);
2030 /* start SAT algorithm */
2032 systemlevel = level + 1;
2033 if (pool->verbose) printf("solving...\n");
2044 if (pool->verbose) printf("propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2045 if ((r = propagate(solv, level)) != 0)
2047 if (analyze_unsolvable(solv, r, disablerules))
2055 * installed packages
2058 if (level < systemlevel && solv->installed && solv->installed->nsolvables)
2060 if (!solv->updatesystem)
2062 /* try to keep as many packages as possible */
2063 if (pool->verbose) printf("installing system packages\n");
2064 for (i = solv->installed->start, n = 0; ; i++)
2066 if (n == solv->installed->nsolvables)
2068 if (i == solv->installed->end)
2069 i = solv->installed->start;
2070 s = pool->solvables + i;
2071 if (s->repo != solv->installed)
2074 if (solv->decisionmap[i] != 0)
2076 if (pool->verbose > 3)
2077 printf("keeping %s\n", solvable2str(pool, s));
2079 level = setpropagatelearn(solv, level, i, disablerules);
2085 if (level <= olevel)
2089 if (solv->weaksystemrules)
2091 if (pool->verbose) printf("installing weak system packages\n");
2092 for (i = solv->installed->start; i < solv->installed->end; i++)
2094 if (pool->solvables[i].repo != solv->installed)
2096 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
2098 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
2099 if (MAPTST(&solv->noupdate, i - solv->installed->start))
2102 if (solv->weaksystemrules[i - solv->installed->start])
2104 dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
2105 while ((p = *dp++) != 0)
2107 if (solv->decisionmap[p] > 0)
2109 if (solv->decisionmap[p] == 0)
2113 continue; /* update package already installed */
2115 if (!dq.count && solv->decisionmap[i] != 0)
2118 /* FIXME: i is handled a bit different because we do not want
2119 * to have it pruned just because it is not recommened.
2120 * we should not prune installed packages instead */
2121 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
2127 if (level <= olevel)
2130 if (i < solv->installed->end)
2133 systemlevel = level;
2140 if (pool->verbose) printf("deciding unresolved rules\n");
2141 for (i = 1, n = 1; ; i++, n++)
2143 if (n == solv->nrules)
2145 if (i == solv->nrules)
2147 r = solv->rules + i;
2153 /* binary or unary rule */
2154 /* need two positive undecided literals */
2155 if (r->p < 0 || r->w2 <= 0)
2157 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2159 queue_push(&dq, r->p);
2160 queue_push(&dq, r->w2);
2165 * all negative literals are installed
2166 * no positive literal is installed
2167 * i.e. the rule is not fulfilled and we
2168 * just need to decide on the positive literals
2172 if (solv->decisionmap[-r->p] <= 0)
2177 if (solv->decisionmap[r->p] > 0)
2179 if (solv->decisionmap[r->p] == 0)
2180 queue_push(&dq, r->p);
2182 dp = pool->whatprovidesdata + r->d;
2183 while ((p = *dp++) != 0)
2187 if (solv->decisionmap[-p] <= 0)
2192 if (solv->decisionmap[p] > 0)
2194 if (solv->decisionmap[p] == 0)
2203 /* cannot happen as this means that
2204 * the rule is unit */
2208 if (pool->verbose > 2)
2212 level = selectandinstall(solv, level, &dq, 0, disablerules);
2218 if (level < systemlevel)
2221 } /* for(), decide */
2223 if (n != solv->nrules) /* continue if level < systemlevel */
2226 if (doweak && !solv->problems.count)
2230 if (pool->verbose) printf("installing recommended packages\n");
2233 for (i = 0; i < solv->decisionq.count; i++)
2235 p = solv->decisionq.elements[i];
2236 if (p > 0 && pool->solvables[p].repo == solv->installed)
2237 solv->decisionmap[p] = -solv->decisionmap[p];
2241 for (i = 1; i < pool->nsolvables; i++)
2243 if (solv->decisionmap[i] < 0)
2245 if (solv->decisionmap[i] > 0)
2247 Id *recp, rec, *pp, p;
2248 s = pool->solvables + i;
2249 /* installed, check for recommends */
2250 /* XXX need to special case AND ? */
2253 recp = s->repo->idarraydata + s->recommends;
2254 while ((rec = *recp++) != 0)
2257 FOR_PROVIDES(p, pp, rec)
2259 if (solv->decisionmap[p] > 0)
2264 else if (solv->decisionmap[p] == 0)
2266 queue_pushunique(&dq, p);
2274 s = pool->solvables + i;
2275 if (!s->supplements && !s->freshens)
2277 if (!pool_installable(pool, s))
2279 if (solver_is_supplementing(solv, s))
2280 queue_pushunique(&dq, i);
2285 for (i = 0; i < solv->decisionq.count; i++)
2287 p = solv->decisionq.elements[i];
2288 if (p > 0 && pool->solvables[p].repo == solv->installed)
2289 solv->decisionmap[p] = -solv->decisionmap[p];
2295 policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
2297 if (pool->verbose > 0)
2298 printf("installing recommended %s\n", solvable2str(pool, pool->solvables + p));
2299 level = setpropagatelearn(solv, level, p, 0);
2304 if (solv->solution_callback)
2306 solv->solution_callback(solv, solv->solution_callback_data);
2307 if (solv->branches.count)
2309 int i = solv->branches.count - 1;
2310 int l = -solv->branches.elements[i];
2312 if (solv->branches.elements[i - 1] < 0)
2314 p = solv->branches.elements[i];
2315 if (pool->verbose > 0)
2316 printf("branching with %s\n", solvable2str(pool, pool->solvables + p));
2318 for (j = i + 1; j < solv->branches.count; j++)
2319 queue_push(&dq, solv->branches.elements[j]);
2320 solv->branches.count = i;
2322 revert(solv, level);
2324 for (j = 0; j < dq.count; j++)
2325 queue_push(&solv->branches, dq.elements[j]);
2327 level = setpropagatelearn(solv, level, p, disablerules);
2335 /* all branches done, we're finally finished */
2339 /* minimization step */
2340 if (solv->branches.count)
2342 int l = 0, lasti = -1, lastl = -1;
2344 for (i = solv->branches.count - 1; i >= 0; i--)
2346 p = solv->branches.elements[i];
2349 else if (p > 0 && solv->decisionmap[p] > l + 1)
2357 /* kill old solvable so that we do not loop */
2358 p = solv->branches.elements[lasti];
2359 solv->branches.elements[lasti] = 0;
2360 if (pool->verbose > 0)
2361 printf("minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
2364 revert(solv, level);
2366 level = setpropagatelearn(solv, level, p, disablerules);
2383 * at this point, all rules that led to conflicts are disabled.
2384 * we re-enable all rules of a problem set but rule "sug", then
2385 * continue to disable more rules until there as again a solution.
2388 /* FIXME: think about conflicting assertions */
2391 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
2393 Pool *pool = solv->pool;
2402 printf("refine_suggestion start\n");
2403 for (i = 0; problem[i]; i++)
2405 if (problem[i] == sug)
2407 printproblem(solv, problem[i]);
2410 queue_init(&disabled);
2411 queue_empty(refined);
2412 queue_push(refined, sug);
2414 /* re-enable all problem rules with the exception of "sug" */
2418 for (i = 0; problem[i]; i++)
2419 if (problem[i] != sug)
2420 enableproblem(solv, problem[i]);
2423 disableupdaterules(solv, job, -(sug + 1));
2427 /* re-enable as many weak rules as possible */
2428 for (i = solv->weakrules; i < solv->learntrules; i++)
2430 r = solv->rules + i;
2432 enablerule(solv, r);
2435 queue_empty(&solv->problems);
2436 revert(solv, 1); /* XXX move to reset_solver? */
2439 run_solver(solv, 0, 0);
2440 if (!solv->problems.count)
2443 printf("no more problems!\n");
2444 if (pool->verbose > 3)
2445 printdecisions(solv);
2446 break; /* great, no more problems */
2448 disabledcnt = disabled.count;
2449 /* skip over proof index */
2450 for (i = 1; i < solv->problems.count - 1; i++)
2452 /* ignore solutions in refined */
2453 v = solv->problems.elements[i];
2455 break; /* end of problem reached */
2456 for (j = 0; problem[j]; j++)
2457 if (problem[j] != sug && problem[j] == v)
2461 queue_push(&disabled, v);
2463 if (disabled.count == disabledcnt)
2465 /* no solution found, this was an invalid suggestion! */
2467 printf("no solution found!\n");
2471 if (disabled.count == disabledcnt + 1)
2473 /* just one suggestion, add it to refined list */
2474 v = disabled.elements[disabledcnt];
2475 queue_push(refined, v);
2476 disableproblem(solv, v);
2478 disableupdaterules(solv, job, -(v + 1));
2482 /* more than one solution, disable all */
2483 /* do not push anything on refine list */
2484 if (pool->verbose > 1)
2486 printf("more than one solution found:\n");
2487 for (i = disabledcnt; i < disabled.count; i++)
2488 printproblem(solv, disabled.elements[i]);
2490 for (i = disabledcnt; i < disabled.count; i++)
2491 disableproblem(solv, disabled.elements[i]);
2494 /* all done, get us back into the same state as before */
2495 /* enable refined rules again */
2496 for (i = 0; i < disabled.count; i++)
2497 enableproblem(solv, disabled.elements[i]);
2498 /* disable problem rules again */
2499 for (i = 0; problem[i]; i++)
2500 disableproblem(solv, problem[i]);
2501 disableupdaterules(solv, job, -1);
2503 printf("refine_suggestion end\n");
2507 problems_to_solutions(Solver *solv, Queue *job)
2509 Pool *pool = solv->pool;
2517 if (!solv->problems.count)
2519 queue_clone(&problems, &solv->problems);
2520 queue_init(&solution);
2521 queue_init(&solutions);
2522 /* copy over proof index */
2523 queue_push(&solutions, problems.elements[0]);
2524 problem = problems.elements + 1;
2525 for (i = 1; i < problems.count; i++)
2527 Id v = problems.elements[i];
2530 /* mark end of this problem */
2531 queue_push(&solutions, 0);
2532 queue_push(&solutions, 0);
2533 if (i + 1 == problems.count)
2535 /* copy over proof of next problem */
2536 queue_push(&solutions, problems.elements[i + 1]);
2538 problem = problems.elements + i + 1;
2541 refine_suggestion(solv, job, problem, v, &solution);
2542 if (!solution.count)
2543 continue; /* this solution didn't work out */
2545 for (j = 0; j < solution.count; j++)
2547 why = solution.elements[j];
2549 printproblem(solv, why);
2553 queue_push(&solutions, 0);
2554 queue_push(&solutions, -why);
2556 else if (why >= solv->systemrules && why < solv->weakrules)
2559 p = solv->installed->start + (why - solv->systemrules);
2560 if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
2562 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
2565 if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
2567 if (solv->decisionmap[*dp] > 0)
2574 queue_push(&solutions, p);
2575 queue_push(&solutions, rp);
2580 /* mark end of this solution */
2581 queue_push(&solutions, 0);
2582 queue_push(&solutions, 0);
2584 queue_free(&solution);
2585 queue_free(&problems);
2586 /* copy queue over to solutions */
2587 queue_free(&solv->problems);
2588 queue_clone(&solv->problems, &solutions);
2590 /* bring solver back into problem state */
2591 revert(solv, 1); /* XXX move to reset_solver? */
2594 if (solv->problems.count != solutions.count)
2596 queue_free(&solutions);
2600 solver_next_problem(Solver *solv, Id problem)
2604 return solv->problems.count ? 1 : 0;
2605 pp = solv->problems.elements + problem;
2606 while (pp[0] || pp[1])
2610 while (pp[0] || pp[1])
2615 problem = pp - solv->problems.elements;
2616 if (problem >= solv->problems.count)
2622 solver_next_solution(Solver *solv, Id problem, Id solution)
2628 pp = solv->problems.elements + solution;
2629 return pp[0] || pp[1] ? solution : 0;
2631 pp = solv->problems.elements + solution;
2632 while (pp[0] || pp[1])
2635 solution = pp - solv->problems.elements;
2636 return pp[0] || pp[1] ? solution : 0;
2640 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
2643 element = element ? element + 2 : solution;
2644 pp = solv->problems.elements + element;
2645 if (!(pp[0] || pp[1]))
2660 printdecisions(Solver *solv)
2662 Pool *pool = solv->pool;
2663 Repo *installed = solv->installed;
2664 Id p, *obsoletesmap;
2668 obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id));
2671 for (i = 0; i < solv->decisionq.count; i++)
2675 n = solv->decisionq.elements[i];
2678 if (n == SYSTEMSOLVABLE)
2680 s = pool->solvables + n;
2681 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2683 FOR_PROVIDES(p, pp, s->name)
2684 if (s->name == pool->solvables[p].name)
2686 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2688 obsoletesmap[p] = n;
2693 for (i = 0; i < solv->decisionq.count; i++)
2698 n = solv->decisionq.elements[i];
2701 if (n == SYSTEMSOLVABLE)
2703 s = pool->solvables + n;
2704 if (s->repo == installed) /* obsoletes don't count for already installed packages */
2708 obsp = s->repo->idarraydata + s->obsoletes;
2709 while ((obs = *obsp++) != 0)
2710 FOR_PROVIDES(p, pp, obs)
2712 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
2714 obsoletesmap[p] = n;
2721 /* print solvables to be erased */
2725 FOR_REPO_SOLVABLES(installed, p, s)
2727 if (solv->decisionmap[p] >= 0)
2729 if (obsoletesmap[p])
2731 printf("erase %s\n", solvable2str(pool, s));
2735 /* print solvables to be installed */
2737 for (i = 0; i < solv->decisionq.count; i++)
2740 p = solv->decisionq.elements[i];
2743 if (p == SYSTEMSOLVABLE)
2745 s = pool->solvables + p;
2746 if (installed && s->repo == installed)
2749 if (!obsoletesmap[p])
2751 printf("install %s", solvable2str(pool, s));
2755 printf("update %s", solvable2str(pool, s));
2756 printf(" (obsoletes");
2757 for (j = installed->start; j < installed->end; j++)
2758 if (obsoletesmap[j] == p)
2759 printf(" %s", solvable2str(pool, pool->solvables + j));
2765 xfree(obsoletesmap);
2767 if (solv->suggestions.count)
2769 printf("\nsuggested packages:\n");
2770 for (i = 0; i < solv->suggestions.count; i++)
2772 s = pool->solvables + solv->suggestions.elements[i];
2773 printf("- %s\n", solvable2str(pool, s));
2779 printconflicts(Solver *solv, Solvable *s, Id pc)
2781 Pool *pool = solv->pool;
2782 Solvable *sc = pool->solvables + pc;
2783 Id p, *pp, con, *conp, obs, *obsp;
2788 conp = s->repo->idarraydata + s->conflicts;
2789 while ((con = *conp++) != 0)
2791 FOR_PROVIDES(p, pp, con)
2795 printf("packags %s conflicts with %s, which is provided by %s\n", solvable2str(pool, s), dep2str(pool, con), solvable2str(pool, sc));
2800 if (s->obsoletes && (!solv->installed || s->repo != solv->installed))
2802 obsp = s->repo->idarraydata + s->obsoletes;
2803 while ((obs = *obsp++) != 0)
2805 FOR_PROVIDES(p, pp, obs)
2809 printf("packags %s obsolets %s, which is provided by %s\n", solvable2str(pool, s), dep2str(pool, obs), solvable2str(pool, sc));
2818 printprobleminfo(Solver *solv, Queue *job, Id problem)
2820 Pool *pool = solv->pool;
2824 Id idx = solv->problems.elements[problem - 1];
2826 rn = solv->learnt_pool.elements[idx];
2829 p = rn; /* fake a negative assertion rule */
2834 r = solv->rules + rn;
2838 if (!r || r->w2 == 0)
2844 if (p == -SYSTEMSOLVABLE)
2848 /* we tried to deinstall the system solvable. must be a job. */
2849 if (rn < solv->jobrules || rn >= solv->systemrules)
2851 ji = solv->ruletojob.elements[rn - solv->jobrules];
2852 what = job->elements[ji + 1];
2853 switch (job->elements[ji])
2855 case SOLVER_INSTALL_SOLVABLE_NAME:
2856 printf("no solvable exists with name %s\n", dep2str(pool, what));
2858 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
2859 printf("no solvable provides %s\n", dep2str(pool, what));
2862 printf("unknown job\n");
2867 if (p > 0 && solv->learnt_pool.elements[idx + 1] == -p)
2869 /* we conflicted with a direct rpm assertion */
2870 /* print other rule */
2874 if (rn >= solv->jobrules)
2876 printf("some job/system/learnt rule\n");
2882 /* negative assertion, i.e. package is not installable */
2883 s = pool->solvables + (-p);
2886 reqp = s->repo->idarraydata + s->requires;
2887 while ((req = *reqp++) != 0)
2889 if (req == SOLVABLE_PREREQMARKER)
2891 dp = pool_whatprovides(pool, req);
2894 printf("package %s requires %s, but no package provides it\n", solvable2str(pool, s), dep2str(pool, req));
2899 printf("package %s is not installable\n", solvable2str(pool, s));
2903 if (rn >= solv->learntrules)
2905 /* learnt rule, ignore for now */
2906 printf("some learnt rule...\n");
2910 if (rn >= solv->systemrules)
2912 /* system rule, ignore for now */
2913 printf("some system rule...\n");
2917 if (rn >= solv->jobrules)
2919 /* job rule, ignore for now */
2920 printf("some job rule...\n");
2924 /* only rpm rules left... */
2929 if (d == 0 && r->w2 < 0)
2933 sp = pool->solvables + (-p);
2934 sd = pool->solvables + (-d);
2935 if (sp->name == sd->name)
2937 printf("cannot install both %s and %s\n", solvable2str(pool, sp), solvable2str(pool, sd));
2941 printconflicts(solv, pool->solvables + (-p), -d);
2942 printconflicts(solv, pool->solvables + (-d), -p);
2947 /* find requires of p that corresponds with our rule */
2949 s = pool->solvables + (-p);
2950 reqp = s->repo->idarraydata + s->requires;
2951 while ((req = *reqp++) != 0)
2953 if (req == SOLVABLE_PREREQMARKER)
2955 dp = pool_whatprovides(pool, req);
2958 if (*dp == r->w2 && dp[1] == 0)
2961 else if (dp - pool->whatprovidesdata == d)
2966 printf("req not found\n");
2969 printf("package %s requires %s, but none of its providers can be installed\n", solvable2str(pool, s), dep2str(pool, req));
2974 printsolutions(Solver *solv, Queue *job)
2976 Pool *pool = solv->pool;
2979 Id problem, solution, element;
2982 printf("Encountered problems! Here are the solutions:\n\n");
2985 while ((problem = solver_next_problem(solv, problem)) != 0)
2987 printf("Problem %d:\n", pcnt++);
2988 printf("====================================\n");
2989 printprobleminfo(solv, job, problem);
2992 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
2995 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
2999 /* job, rp is index into job queue */
3000 what = job->elements[rp];
3001 switch (job->elements[rp - 1])
3003 case SOLVER_INSTALL_SOLVABLE:
3004 s = pool->solvables + what;
3005 if (solv->installed && s->repo == solv->installed)
3006 printf("- do not keep %s installed\n", solvable2str(pool, s));
3008 printf("- do not install %s\n", solvable2str(pool, s));
3010 case SOLVER_ERASE_SOLVABLE:
3011 s = pool->solvables + what;
3012 if (solv->installed && s->repo == solv->installed)
3013 printf("- do not deinstall %s\n", solvable2str(pool, s));
3015 printf("- do not forbid installation of %s\n", solvable2str(pool, s));
3017 case SOLVER_INSTALL_SOLVABLE_NAME:
3018 printf("- do not install %s\n", id2str(pool, what));
3020 case SOLVER_ERASE_SOLVABLE_NAME:
3021 printf("- do not deinstall %s\n", id2str(pool, what));
3023 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3024 printf("- do not install a solvable providing %s\n", dep2str(pool, what));
3026 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3027 printf("- do not deinstall all solvables providing %s\n", dep2str(pool, what));
3029 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3030 s = pool->solvables + what;
3031 printf("- do not install most recent version of %s\n", solvable2str(pool, s));
3034 printf("- do something different\n");
3040 /* policy, replace p with rp */
3041 s = pool->solvables + p;
3042 sd = rp ? pool->solvables + rp : 0;
3046 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr) > 0)
3048 printf("- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3051 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd))
3053 printf("- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3056 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd))
3059 printf("- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
3061 printf("- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
3065 printf("- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
3069 printf("- allow deinstallation of %s\n", solvable2str(pool, s));
3080 /* for each installed solvable find which packages with *different* names
3081 * obsolete the solvable.
3082 * this index is used in policy_findupdatepackages if noupdateprovide is set.
3086 create_obsolete_index(Solver *solv)
3088 Pool *pool = solv->pool;
3090 Repo *installed = solv->installed;
3091 Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
3094 if (!installed || !installed->nsolvables)
3096 /* create reverse obsoletes map for installed solvables */
3097 solv->obsoletes = obsoletes = xcalloc(installed->end - installed->start, sizeof(Id));
3098 for (i = 1; i < pool->nsolvables; i++)
3100 s = pool->solvables + i;
3101 if (s->repo == installed)
3105 if (!pool_installable(pool, s))
3107 obsp = s->repo->idarraydata + s->obsoletes;
3108 while ((obs = *obsp++) != 0)
3109 FOR_PROVIDES(p, pp, obs)
3111 if (pool->solvables[p].repo != installed)
3113 if (pool->solvables[p].name == s->name)
3115 obsoletes[p - installed->start]++;
3119 for (i = 0; i < installed->nsolvables; i++)
3122 n += obsoletes[i] + 1;
3125 solv->obsoletes_data = obsoletes_data = xcalloc(n + 1, sizeof(Id));
3126 if (pool->verbose) printf("obsoletes data: %d entries\n", n + 1);
3127 for (i = pool->nsolvables - 1; i > 0; i--)
3129 s = pool->solvables + i;
3130 if (s->repo == installed)
3134 if (!pool_installable(pool, s))
3136 obsp = s->repo->idarraydata + s->obsoletes;
3137 while ((obs = *obsp++) != 0)
3138 FOR_PROVIDES(p, pp, obs)
3140 if (pool->solvables[p].repo != installed)
3142 if (pool->solvables[p].name == s->name)
3144 p -= installed->start;
3145 if (obsoletes_data[obsoletes[p]] != i)
3146 obsoletes_data[--obsoletes[p]] = i;
3152 /*-----------------------------------------------------------------*/
3162 solver_solve(Solver *solv, Queue *job)
3164 Pool *pool = solv->pool;
3165 Repo *installed = solv->installed;
3168 Map addedmap; /* '1' == have rule for solvable */
3169 Id how, what, p, *pp, d;
3173 /* create obsolete index if needed */
3174 if (solv->noupdateprovide)
3175 create_obsolete_index(solv);
3178 * create basic rule set of all involved packages
3179 * use addedmap bitmap to make sure we don't create rules twice
3183 map_init(&addedmap, pool->nsolvables);
3187 * always install our system solvable
3189 MAPSET(&addedmap, SYSTEMSOLVABLE);
3190 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
3191 queue_push(&solv->decisionq_why, 0);
3192 solv->decisionmap[SYSTEMSOLVABLE] = 1;
3195 * create rules for all package that could be involved with the solving
3196 * so called: rpm rules
3201 oldnrules = solv->nrules;
3202 if (pool->verbose > 3)
3203 printf ("*** create rpm rules for installed solvables ***\n");
3204 FOR_REPO_SOLVABLES(installed, p, s)
3205 addrpmrulesforsolvable(solv, s, &addedmap);
3207 printf("added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3208 if (pool->verbose > 3)
3209 printf ("*** create rpm rules for updaters of installed solvables ***\n");
3210 oldnrules = solv->nrules;
3211 FOR_REPO_SOLVABLES(installed, p, s)
3212 addrpmrulesforupdaters(solv, s, &addedmap, 1);
3214 printf("added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3217 if (solv->pool->verbose > 3)
3218 printf ("*** create rpm rules for packages involved with a job ***\n");
3219 oldnrules = solv->nrules;
3220 for (i = 0; i < job->count; i += 2)
3222 how = job->elements[i];
3223 what = job->elements[i + 1];
3227 case SOLVER_INSTALL_SOLVABLE:
3228 addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
3230 case SOLVER_INSTALL_SOLVABLE_NAME:
3231 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3232 FOR_PROVIDES(p, pp, what)
3234 /* if by name, ensure that the name matches */
3235 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3237 addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3240 case SOLVER_INSTALL_SOLVABLE_UPDATE:
3241 /* dont allow downgrade */
3242 addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
3247 printf("added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3249 if (solv->pool->verbose > 3)
3250 printf ("*** create rpm rules for recommended/suggested packages ***\n");
3252 oldnrules = solv->nrules;
3253 addrpmrulesforweak(solv, &addedmap);
3255 printf("added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3260 int possible = 0, installable = 0;
3261 for (i = 1; i < pool->nsolvables; i++)
3263 if (pool_installable(pool, pool->solvables + i))
3265 if (MAPTST(&addedmap, i))
3268 printf("%d of %d installable solvables considered for solving\n", possible, installable);
3273 * first pass done, we now have all the rpm rules we need.
3274 * unify existing rules before going over all job rules and
3276 * at this point the system is always solvable,
3277 * as an empty system (remove all packages) is a valid solution
3280 unifyrules(solv); /* remove duplicate rpm rules */
3282 if (pool->verbose) printf("decisions so far: %d\n", solv->decisionq.count);
3283 if (pool->verbose > 3)
3284 printdecisions (solv);
3287 * now add all job rules
3290 if (solv->pool->verbose > 3)
3291 printf ("*** Add JOB rules ***\n");
3293 solv->jobrules = solv->nrules;
3295 for (i = 0; i < job->count; i += 2)
3297 how = job->elements[i];
3298 what = job->elements[i + 1];
3301 case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
3302 s = pool->solvables + what;
3304 printf("job: install solvable %s\n", solvable2str(pool, s));
3305 addrule(solv, what, 0); /* install by Id */
3306 queue_push(&solv->ruletojob, i);
3308 case SOLVER_ERASE_SOLVABLE:
3309 s = pool->solvables + what;
3311 printf("job: erase solvable %s\n", solvable2str(pool, s));
3312 addrule(solv, -what, 0); /* remove by Id */
3313 queue_push(&solv->ruletojob, i);
3315 case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
3316 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
3317 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_NAME)
3318 printf("job: install name %s\n", id2str(pool, what));
3319 if (pool->verbose && how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
3320 printf("job: install provides %s\n", dep2str(pool, what));
3322 FOR_PROVIDES(p, pp, what)
3324 /* if by name, ensure that the name matches */
3325 if (how == SOLVER_INSTALL_SOLVABLE_NAME && pool->solvables[p].name != what)
3331 /* no provider, make this an impossible rule */
3332 queue_push(&q, -SYSTEMSOLVABLE);
3335 p = queue_shift(&q); /* get first provider */
3337 d = 0; /* single provider ? -> make assertion */
3339 d = pool_queuetowhatprovides(pool, &q); /* get all providers */
3340 addrule(solv, p, d); /* add 'requires' rule */
3341 queue_push(&solv->ruletojob, i);
3343 case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
3344 case SOLVER_ERASE_SOLVABLE_PROVIDES:
3345 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_NAME)
3346 printf("job: erase name %s\n", id2str(pool, what));
3347 if (pool->verbose && how == SOLVER_ERASE_SOLVABLE_PROVIDES)
3348 printf("job: erase provides %s\n", dep2str(pool, what));
3349 FOR_PROVIDES(p, pp, what)
3351 /* if by name, ensure that the name matches */
3352 if (how == SOLVER_ERASE_SOLVABLE_NAME && pool->solvables[p].name != what)
3354 addrule(solv, -p, 0); /* add 'remove' rule */
3355 queue_push(&solv->ruletojob, i);
3358 case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
3359 s = pool->solvables + what;
3361 printf("job: update %s\n", solvable2str(pool, s));
3362 addupdaterule(solv, s, 0);
3363 queue_push(&solv->ruletojob, i);
3368 if (solv->ruletojob.count != solv->nrules - solv->jobrules)
3372 * now add system rules
3376 if (solv->pool->verbose > 3)
3377 printf ("*** Add system rules ***\n");
3380 solv->systemrules = solv->nrules;
3383 * create rules for updating installed solvables
3387 if (installed && !solv->allowuninstall)
3388 { /* loop over all installed solvables */
3389 /* we create all update rules, but disable some later on depending on the job */
3390 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3391 if (s->repo == installed)
3392 addupdaterule(solv, s, 0); /* allowall = 0 */
3394 addupdaterule(solv, 0, 0); /* create dummy rule; allowall = 0 */
3395 /* consistency check: we added a rule for _every_ system solvable */
3396 if (solv->nrules - solv->systemrules != installed->end - installed->start)
3400 /* create special weak system rules */
3401 /* those are used later on to keep a version of the installed packages in
3403 if (installed && installed->nsolvables)
3405 solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id));
3406 FOR_REPO_SOLVABLES(installed, p, s)
3408 policy_findupdatepackages(solv, s, &q, 1);
3410 solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
3414 /* free unneeded memory */
3415 map_free(&addedmap);
3418 solv->weakrules = solv->nrules;
3420 /* try real hard to keep packages installed */
3423 FOR_REPO_SOLVABLES(installed, p, s)
3425 /* FIXME: can't work with refine_suggestion! */
3426 /* need to always add the rule but disable it */
3427 if (MAPTST(&solv->noupdate, p - installed->start))
3429 d = solv->weaksystemrules[p - installed->start];
3430 addrule(solv, p, d);
3434 /* all new rules are learnt after this point */
3435 solv->learntrules = solv->nrules;
3442 disableupdaterules(solv, job, -1);
3443 makeruledecisions(solv);
3445 if (pool->verbose) printf("problems so far: %d\n", solv->problems.count);
3447 run_solver(solv, 1, 1);
3449 /* find suggested packages */
3450 if (!solv->problems.count)
3452 Id sug, *sugp, p, *pp;
3454 /* create map of all suggests that are still open */
3455 solv->recommends_index = -1;
3456 MAPZERO(&solv->suggestsmap);
3457 for (i = 0; i < solv->decisionq.count; i++)
3459 p = solv->decisionq.elements[i];
3462 s = pool->solvables + p;
3465 sugp = s->repo->idarraydata + s->suggests;
3466 while ((sug = *sugp++) != 0)
3468 FOR_PROVIDES(p, pp, sug)
3469 if (solv->decisionmap[p] > 0)
3472 continue; /* already fulfilled */
3473 FOR_PROVIDES(p, pp, sug)
3474 MAPSET(&solv->suggestsmap, p);
3478 for (i = 1; i < pool->nsolvables; i++)
3480 if (solv->decisionmap[i] != 0)
3482 s = pool->solvables + i;
3483 if (!MAPTST(&solv->suggestsmap, i))
3487 if (!pool_installable(pool, s))
3489 if (!solver_is_enhancing(solv, s))
3492 queue_push(&solv->suggestions, i);
3494 policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
3497 if (solv->problems.count)
3498 problems_to_solutions(solv, job);