Also look at obsoletes of installed packages, like newer versions of rpm do
[platform/upstream/libsolv.git] / src / solverdebug.c
1 /*
2  * Copyright (c) 2008, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * solverdebug.c
10  *
11  * debug functions for the SAT solver
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <assert.h>
19
20 #include "solver.h"
21 #include "solverdebug.h"
22 #include "bitmap.h"
23 #include "pool.h"
24 #include "poolarch.h"
25 #include "util.h"
26 #include "evr.h"
27 #include "policy.h"
28
29
30 /*
31  * create obsoletesmap from solver decisions
32  *
33  * for solvables in installed repo:
34  *   0 - not obsoleted
35  *   p - one of the packages that obsolete us
36  * for all others:
37  *   n - number of packages this package obsoletes
38  *
39  */
40
41 /* OBSOLETE: use transaction code instead! */
42
43 Id *
44 solver_create_decisions_obsoletesmap(Solver *solv)
45 {
46   Pool *pool = solv->pool;
47   Repo *installed = solv->installed;
48   Id p, *obsoletesmap = NULL;
49   int i;
50   Solvable *s;
51
52   obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
53   if (installed)
54     {
55       for (i = 0; i < solv->decisionq.count; i++)
56         {
57           Id pp, n;
58           int noobs;
59
60           n = solv->decisionq.elements[i];
61           if (n < 0)
62             continue;
63           if (n == SYSTEMSOLVABLE)
64             continue;
65           s = pool->solvables + n;
66           if (s->repo == installed)             /* obsoletes don't count for already installed packages */
67             continue;
68           noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
69           FOR_PROVIDES(p, pp, s->name)
70             {
71               Solvable *ps = pool->solvables + p;
72               if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
73                 continue;
74               if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
75                 continue;
76               if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
77                 continue;
78               if (ps->repo == installed && !obsoletesmap[p])
79                 {
80                   obsoletesmap[p] = n;
81                   obsoletesmap[n]++;
82                 }
83             }
84         }
85       for (i = 0; i < solv->decisionq.count; i++)
86         {
87           Id obs, *obsp;
88           Id pp, n;
89
90           n = solv->decisionq.elements[i];
91           if (n < 0)
92             continue;
93           if (n == SYSTEMSOLVABLE)
94             continue;
95           s = pool->solvables + n;
96           if (s->repo == installed)             /* obsoletes don't count for already installed packages */
97             continue;
98           if (!s->obsoletes)
99             continue;
100           if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n))
101             continue;
102           obsp = s->repo->idarraydata + s->obsoletes;
103           while ((obs = *obsp++) != 0)
104             {
105               FOR_PROVIDES(p, pp, obs)
106                 {
107                   Solvable *ps = pool->solvables + p;
108                   if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
109                     continue;
110                   if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
111                     continue;
112                   if (pool->solvables[p].repo == installed && !obsoletesmap[p])
113                     {
114                       obsoletesmap[p] = n;
115                       obsoletesmap[n]++;
116                     }
117                 }
118             }
119         }
120     }
121   return obsoletesmap;
122 }
123
124 void
125 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
126 {
127   Pool *pool = solv->pool;
128   Solvable *s;
129   if (v < 0)
130     {
131       s = pool->solvables + -v;
132       POOL_DEBUG(type, "    !%s [%d]", solvable2str(pool, s), -v);
133     }
134   else
135     {
136       s = pool->solvables + v;
137       POOL_DEBUG(type, "    %s [%d]", solvable2str(pool, s), v);
138     }
139   if (pool->installed && s->repo == pool->installed)
140     POOL_DEBUG(type, "I");
141   if (r)
142     {
143       if (r->w1 == v)
144         POOL_DEBUG(type, " (w1)");
145       if (r->w2 == v)
146         POOL_DEBUG(type, " (w2)");
147     }
148   if (solv->decisionmap[s - pool->solvables] > 0)
149     POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
150   if (solv->decisionmap[s - pool->solvables] < 0)
151     POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
152   POOL_DEBUG(type, "\n");
153 }
154
155
156 /*
157  * print rule
158  */
159
160 void
161 solver_printrule(Solver *solv, int type, Rule *r)
162 {
163   Pool *pool = solv->pool;
164   int i;
165   Id d, v;
166
167   if (r >= solv->rules && r < solv->rules + solv->nrules)   /* r is a solver rule */
168     POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
169   else
170     POOL_DEBUG(type, "Rule:");                 /* r is any rule */
171   if (r && r->d < 0)
172     POOL_DEBUG(type, " (disabled)");
173   POOL_DEBUG(type, "\n");
174   d = r->d < 0 ? -r->d - 1 : r->d;
175   for (i = 0; ; i++)
176     {
177       if (i == 0)
178           /* print direct literal */
179         v = r->p;
180       else if (!d)
181         {
182           if (i == 2)
183             break;
184           /* binary rule --> print w2 as second literal */
185           v = r->w2;
186         }
187       else
188           /* every other which is in d */
189         v = solv->pool->whatprovidesdata[d + i - 1];
190       if (v == ID_NULL)
191         break;
192       solver_printruleelement(solv, type, r, v);
193     }
194   POOL_DEBUG(type, "    next rules: %d %d\n", r->n1, r->n2);
195 }
196
197 void
198 solver_printruleclass(Solver *solv, int type, Rule *r)
199 {
200   Pool *pool = solv->pool;
201   Id p = r - solv->rules;
202   assert(p >= 0);
203   if (p < solv->learntrules)
204     if (MAPTST(&solv->weakrulemap, p))
205       POOL_DEBUG(type, "WEAK ");
206   if (solv->learntrules && p >= solv->learntrules)
207     POOL_DEBUG(type, "LEARNT ");
208   else if (p >= solv->choicerules && p < solv->choicerules_end)
209     POOL_DEBUG(type, "CHOICE ");
210   else if (p >= solv->infarchrules && p < solv->infarchrules_end)
211     POOL_DEBUG(type, "INFARCH ");
212   else if (p >= solv->duprules && p < solv->duprules_end)
213     POOL_DEBUG(type, "DUP ");
214   else if (p >= solv->jobrules && p < solv->jobrules_end)
215     POOL_DEBUG(type, "JOB ");
216   else if (p >= solv->updaterules && p < solv->updaterules_end)
217     POOL_DEBUG(type, "UPDATE ");
218   else if (p >= solv->featurerules && p < solv->featurerules_end)
219     POOL_DEBUG(type, "FEATURE ");
220   solver_printrule(solv, type, r);
221 }
222
223 void
224 solver_printproblem(Solver *solv, Id v)
225 {
226   Pool *pool = solv->pool;
227   int i;
228   Rule *r;
229   Id *jp;
230
231   if (v > 0)
232     solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
233   else
234     {
235       v = -(v + 1);
236       POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
237       jp = solv->ruletojob.elements;
238       for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
239         if (*jp == v)
240           {
241             POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
242             solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
243           }
244       POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
245     }
246 }
247
248 void
249 solver_printwatches(Solver *solv, int type)
250 {
251   Pool *pool = solv->pool;
252   int counter;
253
254   POOL_DEBUG(type, "Watches: \n");
255   for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
256     POOL_DEBUG(type, "    solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
257 }
258
259 void
260 solver_printdecisionq(Solver *solv, int type)
261 {
262   Pool *pool = solv->pool;
263   int i;
264   Id p, why;
265
266   POOL_DEBUG(type, "Decisions:\n");
267   for (i = 0; i < solv->decisionq.count; i++)
268     {
269       p = solv->decisionq.elements[i];
270       if (p > 0)
271         POOL_DEBUG(type, "%d %d install  %s, ", i, solv->decisionmap[p], solvid2str(pool, p));
272       else
273         POOL_DEBUG(type, "%d %d conflict %s, ", i, -solv->decisionmap[-p], solvid2str(pool, -p));
274       why = solv->decisionq_why.elements[i];
275       if (why > 0)
276         {
277           POOL_DEBUG(type, "forced by ");
278           solver_printruleclass(solv, type, solv->rules + why);
279         }
280       else if (why < 0)
281         {
282           POOL_DEBUG(type, "chosen from ");
283           solver_printruleclass(solv, type, solv->rules - why);
284         }
285       else
286         POOL_DEBUG(type, "picked for some unknown reason.\n");
287     }
288 }
289
290 /*
291  * printdecisions
292  */
293
294 void
295 solver_printdecisions(Solver *solv)
296 {
297   Pool *pool = solv->pool;
298   Repo *installed = solv->installed;
299   Id p, type;
300   int i, j;
301   Solvable *s;
302   Queue iq;
303
304   IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
305     {
306       POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
307       for (i = 0; i < solv->decisionq.count; i++)
308         {
309           p = solv->decisionq.elements[i];
310           solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
311         }
312       POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
313     }
314
315   POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
316   POOL_DEBUG(SAT_DEBUG_RESULT, "transaction:\n");
317
318   queue_init(&iq);
319   for (i = 0; i < solv->trans.steps.count; i++)
320     {
321       p = solv->trans.steps.elements[i];
322       s = pool->solvables + p;
323       type = transaction_type(&solv->trans, p, SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES|SOLVER_TRANSACTION_SHOW_MULTIINSTALL);
324       switch(type)
325         {
326         case SOLVER_TRANSACTION_MULTIINSTALL:
327           POOL_DEBUG(SAT_DEBUG_RESULT, "  multi install %s", solvable2str(pool, s));
328           break;
329         case SOLVER_TRANSACTION_MULTIREINSTALL:
330           POOL_DEBUG(SAT_DEBUG_RESULT, "  multi reinstall %s", solvable2str(pool, s));
331           break;
332         case SOLVER_TRANSACTION_INSTALL:
333           POOL_DEBUG(SAT_DEBUG_RESULT, "  install   %s", solvable2str(pool, s));
334           break;
335         case SOLVER_TRANSACTION_REINSTALL:
336           POOL_DEBUG(SAT_DEBUG_RESULT, "  reinstall %s", solvable2str(pool, s));
337           break;
338         case SOLVER_TRANSACTION_DOWNGRADE:
339           POOL_DEBUG(SAT_DEBUG_RESULT, "  downgrade %s", solvable2str(pool, s));
340           break;
341         case SOLVER_TRANSACTION_CHANGE:
342           POOL_DEBUG(SAT_DEBUG_RESULT, "  change    %s", solvable2str(pool, s));
343           break;
344         case SOLVER_TRANSACTION_UPGRADE:
345         case SOLVER_TRANSACTION_OBSOLETES:
346           POOL_DEBUG(SAT_DEBUG_RESULT, "  upgrade   %s", solvable2str(pool, s));
347           break;
348         case SOLVER_TRANSACTION_ERASE:
349           POOL_DEBUG(SAT_DEBUG_RESULT, "  erase     %s", solvable2str(pool, s));
350           break;
351         default:
352           break;
353         }
354       switch(type)
355         {
356         case SOLVER_TRANSACTION_INSTALL:
357         case SOLVER_TRANSACTION_ERASE:
358         case SOLVER_TRANSACTION_MULTIINSTALL:
359         case SOLVER_TRANSACTION_MULTIREINSTALL:
360           POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
361           break;
362         case SOLVER_TRANSACTION_REINSTALL:
363         case SOLVER_TRANSACTION_DOWNGRADE:
364         case SOLVER_TRANSACTION_CHANGE:
365         case SOLVER_TRANSACTION_UPGRADE:
366         case SOLVER_TRANSACTION_OBSOLETES:
367           transaction_all_obs_pkgs(&solv->trans, p, &iq);
368           if (iq.count)
369             {
370               POOL_DEBUG(SAT_DEBUG_RESULT, "  (obsoletes");
371               for (j = 0; j < iq.count; j++)
372                 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvid2str(pool, iq.elements[j]));
373               POOL_DEBUG(SAT_DEBUG_RESULT, ")");
374             }
375           POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
376           break;
377         default:
378           break;
379         }
380     }
381   queue_free(&iq);
382
383   POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
384
385   if (solv->recommendations.count)
386     {
387       POOL_DEBUG(SAT_DEBUG_RESULT, "recommended packages:\n");
388       for (i = 0; i < solv->recommendations.count; i++)
389         {
390           s = pool->solvables + solv->recommendations.elements[i];
391           if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
392             {
393               if (installed && s->repo == installed)
394                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (installed)\n", solvable2str(pool, s));
395               else
396                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (selected)\n", solvable2str(pool, s));
397             }
398           else
399             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s\n", solvable2str(pool, s));
400         }
401       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
402     }
403
404   if (solv->suggestions.count)
405     {
406       POOL_DEBUG(SAT_DEBUG_RESULT, "suggested packages:\n");
407       for (i = 0; i < solv->suggestions.count; i++)
408         {
409           s = pool->solvables + solv->suggestions.elements[i];
410           if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
411             {
412               if (installed && s->repo == installed)
413                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (installed)\n", solvable2str(pool, s));
414               else
415                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (selected)\n", solvable2str(pool, s));
416             }
417           else
418             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s\n", solvable2str(pool, s));
419         }
420       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
421     }
422   if (solv->orphaned.count)
423     {
424       POOL_DEBUG(SAT_DEBUG_RESULT, "orphaned packages:\n");
425       for (i = 0; i < solv->orphaned.count; i++)
426         {
427           s = pool->solvables + solv->orphaned.elements[i];
428           if (solv->decisionmap[solv->orphaned.elements[i]] > 0)
429             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (kept)\n", solvable2str(pool, s));
430           else
431             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (erased)\n", solvable2str(pool, s));
432         }
433       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
434     }
435 }
436
437 static inline
438 const char *id2strnone(Pool *pool, Id id)
439 {
440   return !id || id == 1 ? "(none)" : id2str(pool, id);
441 }
442
443 void
444 solver_printtransaction(Solver *solv)
445 {
446   Transaction *trans = &solv->trans;
447   Pool *pool = trans->pool;
448   Queue classes, pkgs;
449   int i, j, mode, l, linel;
450   char line[76];
451   const char *n;
452
453   queue_init(&classes);
454   queue_init(&pkgs);
455   mode = 0;
456   transaction_classify(trans, mode, &classes);
457   for (i = 0; i < classes.count; i += 4)
458     {
459       Id class = classes.elements[i];
460       Id cnt = classes.elements[i + 1];
461       switch(class)
462         {
463         case SOLVER_TRANSACTION_ERASE:
464           POOL_DEBUG(SAT_DEBUG_RESULT, "%d erased packages:\n", cnt);
465           break;
466         case SOLVER_TRANSACTION_INSTALL:
467           POOL_DEBUG(SAT_DEBUG_RESULT, "%d installed packages:\n", cnt);
468           break;
469         case SOLVER_TRANSACTION_REINSTALLED:
470           POOL_DEBUG(SAT_DEBUG_RESULT, "%d reinstalled packages:\n", cnt);
471           break;
472         case SOLVER_TRANSACTION_DOWNGRADED:
473           POOL_DEBUG(SAT_DEBUG_RESULT, "%d downgraded packages:\n", cnt);
474           break;
475         case SOLVER_TRANSACTION_CHANGED:
476           POOL_DEBUG(SAT_DEBUG_RESULT, "%d changed packages:\n", cnt);
477           break;
478         case SOLVER_TRANSACTION_UPGRADED:
479           POOL_DEBUG(SAT_DEBUG_RESULT, "%d upgraded packages:\n", cnt);
480           break;
481         case SOLVER_TRANSACTION_VENDORCHANGE:
482           POOL_DEBUG(SAT_DEBUG_RESULT, "%d vendor changes from '%s' to '%s':\n", cnt, id2strnone(pool, classes.elements[i + 2]), id2strnone(pool, classes.elements[i + 3]));
483           break;
484         case SOLVER_TRANSACTION_ARCHCHANGE:
485           POOL_DEBUG(SAT_DEBUG_RESULT, "%d arch changes from %s to %s:\n", cnt, id2str(pool, classes.elements[i + 2]), id2str(pool, classes.elements[i + 3]));
486           break;
487         default:
488           class = SOLVER_TRANSACTION_IGNORE;
489           break;
490         }
491       if (class == SOLVER_TRANSACTION_IGNORE)
492         continue;
493       transaction_classify_pkgs(trans, mode, class, classes.elements[i + 2], classes.elements[i + 3], &pkgs);
494       *line = 0;
495       linel = 0;
496       for (j = 0; j < pkgs.count; j++)
497         {
498           Id p = pkgs.elements[j];
499           Solvable *s = pool->solvables + p;
500           Solvable *s2;
501
502           switch(class)
503             {
504             case SOLVER_TRANSACTION_DOWNGRADED:
505             case SOLVER_TRANSACTION_UPGRADED:
506               s2 = pool->solvables + transaction_obs_pkg(trans, p);
507               POOL_DEBUG(SAT_DEBUG_RESULT, "  - %s -> %s\n", solvable2str(pool, s), solvable2str(pool, s2));
508               break;
509             case SOLVER_TRANSACTION_VENDORCHANGE:
510             case SOLVER_TRANSACTION_ARCHCHANGE:
511               n = id2str(pool, s->name);
512               l = strlen(n);
513               if (l + linel > sizeof(line) - 3)
514                 {
515                   if (*line)
516                     POOL_DEBUG(SAT_DEBUG_RESULT, "    %s\n", line);
517                   *line = 0;
518                   linel = 0;
519                 }
520               if (l + linel > sizeof(line) - 3)
521                 POOL_DEBUG(SAT_DEBUG_RESULT, "    %s\n", n);
522               else
523                 {
524                   if (*line)
525                     {
526                       strcpy(line + linel, ", ");
527                       linel += 2;
528                     }
529                   strcpy(line + linel, n);
530                   linel += l;
531                 }
532               break;
533             default:
534               POOL_DEBUG(SAT_DEBUG_RESULT, "  - %s\n", solvable2str(pool, s));
535               break;
536             }
537         }
538       if (*line)
539         POOL_DEBUG(SAT_DEBUG_RESULT, "    %s\n", line);
540       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
541     }
542   queue_free(&classes);
543   queue_free(&pkgs);
544 }
545
546 static void
547 solver_printproblemruleinfo(Solver *solv, Id probr)
548 {
549   Pool *pool = solv->pool;
550   Id dep, source, target;
551
552   switch (solver_ruleinfo(solv, probr, &source, &target, &dep))
553     {
554     case SOLVER_RULE_DISTUPGRADE:
555       POOL_DEBUG(SAT_DEBUG_RESULT, "%s does not belong to a distupgrade repository\n", solvid2str(pool, source));
556       return;
557     case SOLVER_RULE_INFARCH:
558       POOL_DEBUG(SAT_DEBUG_RESULT, "%s has inferior architecture\n", solvid2str(pool, source));
559       return;
560     case SOLVER_RULE_UPDATE:
561       POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvid2str(pool, source));
562       return;
563     case SOLVER_RULE_JOB:
564       POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
565       return;
566     case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
567       POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
568       return;
569     case SOLVER_RULE_RPM:
570       POOL_DEBUG(SAT_DEBUG_RESULT, "some dependency problem\n");
571       return;
572     case SOLVER_RULE_RPM_NOT_INSTALLABLE:
573       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvid2str(pool, source));
574       return;
575     case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
576       POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvid2str(pool, source));
577       return;
578     case SOLVER_RULE_RPM_SAME_NAME:
579       POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvid2str(pool, source), solvid2str(pool, target));
580       return;
581     case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
582       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvid2str(pool, source), dep2str(pool, dep), solvid2str(pool, target));
583       return;
584     case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
585       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvid2str(pool, source), dep2str(pool, dep), solvid2str(pool, target));
586       return;
587     case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
588       POOL_DEBUG(SAT_DEBUG_RESULT, "installed package %s obsoletes %s provided by %s\n", solvid2str(pool, source), dep2str(pool, dep), solvid2str(pool, target));
589       return;
590     case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES:
591       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s implicitely obsoletes %s provided by %s\n", solvid2str(pool, source), dep2str(pool, dep), solvid2str(pool, target));
592       return;
593     case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
594       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvid2str(pool, source), dep2str(pool, dep));
595       return;
596     case SOLVER_RULE_RPM_SELF_CONFLICT:
597       POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvid2str(pool, source), dep2str(pool, dep));
598       return;
599     case SOLVER_RULE_UNKNOWN:
600     case SOLVER_RULE_FEATURE:
601     case SOLVER_RULE_LEARNT:
602     case SOLVER_RULE_CHOICE:
603       POOL_DEBUG(SAT_DEBUG_RESULT, "bad rule type\n");
604       return;
605     }
606 }
607
608 void
609 solver_printprobleminfo(Solver *solv, Id problem)
610 {
611   solver_printproblemruleinfo(solv, solver_findproblemrule(solv, problem));
612 }
613
614 void
615 solver_printcompleteprobleminfo(Solver *solv, Id problem)
616 {
617   Queue q;
618   Id probr;
619   int i, nobad = 0;
620
621   queue_init(&q);
622   solver_findallproblemrules(solv, problem, &q);
623   for (i = 0; i < q.count; i++)
624     {
625       probr = q.elements[i];
626       if (!(probr >= solv->updaterules && probr < solv->updaterules_end) && !(probr >= solv->jobrules && probr < solv->jobrules_end))
627         {
628           nobad = 1;
629           break;
630         }
631     }
632   for (i = 0; i < q.count; i++)
633     {
634       probr = q.elements[i];
635       if (nobad && ((probr >= solv->updaterules && probr < solv->updaterules_end) || (probr >= solv->jobrules && probr < solv->jobrules_end)))
636         continue;
637       solver_printproblemruleinfo(solv, probr);
638     }
639   queue_free(&q);
640 }
641
642 void
643 solver_printsolution(Solver *solv, Id problem, Id solution)
644 {
645   Pool *pool = solv->pool;
646   Id p, rp, element, how, what, select;
647   Solvable *s, *sd;
648
649   element = 0;
650   while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
651     {
652       if (p == SOLVER_SOLUTION_JOB)
653         {
654           /* job, rp is index into job queue */
655           how = solv->job.elements[rp - 1];
656           what = solv->job.elements[rp];
657           select = how & SOLVER_SELECTMASK;
658           switch (how & SOLVER_JOBMASK)
659             {
660             case SOLVER_INSTALL:
661               if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
662                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not keep %s installed\n", solvid2str(pool, what));
663               else if (select == SOLVER_SOLVABLE_PROVIDES)
664                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not install a solvable %s\n", solver_select2str(solv, select, what));
665               else
666                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not install %s\n", solver_select2str(solv, select, what));
667               break;
668             case SOLVER_ERASE:
669               if (select == SOLVER_SOLVABLE && !(solv->installed && pool->solvables[what].repo == solv->installed))
670                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not forbid installation of %s\n", solvid2str(pool, what));
671               else if (select == SOLVER_SOLVABLE_PROVIDES)
672                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not deinstall all solvables %s\n", solver_select2str(solv, select, what));
673               else
674                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not deinstall %s\n", solver_select2str(solv, select, what));
675               break;
676             case SOLVER_UPDATE:
677               POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not install most recent version of %s\n", solver_select2str(solv, select, what));
678               break;
679             case SOLVER_LOCK:
680               POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not lock %s\n", solver_select2str(solv, select, what));
681               break;
682             default:
683               POOL_DEBUG(SAT_DEBUG_RESULT, "  - do something different\n");
684               break;
685             }
686         }
687       else if (p == SOLVER_SOLUTION_INFARCH)
688         {
689           s = pool->solvables + rp;
690           if (solv->installed && s->repo == solv->installed)
691             POOL_DEBUG(SAT_DEBUG_RESULT, "  - keep %s despite the inferior architecture\n", solvable2str(pool, s));
692           else
693             POOL_DEBUG(SAT_DEBUG_RESULT, "  - install %s despite the inferior architecture\n", solvable2str(pool, s));
694         }
695       else if (p == SOLVER_SOLUTION_DISTUPGRADE)
696         {
697           s = pool->solvables + rp;
698           if (solv->installed && s->repo == solv->installed)
699             POOL_DEBUG(SAT_DEBUG_RESULT, "  - keep obsolete %s\n", solvable2str(pool, s));
700           else
701             POOL_DEBUG(SAT_DEBUG_RESULT, "  - install %s from excluded repository\n", solvable2str(pool, s));
702         }
703       else
704         {
705           /* policy, replace p with rp */
706           s = pool->solvables + p;
707           sd = rp ? pool->solvables + rp : 0;
708           if (s == sd && solv->distupgrade)
709             {
710               POOL_DEBUG(SAT_DEBUG_RESULT, "  - keep obsolete %s\n", solvable2str(pool, s));
711             }
712           else if (sd)
713             {
714               int gotone = 0;
715               if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
716                 {
717                   POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
718                   gotone = 1;
719                 }
720               if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
721                 {
722                   POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
723                   gotone = 1;
724                 }
725               if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
726                 {
727                   if (sd->vendor)
728                     POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
729                   else
730                     POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
731                   gotone = 1;
732                 }
733               if (!gotone)
734                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
735             }
736           else
737             {
738               POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow deinstallation of %s\n", solvable2str(pool, s));
739             }
740
741         }
742     }
743 }
744
745 void
746 solver_printallsolutions(Solver *solv)
747 {
748   Pool *pool = solv->pool;
749   int pcnt;
750   Id problem, solution;
751
752   POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
753   pcnt = 0;
754   problem = 0;
755   while ((problem = solver_next_problem(solv, problem)) != 0)
756     {
757       pcnt++;
758       POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt);
759       POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
760 #if 1
761       solver_printprobleminfo(solv, problem);
762 #else
763       solver_printcompleteprobleminfo(solv, problem);
764 #endif
765       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
766       solution = 0;
767       while ((solution = solver_next_solution(solv, problem, solution)) != 0)
768         {
769           solver_printsolution(solv, problem, solution);
770           POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
771         }
772     }
773 }
774
775 void
776 solver_printtrivial(Solver *solv)
777 {
778   Pool *pool = solv->pool;
779   Queue in, out;
780   Id p;
781   const char *n; 
782   Solvable *s; 
783   int i;
784
785   queue_init(&in);
786   for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
787     {   
788       n = id2str(pool, s->name);
789       if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
790         continue;
791       queue_push(&in, p); 
792     }   
793   if (!in.count)
794     {
795       queue_free(&in);
796       return;
797     }
798   queue_init(&out);
799   solver_trivial_installable(solv, &in, &out);
800   POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n");
801   for (i = 0; i < in.count; i++)
802     POOL_DEBUG(SAT_DEBUG_RESULT, "  %s: %d\n", solvid2str(pool, in.elements[i]), out.elements[i]);
803   POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
804   queue_free(&in);
805   queue_free(&out);
806 }
807
808 const char *
809 solver_select2str(Solver *solv, Id select, Id what)
810 {
811   Pool *pool = solv->pool;
812   const char *s;
813   char *b;
814   if (select == SOLVER_SOLVABLE)
815     return solvid2str(pool, what);
816   if (select == SOLVER_SOLVABLE_NAME)
817     return dep2str(pool, what);
818   if (select == SOLVER_SOLVABLE_PROVIDES)
819     {
820       s = dep2str(pool, what);
821       b = pool_alloctmpspace(pool, 11 + strlen(s));
822       sprintf(b, "providing %s", s);
823       return b;
824     }
825   if (select == SOLVER_SOLVABLE_ONE_OF)
826     {
827       Id p;
828       char *b2;
829       b = "";
830       while ((p = pool->whatprovidesdata[what++]) != 0)
831         {
832           s = solvid2str(pool, p);
833           b2 = pool_alloctmpspace(pool, strlen(b) + strlen(s) + 3);
834           sprintf(b2, "%s, %s", b, s);
835           b = b2;
836         }
837       return *b ? b + 2 : "nothing";
838     }
839   if (select == SOLVER_SOLVABLE_REPO)
840     {
841       b = pool_alloctmpspace(pool, 20);
842       sprintf(b, "repo #%d", what);
843       return b;
844     }
845   return "unknown job select";
846 }