2 * Copyright (c) 2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * debug functions for the SAT solver
29 * create obsoletesmap from solver decisions
31 * for solvables in installed repo:
33 * p - one of the packages that obsolete us
35 * n - number of packages this package obsoletes
40 solver_create_decisions_obsoletesmap(Solver *solv)
42 Pool *pool = solv->pool;
43 Repo *installed = solv->installed;
44 Id p, *obsoletesmap = NULL;
48 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
51 for (i = 0; i < solv->decisionq.count; i++)
55 n = solv->decisionq.elements[i];
58 if (n == SYSTEMSOLVABLE)
60 s = pool->solvables + n;
61 if (s->repo == installed) /* obsoletes don't count for already installed packages */
63 FOR_PROVIDES(p, pp, s->name)
65 if (!solv->implicitobsoleteusesprovides && s->name != pool->solvables[p].name)
67 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
74 for (i = 0; i < solv->decisionq.count; i++)
79 n = solv->decisionq.elements[i];
82 if (n == SYSTEMSOLVABLE)
84 s = pool->solvables + n;
85 if (s->repo == installed) /* obsoletes don't count for already installed packages */
89 obsp = s->repo->idarraydata + s->obsoletes;
90 while ((obs = *obsp++) != 0)
92 FOR_PROVIDES(p, pp, obs)
94 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
96 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
109 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
111 Pool *pool = solv->pool;
115 s = pool->solvables + -v;
116 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
120 s = pool->solvables + v;
121 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
126 POOL_DEBUG(type, " (w1)");
128 POOL_DEBUG(type, " (w2)");
130 if (solv->decisionmap[s - pool->solvables] > 0)
131 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
132 if (solv->decisionmap[s - pool->solvables] < 0)
133 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
134 POOL_DEBUG(type, "\n");
143 solver_printrule(Solver *solv, int type, Rule *r)
145 Pool *pool = solv->pool;
149 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
150 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
152 POOL_DEBUG(type, "Rule:"); /* r is any rule */
154 POOL_DEBUG(type, " (disabled)");
155 POOL_DEBUG(type, "\n");
156 d = r->d < 0 ? -r->d - 1 : r->d;
160 /* print direct literal */
166 /* binary rule --> print w2 as second literal */
170 /* every other which is in d */
171 v = solv->pool->whatprovidesdata[d + i - 1];
174 solver_printruleelement(solv, type, r, v);
176 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
180 solver_printruleclass(Solver *solv, int type, Rule *r)
182 Pool *pool = solv->pool;
183 Id p = r - solv->rules;
185 if (p < solv->learntrules)
186 if (MAPTST(&solv->weakrulemap, p))
187 POOL_DEBUG(type, "WEAK ");
188 if (p >= solv->learntrules)
189 POOL_DEBUG(type, "LEARNT ");
190 else if (p >= solv->jobrules && p < solv->jobrules_end)
191 POOL_DEBUG(type, "JOB ");
192 else if (p >= solv->updaterules && p < solv->updaterules_end)
193 POOL_DEBUG(type, "UPDATE ");
194 else if (p >= solv->featurerules && p < solv->featurerules_end)
195 POOL_DEBUG(type, "FEATURE ");
196 solver_printrule(solv, type, r);
200 solver_printproblem(Solver *solv, Id v)
202 Pool *pool = solv->pool;
208 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
212 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
213 jp = solv->ruletojob.elements;
214 for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++, jp++)
217 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
218 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
220 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
225 solver_printwatches(Solver *solv, int type)
227 Pool *pool = solv->pool;
230 POOL_DEBUG(type, "Watches: \n");
231 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
232 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
240 solver_printdecisions(Solver *solv)
242 Pool *pool = solv->pool;
243 Repo *installed = solv->installed;
244 Id p, *obsoletesmap = solver_create_decisions_obsoletesmap(solv);
248 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
250 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
251 for (i = 0; i < solv->decisionq.count; i++)
253 p = solv->decisionq.elements[i];
254 solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
256 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
259 /* print solvables to be erased */
263 FOR_REPO_SOLVABLES(installed, p, s)
265 if (solv->decisionmap[p] >= 0)
269 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
273 /* print solvables to be installed */
275 for (i = 0; i < solv->decisionq.count; i++)
278 p = solv->decisionq.elements[i];
281 if (p == SYSTEMSOLVABLE)
283 s = pool->solvables + p;
284 if (installed && s->repo == installed)
287 if (!obsoletesmap[p])
289 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
294 FOR_PROVIDES(xp, xpp, s->name)
296 Solvable *s2 = pool->solvables + xp;
297 if (s2->name != s->name)
299 if (evrcmp(pool, s->evr, s2->evr, EVRCMP_MATCH_RELEASE) < 0)
303 POOL_DEBUG(SAT_DEBUG_RESULT, "downgrade %s", solvable2str(pool, s));
305 POOL_DEBUG(SAT_DEBUG_RESULT, "upgrade %s", solvable2str(pool, s));
306 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
307 for (j = installed->start; j < installed->end; j++)
308 if (obsoletesmap[j] == p)
309 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
310 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
312 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
315 sat_free(obsoletesmap);
317 if (solv->recommendations.count)
319 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
320 for (i = 0; i < solv->recommendations.count; i++)
322 s = pool->solvables + solv->recommendations.elements[i];
323 if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
325 if (installed && s->repo == installed)
326 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s));
328 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s));
331 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
335 if (solv->suggestions.count)
337 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
338 for (i = 0; i < solv->suggestions.count; i++)
340 s = pool->solvables + solv->suggestions.elements[i];
341 if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
343 if (installed && s->repo == installed)
344 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s));
346 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s));
349 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
355 solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
357 Pool *pool = solv->pool;
359 Id dep, source, target;
362 probr = solver_findproblemrule(solv, problem);
363 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
365 case SOLVER_PROBLEM_UPDATE_RULE:
366 s = pool_id2solvable(pool, source);
367 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
369 case SOLVER_PROBLEM_JOB_RULE:
370 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
372 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
373 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
375 case SOLVER_PROBLEM_NOT_INSTALLABLE:
376 s = pool_id2solvable(pool, source);
377 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
379 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
380 s = pool_id2solvable(pool, source);
381 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
383 case SOLVER_PROBLEM_SAME_NAME:
384 s = pool_id2solvable(pool, source);
385 s2 = pool_id2solvable(pool, target);
386 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
388 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
389 s = pool_id2solvable(pool, source);
390 s2 = pool_id2solvable(pool, target);
391 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
393 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
394 s = pool_id2solvable(pool, source);
395 s2 = pool_id2solvable(pool, target);
396 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
398 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
399 s = pool_id2solvable(pool, source);
400 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
402 case SOLVER_PROBLEM_SELF_CONFLICT:
403 s = pool_id2solvable(pool, source);
404 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
410 solver_printsolutions(Solver *solv, Queue *job)
412 Pool *pool = solv->pool;
415 Id problem, solution, element;
418 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
421 while ((problem = solver_next_problem(solv, problem)) != 0)
423 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
424 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
425 solver_printprobleminfo(solv, job, problem);
426 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
428 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
431 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
435 /* job, rp is index into job queue */
436 how = job->elements[rp - 1] & ~SOLVER_WEAK;
437 what = job->elements[rp];
440 case SOLVER_INSTALL_SOLVABLE:
441 s = pool->solvables + what;
442 if (solv->installed && s->repo == solv->installed)
443 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
445 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
447 case SOLVER_ERASE_SOLVABLE:
448 s = pool->solvables + what;
449 if (solv->installed && s->repo == solv->installed)
450 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
452 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
454 case SOLVER_INSTALL_SOLVABLE_NAME:
455 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
457 case SOLVER_ERASE_SOLVABLE_NAME:
458 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
460 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
461 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
463 case SOLVER_ERASE_SOLVABLE_PROVIDES:
464 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
466 case SOLVER_INSTALL_SOLVABLE_UPDATE:
467 s = pool->solvables + what;
468 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
471 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
477 /* policy, replace p with rp */
478 s = pool->solvables + p;
479 sd = rp ? pool->solvables + rp : 0;
483 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
485 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
488 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
490 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
493 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
496 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));
498 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));
502 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
506 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
511 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");