- do not use obsolete interface in libsolv library itself
[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]", pool_solvable2str(pool, s), -v);
133     }
134   else
135     {
136       s = pool->solvables + v;
137       POOL_DEBUG(type, "    %s [%d]", pool_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], pool_solvid2str(pool, p));
272       else
273         POOL_DEBUG(type, "%d %d conflict %s, ", i, -solv->decisionmap[-p], pool_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", pool_solvable2str(pool, s));
328           break;
329         case SOLVER_TRANSACTION_MULTIREINSTALL:
330           POOL_DEBUG(SAT_DEBUG_RESULT, "  multi reinstall %s", pool_solvable2str(pool, s));
331           break;
332         case SOLVER_TRANSACTION_INSTALL:
333           POOL_DEBUG(SAT_DEBUG_RESULT, "  install   %s", pool_solvable2str(pool, s));
334           break;
335         case SOLVER_TRANSACTION_REINSTALL:
336           POOL_DEBUG(SAT_DEBUG_RESULT, "  reinstall %s", pool_solvable2str(pool, s));
337           break;
338         case SOLVER_TRANSACTION_DOWNGRADE:
339           POOL_DEBUG(SAT_DEBUG_RESULT, "  downgrade %s", pool_solvable2str(pool, s));
340           break;
341         case SOLVER_TRANSACTION_CHANGE:
342           POOL_DEBUG(SAT_DEBUG_RESULT, "  change    %s", pool_solvable2str(pool, s));
343           break;
344         case SOLVER_TRANSACTION_UPGRADE:
345         case SOLVER_TRANSACTION_OBSOLETES:
346           POOL_DEBUG(SAT_DEBUG_RESULT, "  upgrade   %s", pool_solvable2str(pool, s));
347           break;
348         case SOLVER_TRANSACTION_ERASE:
349           POOL_DEBUG(SAT_DEBUG_RESULT, "  erase     %s", pool_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", pool_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", pool_solvable2str(pool, s));
395               else
396                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (selected)\n", pool_solvable2str(pool, s));
397             }
398           else
399             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s\n", pool_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", pool_solvable2str(pool, s));
414               else
415                 POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (selected)\n", pool_solvable2str(pool, s));
416             }
417           else
418             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s\n", pool_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", pool_solvable2str(pool, s));
430           else
431             POOL_DEBUG(SAT_DEBUG_RESULT, "  %s (erased)\n", pool_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)" : pool_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, pool_id2str(pool, classes.elements[i + 2]), pool_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", pool_solvable2str(pool, s), pool_solvable2str(pool, s2));
508               break;
509             case SOLVER_TRANSACTION_VENDORCHANGE:
510             case SOLVER_TRANSACTION_ARCHCHANGE:
511               n = pool_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", pool_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 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", pool_solvid2str(pool, source));
556       return;
557     case SOLVER_RULE_INFARCH:
558       POOL_DEBUG(SAT_DEBUG_RESULT, "%s has inferior architecture\n", pool_solvid2str(pool, source));
559       return;
560     case SOLVER_RULE_UPDATE:
561       POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", pool_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", pool_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", pool_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", pool_dep2str(pool, dep), pool_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", pool_solvid2str(pool, source), pool_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", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_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", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_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", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_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", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_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", pool_solvid2str(pool, source), pool_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", pool_solvid2str(pool, source), pool_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", pool_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(pool, select, what));
665               else
666                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not install %s\n", solver_select2str(pool, 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", pool_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(pool, select, what));
673               else
674                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not deinstall %s\n", solver_select2str(pool, 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(pool, select, what));
678               break;
679             case SOLVER_LOCK:
680               POOL_DEBUG(SAT_DEBUG_RESULT, "  - do not lock %s\n", solver_select2str(pool, 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", pool_solvable2str(pool, s));
692           else
693             POOL_DEBUG(SAT_DEBUG_RESULT, "  - install %s despite the inferior architecture\n", pool_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", pool_solvable2str(pool, s));
700           else
701             POOL_DEBUG(SAT_DEBUG_RESULT, "  - install %s from excluded repository\n", pool_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 (sd)
709             {
710               int illegal = policy_is_illegal(solv, s, sd, 0);
711               if ((illegal & POLICY_ILLEGAL_DOWNGRADE) != 0)
712                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow downgrade of %s to %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
713               if ((illegal & POLICY_ILLEGAL_ARCHCHANGE) != 0)
714                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow architecture change of %s to %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
715               if ((illegal & POLICY_ILLEGAL_VENDORCHANGE) != 0)
716                 {
717                   if (sd->vendor)
718                     POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow vendor change from '%s' (%s) to '%s' (%s)\n", pool_id2str(pool, s->vendor), pool_solvable2str(pool, s), pool_id2str(pool, sd->vendor), pool_solvable2str(pool, sd));
719                   else
720                     POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow vendor change from '%s' (%s) to no vendor (%s)\n", pool_id2str(pool, s->vendor), pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
721                 }
722               if (!illegal)
723                 POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow replacement of %s with %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, sd));
724             }
725           else
726             {
727               POOL_DEBUG(SAT_DEBUG_RESULT, "  - allow deinstallation of %s\n", pool_solvable2str(pool, s));
728             }
729         }
730     }
731 }
732
733 void
734 solver_printallsolutions(Solver *solv)
735 {
736   Pool *pool = solv->pool;
737   int pcnt;
738   Id problem, solution;
739
740   POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
741   pcnt = 0;
742   problem = 0;
743   while ((problem = solver_next_problem(solv, problem)) != 0)
744     {
745       pcnt++;
746       POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt);
747       POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
748 #if 1
749       solver_printprobleminfo(solv, problem);
750 #else
751       solver_printcompleteprobleminfo(solv, problem);
752 #endif
753       POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
754       solution = 0;
755       while ((solution = solver_next_solution(solv, problem, solution)) != 0)
756         {
757           solver_printsolution(solv, problem, solution);
758           POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
759         }
760     }
761 }
762
763 void
764 solver_printtrivial(Solver *solv)
765 {
766   Pool *pool = solv->pool;
767   Queue in, out;
768   Id p;
769   const char *n; 
770   Solvable *s; 
771   int i;
772
773   queue_init(&in);
774   for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
775     {   
776       n = pool_id2str(pool, s->name);
777       if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
778         continue;
779       queue_push(&in, p); 
780     }   
781   if (!in.count)
782     {
783       queue_free(&in);
784       return;
785     }
786   queue_init(&out);
787   solver_trivial_installable(solv, &in, &out);
788   POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n");
789   for (i = 0; i < in.count; i++)
790     POOL_DEBUG(SAT_DEBUG_RESULT, "  %s: %d\n", pool_solvid2str(pool, in.elements[i]), out.elements[i]);
791   POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
792   queue_free(&in);
793   queue_free(&out);
794 }
795
796 const char *
797 solver_select2str(Pool *pool, Id select, Id what)
798 {
799   const char *s;
800   char *b;
801   if (select == SOLVER_SOLVABLE)
802     return pool_solvid2str(pool, what);
803   if (select == SOLVER_SOLVABLE_NAME)
804     return pool_dep2str(pool, what);
805   if (select == SOLVER_SOLVABLE_PROVIDES)
806     {
807       s = pool_dep2str(pool, what);
808       b = pool_alloctmpspace(pool, 11 + strlen(s));
809       sprintf(b, "providing %s", s);
810       return b;
811     }
812   if (select == SOLVER_SOLVABLE_ONE_OF)
813     {
814       Id p;
815       b = 0;
816       while ((p = pool->whatprovidesdata[what++]) != 0)
817         {
818           s = pool_solvid2str(pool, p);
819           if (b)
820             b = pool_tmpappend(pool, b, ", ", s);
821           else
822             b = pool_tmpjoin(pool, s, 0, 0);
823           pool_freetmpspace(pool, s);
824         }
825       return b ? b : "nothing";
826     }
827   if (select == SOLVER_SOLVABLE_REPO)
828     {
829       b = pool_alloctmpspace(pool, 20);
830       sprintf(b, "repo #%d", what);
831       return b;
832     }
833   if (select == SOLVER_SOLVABLE_ALL)
834     return "all packages";
835   return "unknown job select";
836 }
837
838 const char *
839 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
840 {
841   Id select = how & SOLVER_SELECTMASK;
842   const char *strstart = 0, *strend = 0;
843   char *s;
844   int o;
845
846   switch (how & SOLVER_JOBMASK)
847     {
848     case SOLVER_NOOP:
849       return "do nothing";
850     case SOLVER_INSTALL:
851       if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
852         strstart = "keep ", strend = "installed";
853       else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
854         strstart = "install ";
855       else if (select == SOLVER_SOLVABLE_PROVIDES)
856         strstart = "install a package ";
857       else
858         strstart = "install one of ";
859       break;
860     case SOLVER_ERASE:
861       if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
862         strstart = "keep ", strend = "unstalled";
863       else if (select == SOLVER_SOLVABLE_PROVIDES)
864         strstart = "deinstall all packages ";
865       else
866         strstart = "deinstall ";
867       break;
868     case SOLVER_UPDATE:
869       strstart = "update ";
870       break;
871     case SOLVER_WEAKENDEPS:
872       strstart = "weaken deps of ";
873       break;
874     case SOLVER_NOOBSOLETES:
875       strstart = "multi version ";
876       break;
877     case SOLVER_LOCK:
878       strstart = "update ";
879       break;
880     case SOLVER_DISTUPGRADE:
881       strstart = "dist upgrade ";
882       break;
883     case SOLVER_VERIFY:
884       strstart = "verify ";
885       break;
886     case SOLVER_DROP_ORPHANED:
887       strstart = "deinstall ", strend = "if orphaned";
888       break;
889     case SOLVER_USERINSTALLED:
890       strstart = "regard ", strend = "as userinstalled";
891       break;
892     default:
893       strstart = "unknown job ";
894       break;
895     }
896   s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
897   if ((how & flagmask & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
898     return s;
899   o = strlen(s);
900   s = pool_tmpappend(pool, s, " ", 0);
901   if (how & SOLVER_WEAK)
902     s = pool_tmpappend(pool, s, ",weak", 0);
903   if (how & SOLVER_ESSENTIAL)
904     s = pool_tmpappend(pool, s, ",essential", 0);
905   if (how & SOLVER_CLEANDEPS)
906     s = pool_tmpappend(pool, s, ",cleandeps", 0);
907   if (how & SOLVER_SETEV)
908     s = pool_tmpappend(pool, s, ",setev", 0);
909   if (how & SOLVER_SETEVR)
910     s = pool_tmpappend(pool, s, ",setevr", 0);
911   if (how & SOLVER_SETARCH)
912     s = pool_tmpappend(pool, s, ",setarch", 0);
913   if (how & SOLVER_SETVENDOR)
914     s = pool_tmpappend(pool, s, ",setvendor", 0);
915   if (how & SOLVER_SETREPO)
916     s = pool_tmpappend(pool, s, ",setrepo", 0);
917   if (how & SOLVER_NOAUTOSET)
918     s = pool_tmpappend(pool, s, ",noautoset", 0);
919   if (s[o + 1] != ',')
920     s = pool_tmpappend(pool, s, ",?", 0);
921   s[o + 1] = '[';
922   return pool_tmpappend(pool, s, "]", 0);
923 }
924
925 const char *
926 solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep)
927 {
928   Pool *pool = solv->pool;
929   char *s;
930   switch (type)
931     {
932     case SOLVER_RULE_DISTUPGRADE:
933       return pool_tmpjoin(pool, pool_solvid2str(pool, source), " does not belong to a distupgrade repository", 0);
934     case SOLVER_RULE_INFARCH:
935       return pool_tmpjoin(pool, pool_solvid2str(pool, source), " has inferior architecture", 0);
936     case SOLVER_RULE_UPDATE:
937       return pool_tmpjoin(pool, "problem with installed package ", pool_solvid2str(pool, source), 0);
938     case SOLVER_RULE_JOB:
939       return "conflicting requests";
940     case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
941       return pool_tmpjoin(pool, "nothing provides requested ", pool_dep2str(pool, dep), 0);
942     case SOLVER_RULE_RPM:
943       return "some dependency problem";
944     case SOLVER_RULE_RPM_NOT_INSTALLABLE:
945       return pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " is not installable");
946     case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
947       s = pool_tmpjoin(pool, "nothing provides ", pool_dep2str(pool, dep), 0);
948       return pool_tmpappend(pool, s, " needed by ", pool_solvid2str(pool, source));
949     case SOLVER_RULE_RPM_SAME_NAME:
950       s = pool_tmpjoin(pool, "cannot install both ", pool_solvid2str(pool, source), 0);
951       return pool_tmpappend(pool, s, " and ", pool_solvid2str(pool, target));
952     case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
953       s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
954       s = pool_tmpappend(pool, s, " conflicts with ", pool_dep2str(pool, dep));
955       return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
956     case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
957       s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
958       s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
959       return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
960     case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
961       s = pool_tmpjoin(pool, "installed package ", pool_solvid2str(pool, source), 0);
962       s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
963       return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
964     case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES:
965       s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
966       s = pool_tmpappend(pool, s, " implicitely obsoletes ", pool_dep2str(pool, dep));
967       return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
968     case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
969       s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " requires ");
970       return pool_tmpappend(pool, s, pool_dep2str(pool, dep), ", but none of the providers can be installed");
971     case SOLVER_RULE_RPM_SELF_CONFLICT:
972       s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " conflicts with ");
973       return pool_tmpappend(pool, s, pool_dep2str(pool, dep), " provided by itself");
974     default:
975       return "bad problem rule type";
976     }
977 }
978
979 const char *
980 solver_solutionelement2str(Solver *solv, Id p, Id rp)
981 {
982   Pool *pool = solv->pool;
983   if (p == SOLVER_SOLUTION_JOB)
984     {
985       Id how = solv->job.elements[rp - 1];
986       Id what = solv->job.elements[rp];
987       return pool_tmpjoin(pool, "do not ask to ", pool_job2str(pool, how, what, 0), 0);
988     }
989   else if (p == SOLVER_SOLUTION_INFARCH)
990     {
991       Solvable *s = pool->solvables + rp;
992       if (solv->installed && s->repo == solv->installed)
993         return pool_tmpjoin(pool, "keep ", pool_solvable2str(pool, s), " despite the inferior architecture");
994       else
995         return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " despite the inferior architecture");
996     }
997   else if (p == SOLVER_SOLUTION_DISTUPGRADE)
998     {
999       Solvable *s = pool->solvables + rp;
1000       if (solv->installed && s->repo == solv->installed)
1001         return pool_tmpjoin(pool, "keep obsolete ", pool_solvable2str(pool, s), 0);
1002       else
1003         return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " from excluded repository");
1004     }
1005   else if (p > 0 && rp == 0)
1006     return pool_tmpjoin(pool, "allow deinstallation of ", pool_solvid2str(pool, p), 0);
1007   else if (p > 0 && rp > 0)
1008     {
1009       const char *sp = pool_solvid2str(pool, p);
1010       const char *srp = pool_solvid2str(pool, rp);
1011       const char *str = pool_tmpjoin(pool, "allow replacement of ", sp, 0);
1012       return pool_tmpappend(pool, str, " with ", srp);
1013     }
1014   else
1015     return "bad solution element";
1016 }
1017
1018 const char *
1019 policy_illegal2str(Solver *solv, int illegal, Solvable *s, Solvable *rs)
1020 {
1021   Pool *pool = solv->pool;
1022   const char *str;
1023   if (illegal == POLICY_ILLEGAL_DOWNGRADE)
1024     {
1025       str = pool_tmpjoin(pool, "downgrade of ", pool_solvable2str(pool, s), 0);
1026       return pool_tmpappend(pool, str, " to ", pool_solvable2str(pool, rs));
1027     }
1028   if (illegal == POLICY_ILLEGAL_ARCHCHANGE)
1029     {
1030       str = pool_tmpjoin(pool, "architecture change of ", pool_solvable2str(pool, s), 0);
1031       return pool_tmpappend(pool, str, " to ", pool_solvable2str(pool, rs));
1032     }
1033   if (illegal == POLICY_ILLEGAL_VENDORCHANGE)
1034     {
1035       str = pool_tmpjoin(pool, "vendor change from '", pool_id2str(pool, s->vendor), "' (");
1036       if (rs->vendor)
1037         {
1038           str = pool_tmpappend(pool, str, pool_solvable2str(pool, s), ") to '");
1039           str = pool_tmpappend(pool, str, pool_id2str(pool, rs->vendor), "' (");
1040         }
1041       else
1042         str = pool_tmpappend(pool, str, pool_solvable2str(pool, s), ") to no vendor (");
1043       return pool_tmpappend(pool, str, pool_solvable2str(pool, rs), ")");
1044     }
1045   return "unknown illegal change";
1046 }