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)
64 if (s->name == pool->solvables[p].name)
66 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
73 for (i = 0; i < solv->decisionq.count; i++)
78 n = solv->decisionq.elements[i];
81 if (n == SYSTEMSOLVABLE)
83 s = pool->solvables + n;
84 if (s->repo == installed) /* obsoletes don't count for already installed packages */
88 obsp = s->repo->idarraydata + s->obsoletes;
89 while ((obs = *obsp++) != 0)
90 FOR_PROVIDES(p, pp, obs)
92 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
104 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
106 Pool *pool = solv->pool;
110 s = pool->solvables + -v;
111 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
115 s = pool->solvables + v;
116 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
121 POOL_DEBUG(type, " (w1)");
123 POOL_DEBUG(type, " (w2)");
125 if (solv->decisionmap[s - pool->solvables] > 0)
126 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
127 if (solv->decisionmap[s - pool->solvables] < 0)
128 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
129 POOL_DEBUG(type, "\n");
138 solver_printrule(Solver *solv, int type, Rule *r)
140 Pool *pool = solv->pool;
144 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
145 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
147 POOL_DEBUG(type, "Rule:"); /* r is any rule */
149 POOL_DEBUG(type, " (disabled)");
150 POOL_DEBUG(type, "\n");
154 /* print direct literal */
156 else if (r->d == ID_NULL)
160 /* binary rule --> print w2 as second literal */
164 /* every other which is in d */
165 v = solv->pool->whatprovidesdata[r->d + i - 1];
168 solver_printruleelement(solv, type, r, v);
170 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
174 solver_printruleclass(Solver *solv, int type, Rule *r)
176 Pool *pool = solv->pool;
177 Id p = r - solv->rules;
179 if (p < solv->learntrules)
180 if (MAPTST(&solv->weakrulemap, p))
181 POOL_DEBUG(type, "WEAK ");
182 if (p >= solv->learntrules)
183 POOL_DEBUG(type, "LEARNT ");
184 else if (p >= solv->featurerules)
185 POOL_DEBUG(type, "FEATURE ");
186 else if (p >= solv->updaterules)
187 POOL_DEBUG(type, "UPDATE ");
188 else if (p >= solv->jobrules)
189 POOL_DEBUG(type, "JOB ");
190 solver_printrule(solv, type, r);
194 solver_printproblem(Solver *solv, Id v)
196 Pool *pool = solv->pool;
202 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
206 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
207 jp = solv->ruletojob.elements;
208 for (i = solv->jobrules, r = solv->rules + i; i < solv->updaterules; i++, r++, jp++)
211 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
212 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
214 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
219 solver_printwatches(Solver *solv, int type)
221 Pool *pool = solv->pool;
224 POOL_DEBUG(type, "Watches: \n");
225 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
226 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
234 solver_printdecisions(Solver *solv)
236 Pool *pool = solv->pool;
237 Repo *installed = solv->installed;
238 Id p, *obsoletesmap = solver_create_decisions_obsoletesmap(solv);
242 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
244 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
245 for (i = 0; i < solv->decisionq.count; i++)
247 p = solv->decisionq.elements[i];
248 solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
250 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
253 /* print solvables to be erased */
257 FOR_REPO_SOLVABLES(installed, p, s)
259 if (solv->decisionmap[p] >= 0)
263 POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s));
267 /* print solvables to be installed */
269 for (i = 0; i < solv->decisionq.count; i++)
272 p = solv->decisionq.elements[i];
275 if (p == SYSTEMSOLVABLE)
277 s = pool->solvables + p;
278 if (installed && s->repo == installed)
281 if (!obsoletesmap[p])
283 POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
288 FOR_PROVIDES(xp, xpp, s->name)
290 Solvable *s2 = pool->solvables + xp;
291 if (s2->name != s->name)
293 if (evrcmp(pool, s->evr, s2->evr, EVRCMP_MATCH_RELEASE) < 0)
297 POOL_DEBUG(SAT_DEBUG_RESULT, "downgrade %s", solvable2str(pool, s));
299 POOL_DEBUG(SAT_DEBUG_RESULT, "upgrade %s", solvable2str(pool, s));
300 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
301 for (j = installed->start; j < installed->end; j++)
302 if (obsoletesmap[j] == p)
303 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
304 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
306 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
309 sat_free(obsoletesmap);
311 if (solv->recommendations.count)
313 POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
314 for (i = 0; i < solv->recommendations.count; i++)
316 s = pool->solvables + solv->recommendations.elements[i];
317 if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
319 if (installed && s->repo == installed)
320 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s));
322 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s));
325 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
329 if (solv->suggestions.count)
331 POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
332 for (i = 0; i < solv->suggestions.count; i++)
334 s = pool->solvables + solv->suggestions.elements[i];
335 if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
337 if (installed && s->repo == installed)
338 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s));
340 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s));
343 POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
349 solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
351 Pool *pool = solv->pool;
353 Id dep, source, target;
356 probr = solver_findproblemrule(solv, problem);
357 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
359 case SOLVER_PROBLEM_UPDATE_RULE:
360 s = pool_id2solvable(pool, source);
361 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
363 case SOLVER_PROBLEM_JOB_RULE:
364 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
366 case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
367 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
369 case SOLVER_PROBLEM_NOT_INSTALLABLE:
370 s = pool_id2solvable(pool, source);
371 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
373 case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
374 s = pool_id2solvable(pool, source);
375 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
377 case SOLVER_PROBLEM_SAME_NAME:
378 s = pool_id2solvable(pool, source);
379 s2 = pool_id2solvable(pool, target);
380 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
382 case SOLVER_PROBLEM_PACKAGE_CONFLICT:
383 s = pool_id2solvable(pool, source);
384 s2 = pool_id2solvable(pool, target);
385 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
387 case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
388 s = pool_id2solvable(pool, source);
389 s2 = pool_id2solvable(pool, target);
390 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
392 case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
393 s = pool_id2solvable(pool, source);
394 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
396 case SOLVER_PROBLEM_SELF_CONFLICT:
397 s = pool_id2solvable(pool, source);
398 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
404 solver_printsolutions(Solver *solv, Queue *job)
406 Pool *pool = solv->pool;
409 Id problem, solution, element;
412 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
415 while ((problem = solver_next_problem(solv, problem)) != 0)
417 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
418 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
419 solver_printprobleminfo(solv, job, problem);
420 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
422 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
425 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
429 /* job, rp is index into job queue */
430 how = job->elements[rp - 1] & ~SOLVER_WEAK;
431 what = job->elements[rp];
434 case SOLVER_INSTALL_SOLVABLE:
435 s = pool->solvables + what;
436 if (solv->installed && s->repo == solv->installed)
437 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
439 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
441 case SOLVER_ERASE_SOLVABLE:
442 s = pool->solvables + what;
443 if (solv->installed && s->repo == solv->installed)
444 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
446 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
448 case SOLVER_INSTALL_SOLVABLE_NAME:
449 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
451 case SOLVER_ERASE_SOLVABLE_NAME:
452 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
454 case SOLVER_INSTALL_SOLVABLE_PROVIDES:
455 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
457 case SOLVER_ERASE_SOLVABLE_PROVIDES:
458 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
460 case SOLVER_INSTALL_SOLVABLE_UPDATE:
461 s = pool->solvables + what;
462 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
465 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
471 /* policy, replace p with rp */
472 s = pool->solvables + p;
473 sd = rp ? pool->solvables + rp : 0;
477 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
479 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
482 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
484 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
487 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
490 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));
492 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));
496 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
500 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
505 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");