#include <assert.h>
#include "solver.h"
+#include "solver_private.h"
#include "bitmap.h"
#include "pool.h"
#include "util.h"
#include "policy.h"
+#include "poolarch.h"
#include "solverdebug.h"
#define RULES_BLOCK 63
/*-------------------------------------------------------------------
* handle split provides
+ *
+ * a splitprovides dep looks like
+ * namespace:splitprovides(pkg REL_WITH path)
+ * and is only true if pkg is installed and contains the specified path.
+ * we also make sure that pkg is selected for an update, otherwise the
+ * update would always be forced onto the user.
*/
-
int
solver_splitprovides(Solver *solv, Id dep)
{
Reldep *rd;
Solvable *s;
- if (!solv->dosplitprovides || !solv->installed)
+ if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
return 0;
if (!ISRELDEP(dep))
return 0;
return 0;
FOR_PROVIDES(p, pp, dep)
{
+ /* here we have packages that provide the correct name and contain the path,
+ * now do extra filtering */
s = pool->solvables + p;
- if (s->repo == solv->installed && s->name == rd->name)
+ if (s->repo == solv->installed && s->name == rd->name &&
+ (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
return 1;
}
return 0;
return 0;
}
-
-
-/************************************************************************/
-
-/*
- * make assertion rules into decisions
- *
- * Go through rules and add direct assertions to the decisionqueue.
- * If we find a conflict, disable rules and add them to problem queue.
- */
-
-static void
-makeruledecisions(Solver *solv)
+/* mirrors solver_dep_installed, but returns 2 if a
+ * dependency listed in solv->installsuppdepq was involved */
+static int
+solver_check_installsuppdepq_dep(Solver *solv, Id dep)
{
Pool *pool = solv->pool;
- int i, ri, ii;
- Rule *r, *rr;
- Id v, vv;
- int decisionstart;
- int record_proof = 1;
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
-
- /* The system solvable is always installed first */
- assert(solv->decisionq.count == 0);
- queue_push(&solv->decisionq, SYSTEMSOLVABLE);
- queue_push(&solv->decisionq_why, 0);
- solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
+ Id p, pp;
+ Queue *q;
- decisionstart = solv->decisionq.count;
- for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ if (ISRELDEP(dep))
{
- ri = solv->ruleassertions.elements[ii];
- r = solv->rules + ri;
-
- if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
- continue;
- /* do weak rules in phase 2 */
- if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
- continue;
-
- v = r->p;
- vv = v > 0 ? v : -v;
-
- if (!solv->decisionmap[vv]) /* if not yet decided */
- {
- /*
- * decide !
- */
- queue_push(&solv->decisionq, v);
- queue_push(&solv->decisionq_why, r - solv->rules);
- solv->decisionmap[vv] = v > 0 ? 1 : -1;
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- Solvable *s = solv->pool->solvables + vv;
- if (v < 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
- else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
- }
- continue;
- }
- /*
- * check previous decision: is it sane ?
- */
-
- if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
- continue;
- if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
- continue;
-
- /*
- * found a conflict!
- *
- * The rule (r) we're currently processing says something
- * different (v = r->p) than a previous decision (decisionmap[abs(v)])
- * on this literal
- */
-
- if (ri >= solv->learntrules)
+ Reldep *rd = GETRELDEP(pool, dep);
+ if (rd->flags == REL_AND)
+ {
+ int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
+ if (!r1)
+ return 0;
+ r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
+ if (!r2)
+ return 0;
+ return r1 == 2 || r2 == 2 ? 2 : 1;
+ }
+ if (rd->flags == REL_OR)
{
- /* conflict with a learnt rule */
- /* can happen when packages cannot be installed for
- * multiple reasons. */
- /* we disable the learnt rule in this case */
- solver_disablerule(solv, r);
- continue;
+ int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
+ r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
+ if (!r1 && !r2)
+ return 0;
+ return r1 == 2 || r2 == 2 ? 2 : 1;
}
-
- /*
- * find the decision which is the "opposite" of the rule
- */
-
- for (i = 0; i < solv->decisionq.count; i++)
- if (solv->decisionq.elements[i] == -v)
- break;
- assert(i < solv->decisionq.count); /* assert that we found it */
-
- /*
- * conflict with system solvable ?
- */
-
- if (v == -SYSTEMSOLVABLE)
+ if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
+ return solver_splitprovides(solv, rd->evr);
+ if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
+ return solver_dep_installed(solv, rd->evr);
+ if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
{
- /* conflict with system solvable */
- if (record_proof)
- {
- queue_push(&solv->problems, solv->learnt_pool.count);
- queue_push(&solv->learnt_pool, ri);
- queue_push(&solv->learnt_pool, 0);
- }
- else
- queue_push(&solv->problems, 0);
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
- if (ri >= solv->jobrules && ri < solv->jobrules_end)
- v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
- else
- v = ri;
- queue_push(&solv->problems, v);
- queue_push(&solv->problems, 0);
- solver_disableproblem(solv, v);
- continue;
+ int i;
+ for (i = 0; i < q->count; i++)
+ if (q->elements[i] == dep || q->elements[i] == rd->name)
+ return 2;
}
+ }
+ FOR_PROVIDES(p, pp, dep)
+ if (solv->decisionmap[p] > 0)
+ return 1;
+ return 0;
+}
- assert(solv->decisionq_why.elements[i] > 0);
+static int
+solver_check_installsuppdepq(Solver *solv, Solvable *s)
+{
+ Id sup, *supp;
+ supp = s->repo->idarraydata + s->supplements;
+ while ((sup = *supp++) != 0)
+ if (solver_check_installsuppdepq_dep(solv, sup) == 2)
+ return 1;
+ return 0;
+}
- /*
- * conflict with an rpm rule ?
- */
+static Id
+autouninstall(Solver *solv, Id *problem)
+{
+ Pool *pool = solv->pool;
+ int i;
+ int lastfeature = 0, lastupdate = 0;
+ Id v;
+ Id extraflags = -1;
- if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
+ for (i = 0; (v = problem[i]) != 0; i++)
+ {
+ if (v < 0)
+ extraflags &= solv->job.elements[-v - 1];
+ if (v >= solv->featurerules && v < solv->featurerules_end)
+ if (v > lastfeature)
+ lastfeature = v;
+ if (v >= solv->updaterules && v < solv->updaterules_end)
{
- /* conflict with rpm rule assertion */
- if (record_proof)
+ /* check if identical to feature rule */
+ Id p = solv->rules[v].p;
+ if (p <= 0)
+ continue;
+ Rule *r = solv->rules + solv->featurerules + (p - solv->installed->start);
+ if (!r->p)
{
- queue_push(&solv->problems, solv->learnt_pool.count);
- queue_push(&solv->learnt_pool, ri);
- queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
- queue_push(&solv->learnt_pool, 0);
+ /* update rule == feature rule */
+ if (v > lastfeature)
+ lastfeature = v;
+ continue;
}
- else
- queue_push(&solv->problems, 0);
- assert(v > 0 || v == -SYSTEMSOLVABLE);
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
- if (ri >= solv->jobrules && ri < solv->jobrules_end)
- v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
- else
- v = ri;
- queue_push(&solv->problems, v);
- queue_push(&solv->problems, 0);
- solver_disableproblem(solv, v);
- continue;
- }
-
- /*
- * conflict with another job or update/feature rule
- */
-
- /* record proof */
- if (record_proof)
- {
- queue_push(&solv->problems, solv->learnt_pool.count);
- queue_push(&solv->learnt_pool, ri);
- queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
- queue_push(&solv->learnt_pool, 0);
- }
- else
- queue_push(&solv->problems, 0);
-
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
-
- /*
- * push all of our rules (can only be feature or job rules)
- * asserting this literal on the problem stack
- */
-
- for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
- {
- if (rr->d < 0 /* disabled */
- || rr->w2) /* or no assertion */
- continue;
- if (rr->p != vv /* not affecting the literal */
- && rr->p != -vv)
- continue;
- if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
- continue;
-
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
-
- solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
-
- v = i;
- /* is is a job rule ? */
- if (i >= solv->jobrules && i < solv->jobrules_end)
- v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
-
- queue_push(&solv->problems, v);
- solver_disableproblem(solv, v);
- }
- queue_push(&solv->problems, 0);
-
- /*
- * start over
- * (back up from decisions)
- */
- while (solv->decisionq.count > decisionstart)
- {
- v = solv->decisionq.elements[--solv->decisionq.count];
- --solv->decisionq_why.count;
- vv = v > 0 ? v : -v;
- solv->decisionmap[vv] = 0;
+ if (v > lastupdate)
+ lastupdate = v;
}
- ii = -1; /* restarts loop at 0 */
}
-
- /*
- * phase 2: now do the weak assertions
- */
- for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ if (!lastupdate && !lastfeature)
+ return 0;
+ v = lastupdate ? lastupdate : lastfeature;
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
+ solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
+ solver_disableproblem(solv, v);
+ if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
{
- ri = solv->ruleassertions.elements[ii];
- r = solv->rules + ri;
- if (r->d < 0 || r->w2) /* disabled or no assertion */
- continue;
- if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
- continue;
- v = r->p;
- vv = v > 0 ? v : -v;
- /*
- * decide !
- * (if not yet decided)
- */
- if (!solv->decisionmap[vv])
+ /* add the package to the updatepkgs list, this will automatically turn
+ * on cleandeps mode */
+ Id p = solv->rules[v].p;
+ if (!solv->cleandeps_updatepkgs)
{
- queue_push(&solv->decisionq, v);
- queue_push(&solv->decisionq_why, r - solv->rules);
- solv->decisionmap[vv] = v > 0 ? 1 : -1;
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- Solvable *s = solv->pool->solvables + vv;
- if (v < 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", solvable2str(solv->pool, s));
- else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", solvable2str(solv->pool, s));
- }
- continue;
+ solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->cleandeps_updatepkgs);
+ }
+ if (p > 0)
+ {
+ int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
+ queue_pushunique(solv->cleandeps_updatepkgs, p);
+ if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
+ solver_disablepolicyrules(solv);
}
- /*
- * previously decided, sane ?
- */
- if (v > 0 && solv->decisionmap[vv] > 0)
- continue;
- if (v < 0 && solv->decisionmap[vv] < 0)
- continue;
-
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
- solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
-
- if (ri >= solv->jobrules && ri < solv->jobrules_end)
- v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
- else
- v = ri;
- solver_disableproblem(solv, v);
- if (v < 0)
- solver_reenablepolicyrules(solv, -(v + 1));
}
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
+ return v;
}
+/************************************************************************/
-/*-------------------------------------------------------------------
+/*
* enable/disable learnt rules
*
* we have enabled or disabled some of our rules. We now reenable all
Id why, *whyp;
int i;
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
{
whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
/* why != 0: we found a disabled rule, disable the learnt rule */
if (why && r->d >= 0)
{
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
- solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
+ solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
}
solver_disablerule(solv, r);
}
else if (!why && r->d < 0)
{
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
- solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
+ solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
}
solver_enablerule(solv, r);
}
}
-/********************************************************************/
-/* watches */
-
-
-/*-------------------------------------------------------------------
- * makewatches
- *
- * initial setup for all watches
+/*
+ * make assertion rules into decisions
+ *
+ * Go through rules and add direct assertions to the decisionqueue.
+ * If we find a conflict, disable rules and add them to problem queue.
*/
static void
-makewatches(Solver *solv)
+makeruledecisions(Solver *solv)
{
- Rule *r;
- int i;
- int nsolvables = solv->pool->nsolvables;
+ Pool *pool = solv->pool;
+ int i, ri, ii;
+ Rule *r, *rr;
+ Id v, vv;
+ int decisionstart;
+ int record_proof = 1;
+ int oldproblemcount;
+ int havedisabled = 0;
- sat_free(solv->watches);
- /* lower half for removals, upper half for installs */
- solv->watches = sat_calloc(2 * nsolvables, sizeof(Id));
-#if 1
- /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
- for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
-#else
- for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
-#endif
+ /* The system solvable is always installed first */
+ assert(solv->decisionq.count == 0);
+ queue_push(&solv->decisionq, SYSTEMSOLVABLE);
+ queue_push(&solv->decisionq_why, 0);
+ solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
+
+ decisionstart = solv->decisionq.count;
+ for (;;)
{
- if (!r->w2) /* assertions do not need watches */
- continue;
+ /* if we needed to re-run, back up decisions to decisionstart */
+ while (solv->decisionq.count > decisionstart)
+ {
+ v = solv->decisionq.elements[--solv->decisionq.count];
+ --solv->decisionq_why.count;
+ vv = v > 0 ? v : -v;
+ solv->decisionmap[vv] = 0;
+ }
- /* see addwatches_rule(solv, r) */
- r->n1 = solv->watches[nsolvables + r->w1];
- solv->watches[nsolvables + r->w1] = r - solv->rules;
+ /* note that the ruleassertions queue is ordered */
+ for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ {
+ ri = solv->ruleassertions.elements[ii];
+ r = solv->rules + ri;
+
+ if (havedisabled && ri >= solv->learntrules)
+ {
+ /* just started with learnt rule assertions. If we have disabled
+ * some rules, adapt the learnt rule status */
+ enabledisablelearntrules(solv);
+ havedisabled = 0;
+ }
+
+ if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
+ continue;
- r->n2 = solv->watches[nsolvables + r->w2];
- solv->watches[nsolvables + r->w2] = r - solv->rules;
- }
-}
+ /* do weak rules in phase 2 */
+ if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
+ continue;
+ v = r->p;
+ vv = v > 0 ? v : -v;
+
+ if (!solv->decisionmap[vv]) /* if not yet decided */
+ {
+ queue_push(&solv->decisionq, v);
+ queue_push(&solv->decisionq_why, r - solv->rules);
+ solv->decisionmap[vv] = v > 0 ? 1 : -1;
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
+ {
+ Solvable *s = solv->pool->solvables + vv;
+ if (v < 0)
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
+ else
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
+ }
+ continue;
+ }
-/*-------------------------------------------------------------------
- *
- * add watches (for a new learned rule)
- * sets up watches for a single rule
+ /* check against previous decision: is there a conflict? */
+ if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
+ continue;
+ if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
+ continue;
+
+ /*
+ * found a conflict!
+ *
+ * The rule (r) we're currently processing says something
+ * different (v = r->p) than a previous decision (decisionmap[abs(v)])
+ * on this literal
+ */
+
+ if (ri >= solv->learntrules)
+ {
+ /* conflict with a learnt rule */
+ /* can happen when packages cannot be installed for multiple reasons. */
+ /* we disable the learnt rule in this case */
+ /* (XXX: we should really call analyze_unsolvable_rule here!) */
+ solver_disablerule(solv, r);
+ continue;
+ }
+
+ /*
+ * find the decision which is the "opposite" of the rule
+ */
+ for (i = 0; i < solv->decisionq.count; i++)
+ if (solv->decisionq.elements[i] == -v)
+ break;
+ assert(i < solv->decisionq.count); /* assert that we found it */
+ oldproblemcount = solv->problems.count;
+
+ /*
+ * conflict with system solvable ?
+ */
+ if (v == -SYSTEMSOLVABLE)
+ {
+ if (record_proof)
+ {
+ queue_push(&solv->problems, solv->learnt_pool.count);
+ queue_push(&solv->learnt_pool, ri);
+ queue_push(&solv->learnt_pool, 0);
+ }
+ else
+ queue_push(&solv->problems, 0);
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
+ if (ri >= solv->jobrules && ri < solv->jobrules_end)
+ v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
+ else
+ v = ri;
+ queue_push(&solv->problems, v);
+ queue_push(&solv->problems, 0);
+ if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
+ solv->problems.count = oldproblemcount;
+ solver_disableproblem(solv, v);
+ havedisabled = 1;
+ break; /* start over */
+ }
+
+ assert(solv->decisionq_why.elements[i] > 0);
+
+ /*
+ * conflict with an rpm rule ?
+ */
+ if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
+ {
+ if (record_proof)
+ {
+ queue_push(&solv->problems, solv->learnt_pool.count);
+ queue_push(&solv->learnt_pool, ri);
+ queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
+ queue_push(&solv->learnt_pool, 0);
+ }
+ else
+ queue_push(&solv->problems, 0);
+ assert(v > 0 || v == -SYSTEMSOLVABLE);
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
+ if (ri >= solv->jobrules && ri < solv->jobrules_end)
+ v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
+ else
+ v = ri;
+ queue_push(&solv->problems, v);
+ queue_push(&solv->problems, 0);
+ if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
+ solv->problems.count = oldproblemcount;
+ solver_disableproblem(solv, v);
+ havedisabled = 1;
+ break; /* start over */
+ }
+
+ /*
+ * conflict with another job or update/feature rule
+ */
+
+ /* record proof */
+ if (record_proof)
+ {
+ queue_push(&solv->problems, solv->learnt_pool.count);
+ queue_push(&solv->learnt_pool, ri);
+ queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
+ queue_push(&solv->learnt_pool, 0);
+ }
+ else
+ queue_push(&solv->problems, 0);
+
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
+
+ /*
+ * push all of our rules (can only be feature or job rules)
+ * asserting this literal on the problem stack
+ */
+ for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
+ {
+ if (rr->d < 0 /* disabled */
+ || rr->w2) /* or no assertion */
+ continue;
+ if (rr->p != vv /* not affecting the literal */
+ && rr->p != -vv)
+ continue;
+ if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
+ continue;
+
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
+ solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
+
+ v = i;
+ if (i >= solv->jobrules && i < solv->jobrules_end)
+ v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
+ queue_push(&solv->problems, v);
+ }
+ queue_push(&solv->problems, 0);
+
+ if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
+ solv->problems.count = oldproblemcount;
+
+ for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
+ solver_disableproblem(solv, solv->problems.elements[i]);
+ havedisabled = 1;
+ break; /* start over */
+ }
+ if (ii < solv->ruleassertions.count)
+ continue;
+
+ /*
+ * phase 2: now do the weak assertions
+ */
+ for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ {
+ ri = solv->ruleassertions.elements[ii];
+ r = solv->rules + ri;
+ if (r->d < 0 || r->w2) /* disabled or no assertion */
+ continue;
+ if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
+ continue;
+ v = r->p;
+ vv = v > 0 ? v : -v;
+
+ if (!solv->decisionmap[vv]) /* if not yet decided */
+ {
+ queue_push(&solv->decisionq, v);
+ queue_push(&solv->decisionq_why, r - solv->rules);
+ solv->decisionmap[vv] = v > 0 ? 1 : -1;
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
+ {
+ Solvable *s = solv->pool->solvables + vv;
+ if (v < 0)
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
+ else
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
+ }
+ continue;
+ }
+ /* check against previous decision: is there a conflict? */
+ if (v > 0 && solv->decisionmap[vv] > 0)
+ continue;
+ if (v < 0 && solv->decisionmap[vv] < 0)
+ continue;
+
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
+ solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
+
+ if (ri >= solv->jobrules && ri < solv->jobrules_end)
+ v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
+ else
+ v = ri;
+ solver_disableproblem(solv, v);
+ if (v < 0)
+ solver_reenablepolicyrules(solv, -v);
+ havedisabled = 1;
+ break; /* start over */
+ }
+ if (ii == solv->ruleassertions.count)
+ break; /* finished! */
+ }
+}
+
+
+/********************************************************************/
+/* watches */
+
+
+/*-------------------------------------------------------------------
+ * makewatches
+ *
+ * initial setup for all watches
+ */
+
+static void
+makewatches(Solver *solv)
+{
+ Rule *r;
+ int i;
+ int nsolvables = solv->pool->nsolvables;
+
+ solv_free(solv->watches);
+ /* lower half for removals, upper half for installs */
+ solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
+#if 1
+ /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
+ for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
+#else
+ for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
+#endif
+ {
+ if (!r->w2) /* assertions do not need watches */
+ continue;
+
+ /* see addwatches_rule(solv, r) */
+ r->n1 = solv->watches[nsolvables + r->w1];
+ solv->watches[nsolvables + r->w1] = r - solv->rules;
+
+ r->n2 = solv->watches[nsolvables + r->w2];
+ solv->watches[nsolvables + r->w2] = r - solv->rules;
+ }
+}
+
+
+/*-------------------------------------------------------------------
+ *
+ * add watches (for a new learned rule)
+ * sets up watches for a single rule
*
* see also makewatches() above.
*/
*
* make decision and propagate to all rules
*
- * Evaluate each term affected by the decision (linked through watches)
- * If we find unit rules we make new decisions based on them
- *
- * Everything's fixed there, it's just finding rules that are
- * unit.
+ * Evaluate each term affected by the decision (linked through watches).
+ * If we find unit rules we make new decisions based on them.
*
* return : 0 = everything is OK
* rule = conflict found in this rule
Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
/* foreach non-propagated decision */
while (solv->propagate_index < solv->decisionq.count)
*/
pkg = -solv->decisionq.elements[solv->propagate_index++];
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
- solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
+ solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
}
/* foreach rule where 'pkg' is now FALSE */
continue;
}
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
- solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
+ solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
}
/* 'pkg' was just decided (was set to FALSE)
* if we found some p that is UNDEF or TRUE, move
* watch to it
*/
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
if (p > 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvid2str(pool, -p));
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
}
*rp = *next_rp;
} /* not binary */
- /*
- * unit clause found, set literal other_watch to TRUE
- */
+ /*
+ * unit clause found, set literal other_watch to TRUE
+ */
if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
return r; /* eek, a conflict! */
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
- solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
+ solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
}
if (other_watch > 0)
queue_push(&solv->decisionq, other_watch);
queue_push(&solv->decisionq_why, r - solv->rules);
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
if (other_watch > 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvid2str(pool, other_watch));
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvid2str(pool, -other_watch));
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
}
} /* foreach rule involving 'pkg' */
} /* while we have non-decided decisions */
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
return 0; /* all is well */
}
queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
map_init(&seen, pool->nsolvables);
idx = solv->decisionq.count;
for (;;)
{
- IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
- solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
+ solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
queue_push(&solv->learnt_pool, c - solv->rules);
d = c->d < 0 ? -c->d - 1 : c->d;
dp = d ? pool->whatprovidesdata + d : 0;
*pr = -v; /* so that v doesn't get lost */
if (!l1num)
break;
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
/* clear non-l1 bits from seen map */
for (i = 0; i < r.count; i++)
{
*dr = r.elements[0];
else
*dr = pool_queuetowhatprovides(pool, &r);
- IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
{
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
- solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
for (i = 0; i < r.count; i++)
- solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
}
/* push end marker on learnt reasons stack */
queue_push(&solv->learnt_pool, 0);
*
* solver_reset
*
- * reset the solver decisions to right after the rpm rules.
+ * reset all solver decisions
* called after rules have been enabled/disabled
*/
v = solv->decisionq.elements[i];
solv->decisionmap[v > 0 ? v : -v] = 0;
}
- solv->decisionq_why.count = 0;
- solv->decisionq.count = 0;
+ queue_empty(&solv->decisionq_why);
+ queue_empty(&solv->decisionq);
solv->recommends_index = -1;
solv->propagate_index = 0;
- solv->recommendations.count = 0;
- solv->branches.count = 0;
+ queue_empty(&solv->branches);
/* adapt learnt rule status to new set of enabled/disabled rules */
enabledisablelearntrules(solv);
/* redo all assertion rule decisions */
makeruledecisions(solv);
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
}
/*-------------------------------------------------------------------
*
* analyze_unsolvable_rule
+ *
+ * recursion helper used by analyze_unsolvable
*/
static void
int i;
Id why = r - solv->rules;
- IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
- solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
- MAPSET(rseen, why);
+ IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
+ solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
if (solv->learntrules && why >= solv->learntrules)
{
+ if (MAPTST(rseen, why - solv->learntrules))
+ return;
+ MAPSET(rseen, why - solv->learntrules);
for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
- if (solv->learnt_pool.elements[i] > 0 && !MAPTST(rseen, solv->learnt_pool.elements[i]))
+ if (solv->learnt_pool.elements[i] > 0)
analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
return;
}
*
* analyze_unsolvable
*
+ * We know that the problem is not solvable. Record all involved
+ * rules (i.e. the "proof") into solv->learnt_pool.
+ * Record the learnt pool index and all non-rpm rules into
+ * solv->problems. (Our solutions to fix the problems are to
+ * disable those rules.)
+ *
+ * If the proof contains at least one weak rule, we disable the
+ * last of them.
+ *
+ * Otherwise we return 0 if disablerules is not set or disable
+ * _all_ of the problem rules and return 1.
+ *
* return: 1 - disabled some rules, try again
* 0 - hopeless
*/
Id lastweak;
int record_proof = 1;
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
solv->stats_unsolvable++;
oldproblemcount = solv->problems.count;
oldlearntpoolcount = solv->learnt_pool.count;
r = cr;
map_init(&seen, pool->nsolvables);
- map_init(&rseen, solv->nrules);
+ map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
if (record_proof)
queue_push(&solv->learnt_pool, r - solv->rules);
lastweak = 0;
if (record_proof)
queue_push(&solv->learnt_pool, why);
r = solv->rules + why;
- if (!MAPTST(&rseen, why))
- analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
+ analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
d = r->d < 0 ? -r->d - 1 : r->d;
dp = d ? pool->whatprovidesdata + d : 0;
for (i = -1; ; i++)
if (lastweak)
{
- Id v;
/* disable last weak rule */
solv->problems.count = oldproblemcount;
solv->learnt_pool.count = oldlearntpoolcount;
v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
else
v = lastweak;
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
- solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + lastweak);
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
+ solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
solver_disablechoicerules(solv, solv->rules + lastweak);
solver_disableproblem(solv, v);
if (v < 0)
- solver_reenablepolicyrules(solv, -(v + 1));
+ solver_reenablepolicyrules(solv, -v);
+ solver_reset(solv);
+ return 1;
+ }
+
+ if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
+ {
+ solv->problems.count = oldproblemcount;
+ solv->learnt_pool.count = oldlearntpoolcount;
solver_reset(solv);
return 1;
}
solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
}
- if (disablerules)
+ /* + 2: index + trailing zero */
+ if (disablerules && oldproblemcount + 2 < solv->problems.count)
{
for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
solver_disableproblem(solv, solv->problems.elements[i]);
solver_reset(solv);
return 1;
}
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
return 0;
}
vv = v > 0 ? v : -v;
if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
break;
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
- if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
- solv->recommendations.count--;
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
solv->decisionmap[vv] = 0;
solv->decisionq.count--;
solv->decisionq_why.count--;
break;
if (level == 1)
return analyze_unsolvable(solv, r, disablerules);
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
assert(l > 0 && l < level);
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
level = l;
revert(solv, level);
r = solver_addrule(solv, p, d);
solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
queue_push(&solv->decisionq, p);
queue_push(&solv->decisionq_why, r - solv->rules);
- IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
{
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
- solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
- solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
+ solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
}
}
return level;
}
p = dq->elements[0];
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
return setpropagatelearn(solv, level, p, disablerules, ruleid);
}
solver_create(Pool *pool)
{
Solver *solv;
- solv = (Solver *)sat_calloc(1, sizeof(Solver));
+ solv = (Solver *)solv_calloc(1, sizeof(Solver));
solv->pool = pool;
solv->installed = pool->installed;
- transaction_init(&solv->trans, pool);
+ solv->allownamechange = 1;
+
+ solv->dup_allowdowngrade = 1;
+ solv->dup_allownamechange = 1;
+ solv->dup_allowarchchange = 1;
+ solv->dup_allowvendorchange = 1;
+
queue_init(&solv->ruletojob);
queue_init(&solv->decisionq);
queue_init(&solv->decisionq_why);
queue_init(&solv->problems);
- queue_init(&solv->suggestions);
- queue_init(&solv->recommendations);
queue_init(&solv->orphaned);
queue_init(&solv->learnt_why);
queue_init(&solv->learnt_pool);
queue_init(&solv->branches);
- queue_init(&solv->covenantq);
queue_init(&solv->weakruleq);
queue_init(&solv->ruleassertions);
+ queue_init(&solv->addedmap_deduceq);
queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
solv->recommends_index = 0;
- solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
+ solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
solv->nrules = 1;
- solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
+ solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
memset(solv->rules, 0, sizeof(Rule));
return solv;
void
solver_free(Solver *solv)
{
- transaction_free(&solv->trans);
queue_free(&solv->job);
queue_free(&solv->ruletojob);
queue_free(&solv->decisionq);
queue_free(&solv->learnt_pool);
queue_free(&solv->problems);
queue_free(&solv->solutions);
- queue_free(&solv->suggestions);
- queue_free(&solv->recommendations);
queue_free(&solv->orphaned);
queue_free(&solv->branches);
- queue_free(&solv->covenantq);
queue_free(&solv->weakruleq);
queue_free(&solv->ruleassertions);
+ queue_free(&solv->addedmap_deduceq);
+ if (solv->cleandeps_updatepkgs)
+ {
+ queue_free(solv->cleandeps_updatepkgs);
+ solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
+ }
+ if (solv->cleandeps_mistakes)
+ {
+ queue_free(solv->cleandeps_mistakes);
+ solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
+ }
+ if (solv->update_targets)
+ {
+ queue_free(solv->update_targets);
+ solv->update_targets = solv_free(solv->update_targets);
+ }
+ if (solv->installsuppdepq)
+ {
+ queue_free(solv->installsuppdepq);
+ solv->installsuppdepq = solv_free(solv->installsuppdepq);
+ }
map_free(&solv->recommendsmap);
map_free(&solv->suggestsmap);
map_free(&solv->noobsoletes);
map_free(&solv->updatemap);
+ map_free(&solv->bestupdatemap);
map_free(&solv->fixmap);
map_free(&solv->dupmap);
map_free(&solv->dupinvolvedmap);
map_free(&solv->droporphanedmap);
map_free(&solv->cleandepsmap);
- sat_free(solv->decisionmap);
- sat_free(solv->rules);
- sat_free(solv->watches);
- sat_free(solv->obsoletes);
- sat_free(solv->obsoletes_data);
- sat_free(solv->multiversionupdaters);
- sat_free(solv->choicerules_ref);
- sat_free(solv);
+ solv_free(solv->decisionmap);
+ solv_free(solv->rules);
+ solv_free(solv->watches);
+ solv_free(solv->obsoletes);
+ solv_free(solv->obsoletes_data);
+ solv_free(solv->multiversionupdaters);
+ solv_free(solv->choicerules_ref);
+ solv_free(solv->bestrules_pkg);
+ solv_free(solv);
+}
+
+int
+solver_get_flag(Solver *solv, int flag)
+{
+ switch (flag)
+ {
+ case SOLVER_FLAG_ALLOW_DOWNGRADE:
+ return solv->allowdowngrade;
+ case SOLVER_FLAG_ALLOW_NAMECHANGE:
+ return solv->allownamechange;
+ case SOLVER_FLAG_ALLOW_ARCHCHANGE:
+ return solv->allowarchchange;
+ case SOLVER_FLAG_ALLOW_VENDORCHANGE:
+ return solv->allowvendorchange;
+ case SOLVER_FLAG_ALLOW_UNINSTALL:
+ return solv->allowuninstall;
+ case SOLVER_FLAG_NO_UPDATEPROVIDE:
+ return solv->noupdateprovide;
+ case SOLVER_FLAG_SPLITPROVIDES:
+ return solv->dosplitprovides;
+ case SOLVER_FLAG_IGNORE_RECOMMENDED:
+ return solv->dontinstallrecommended;
+ case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
+ return solv->addalreadyrecommended;
+ case SOLVER_FLAG_NO_INFARCHCHECK:
+ return solv->noinfarchcheck;
+ case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
+ return solv->keepexplicitobsoletes;
+ case SOLVER_FLAG_BEST_OBEY_POLICY:
+ return solv->bestobeypolicy;
+ case SOLVER_FLAG_NO_AUTOTARGET:
+ return solv->noautotarget;
+ default:
+ break;
+ }
+ return -1;
+}
+
+int
+solver_set_flag(Solver *solv, int flag, int value)
+{
+ int old = solver_get_flag(solv, flag);
+ switch (flag)
+ {
+ case SOLVER_FLAG_ALLOW_DOWNGRADE:
+ solv->allowdowngrade = value;
+ break;
+ case SOLVER_FLAG_ALLOW_NAMECHANGE:
+ solv->allownamechange = value;
+ break;
+ case SOLVER_FLAG_ALLOW_ARCHCHANGE:
+ solv->allowarchchange = value;
+ break;
+ case SOLVER_FLAG_ALLOW_VENDORCHANGE:
+ solv->allowvendorchange = value;
+ break;
+ case SOLVER_FLAG_ALLOW_UNINSTALL:
+ solv->allowuninstall = value;
+ break;
+ case SOLVER_FLAG_NO_UPDATEPROVIDE:
+ solv->noupdateprovide = value;
+ break;
+ case SOLVER_FLAG_SPLITPROVIDES:
+ solv->dosplitprovides = value;
+ break;
+ case SOLVER_FLAG_IGNORE_RECOMMENDED:
+ solv->dontinstallrecommended = value;
+ break;
+ case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
+ solv->addalreadyrecommended = value;
+ break;
+ case SOLVER_FLAG_NO_INFARCHCHECK:
+ solv->noinfarchcheck = value;
+ break;
+ case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
+ solv->keepexplicitobsoletes = value;
+ break;
+ case SOLVER_FLAG_BEST_OBEY_POLICY:
+ solv->bestobeypolicy = value;
+ break;
+ case SOLVER_FLAG_NO_AUTOTARGET:
+ solv->noautotarget = value;
+ break;
+ default:
+ break;
+ }
+ return old;
+}
+
+int
+cleandeps_check_mistakes(Solver *solv, int level)
+{
+ Pool *pool = solv->pool;
+ Rule *r;
+ Id p, pp;
+ int i;
+ int mademistake = 0;
+
+ if (!solv->cleandepsmap.size)
+ return 0;
+ /* check for mistakes */
+ for (i = solv->installed->start; i < solv->installed->end; i++)
+ {
+ if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
+ continue;
+ r = solv->rules + solv->featurerules + (i - solv->installed->start);
+ /* a mistake is when the featurerule is true but the updaterule is false */
+ if (!r->p)
+ continue;
+ FOR_RULELITERALS(p, pp, r)
+ if (p > 0 && solv->decisionmap[p] > 0)
+ break;
+ if (!p)
+ continue; /* feature rule is not true */
+ r = solv->rules + solv->updaterules + (i - solv->installed->start);
+ if (!r->p)
+ continue;
+ FOR_RULELITERALS(p, pp, r)
+ if (p > 0 && solv->decisionmap[p] > 0)
+ break;
+ if (p)
+ continue; /* update rule is true */
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
+ solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
+ solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
+ if (!solv->cleandeps_mistakes)
+ {
+ solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->cleandeps_mistakes);
+ }
+ queue_push(solv->cleandeps_mistakes, i);
+ MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
+ solver_reenablepolicyrules_cleandeps(solv, i);
+ mademistake = 1;
+ }
+ if (mademistake)
+ solver_reset(solv);
+ return mademistake;
}
+static void
+prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
+{
+ int i, j;
+ Id p, *cp2;
+ for (i = j = 0; i < q->count; i++)
+ {
+ p = q->elements[i];
+ for (cp2 = cp; *cp2; cp2++)
+ if (*cp2 == p)
+ {
+ q->elements[j++] = p;
+ break;
+ }
+ }
+ queue_truncate(q, j);
+}
/*-------------------------------------------------------------------
*
int i, j, n;
Solvable *s;
Pool *pool = solv->pool;
- Id p, *dp;
+ Id p, pp, *dp;
int minimizationsteps;
int installedpos = solv->installed ? solv->installed->start : 0;
- IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
+ IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
{
- POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
+ POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
for (i = 1; i < solv->nrules; i++)
- solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
+ solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
}
- POOL_DEBUG(SAT_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
-
- IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
- solver_printdecisions(solv);
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
/* start SAT algorithm */
level = 1;
systemlevel = level + 1;
- POOL_DEBUG(SAT_DEBUG_SOLVER, "solving...\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
queue_init(&dq);
queue_init(&dqs);
*/
if (level == 1)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
if ((r = propagate(solv, level)) != 0)
{
if (analyze_unsolvable(solv, r, disablerules))
continue;
- queue_free(&dq);
- queue_free(&dqs);
- return;
+ level = 0;
+ break; /* unsolvable */
}
}
*/
if (level < systemlevel)
{
- POOL_DEBUG(SAT_DEBUG_SOLVER, "resolving job rules\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
{
Id l;
if (r->d < 0) /* ignore disabled rules */
continue;
queue_empty(&dq);
- FOR_RULELITERALS(l, dp, r)
+ FOR_RULELITERALS(l, pp, r)
{
if (l < 0)
{
if (l || !dq.count)
continue;
/* prune to installed if not updating */
- if (dq.count > 1 && solv->installed && !solv->updatemap_all)
+ if (dq.count > 1 && solv->installed && !solv->updatemap_all &&
+ !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
{
int j, k;
for (j = k = 0; j < dq.count; j++)
olevel = level;
level = selectandinstall(solv, level, &dq, disablerules, i);
if (level == 0)
- {
- queue_free(&dq);
- queue_free(&dqs);
- return;
- }
+ break;
if (level <= olevel)
break;
}
+ if (level == 0)
+ break; /* unsolvable */
systemlevel = level + 1;
if (i < solv->jobrules_end)
continue;
+ solv->decisioncnt_update = solv->decisionq.count;
+ solv->decisioncnt_keep = solv->decisionq.count;
}
-
/*
* installed packages
*/
Repo *installed = solv->installed;
int pass;
- POOL_DEBUG(SAT_DEBUG_SOLVER, "resolving installed packages\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
/* we use two passes if we need to update packages
* to create a better user experience */
for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
{
int passlevel = level;
+ if (pass == 1)
+ solv->decisioncnt_keep = solv->decisionq.count;
/* start with installedpos, the position that gave us problems last time */
for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
{
while ((p = pool->whatprovidesdata[d++]) != 0)
if (solv->decisionmap[p] >= 0)
queue_push(&dq, p);
- policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
- p = dq.elements[0];
- if (p != i && solv->decisionmap[p] == 0)
+ if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
+ prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
+ if (dq.count)
{
- rr = solv->rules + solv->featurerules + (i - solv->installed->start);
- if (!rr->p) /* update rule == feature rule? */
- rr = rr - solv->featurerules + solv->updaterules;
- dq.count = 1;
+ policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
+ p = dq.elements[0];
+ if (p != i && solv->decisionmap[p] == 0)
+ {
+ rr = solv->rules + solv->featurerules + (i - solv->installed->start);
+ if (!rr->p) /* update rule == feature rule? */
+ rr = rr - solv->featurerules + solv->updaterules;
+ dq.count = 1;
+ }
+ else
+ dq.count = 0;
}
- else
- dq.count = 0;
}
else
{
/* update to best package */
- FOR_RULELITERALS(p, dp, rr)
+ FOR_RULELITERALS(p, pp, rr)
{
if (solv->decisionmap[p] > 0)
{
}
}
}
+ if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
+ prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
/* install best version */
if (dq.count)
{
olevel = level;
if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
{
- POOL_DEBUG(SAT_DEBUG_POLICY, "cleandeps erasing %s\n", solvid2str(pool, i));
+#if 0
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
level = setpropagatelearn(solv, level, -i, disablerules, 0);
+#else
+ continue;
+#endif
}
else
{
- POOL_DEBUG(SAT_DEBUG_POLICY, "keeping %s\n", solvid2str(pool, i));
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
}
if (level == 0)
- {
- queue_free(&dq);
- queue_free(&dqs);
- return;
- }
+ break;
if (level <= olevel)
{
if (level == 1 || level < passlevel)
n = installed->start; /* redo all */
i--;
n--;
- continue; /* retry with learnt rule */
+ continue; /* retry with learnt rule */
}
}
}
}
installedpos = installed->start; /* reset installedpos */
}
+ if (level == 0)
+ break; /* unsolvable */
systemlevel = level + 1;
if (pass < 2)
continue; /* had trouble, retry */
/*
* decide
*/
- POOL_DEBUG(SAT_DEBUG_POLICY, "deciding unresolved rules\n");
+ solv->decisioncnt_resolve = solv->decisionq.count;
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
for (i = 1, n = 1; n < solv->nrules; i++, n++)
{
if (i == solv->nrules)
if (p)
continue;
}
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
- solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
+ solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
}
/* dq.count < 2 cannot happen as this means that
* the rule is unit */
assert(dq.count > 1);
+ /* prune to cleandeps packages */
+ if (solv->cleandepsmap.size && solv->installed)
+ {
+ Repo *installed = solv->installed;
+ for (j = 0; j < dq.count; j++)
+ if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
+ break;
+ if (j < dq.count)
+ {
+ dq.elements[0] = dq.elements[j];
+ queue_truncate(&dq, 1);
+ }
+ }
+
olevel = level;
level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
if (level == 0)
- {
- queue_free(&dq);
- queue_free(&dqs);
- return;
- }
+ break; /* unsolvable */
if (level < systemlevel || level == 1)
break; /* trouble */
/* something changed, so look at all rules again */
n = 0;
}
- if (n != solv->nrules) /* ran into trouble, restart */
- continue;
+ if (n != solv->nrules) /* ran into trouble? */
+ {
+ if (level == 0)
+ break; /* unsolvable */
+ continue; /* start over */
+ }
/* at this point we have a consistent system. now do the extras... */
+ /* first decide leftover cleandeps packages */
+ if (solv->cleandepsmap.size && solv->installed)
+ {
+ for (p = solv->installed->start; p < solv->installed->end; p++)
+ {
+ s = pool->solvables + p;
+ if (s->repo != solv->installed)
+ continue;
+ if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
+ {
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
+ olevel = level;
+ level = setpropagatelearn(solv, level, -p, 0, 0);
+ if (level < olevel)
+ break;
+ }
+ }
+ if (p < solv->installed->end)
+ continue;
+ }
+
+ solv->decisioncnt_weak = solv->decisionq.count;
if (doweak)
{
int qcount;
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended packages\n");
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
queue_empty(&dq); /* recommended packages */
queue_empty(&dqs); /* supplemented packages */
for (i = 1; i < pool->nsolvables; i++)
/* installed, check for recommends */
Id *recp, rec, pp, p;
s = pool->solvables + i;
- if (solv->ignorealreadyrecommended && s->repo == solv->installed)
+ if (!solv->addalreadyrecommended && s->repo == solv->installed)
continue;
/* XXX need to special case AND ? */
if (s->recommends)
}
/* filter out all already supplemented packages if requested */
- if (solv->ignorealreadyrecommended && dqs.count)
+ if (!solv->addalreadyrecommended && dqs.count)
{
/* turn off all new packages */
for (i = 0; i < solv->decisionq.count; i++)
continue;
if (!solver_is_supplementing(solv, s))
dqs.elements[j++] = p;
+ else if (s->supplements && solv->installsuppdepq && solver_check_installsuppdepq(solv, s))
+ dqs.elements[j++] = p;
}
dqs.count = j;
/* undo turning off */
if (dq.count == 1)
{
- /* simple case, just one package. no need to choose */
+ /* simple case, just one package. no need to choose to best version */
p = dq.elements[0];
if (dqs.count)
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
else
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvid2str(pool, p));
- queue_push(&solv->recommendations, p);
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
level = setpropagatelearn(solv, level, p, 0, 0);
+ if (level == 0)
+ break;
continue; /* back to main loop */
}
p = dqs.elements[i];
if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
continue;
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing supplemented %s\n", solvid2str(pool, p));
- queue_push(&solv->recommendations, p);
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
olevel = level;
level = setpropagatelearn(solv, level, p, 0, 0);
if (level <= olevel)
if (i < dqs.count || solv->decisionq.count < decisioncount)
{
map_free(&dqmap);
+ if (level == 0)
+ break;
continue;
}
if (p < 0)
continue;
s = pool->solvables + p;
- if (!s->repo || (solv->ignorealreadyrecommended && s->repo == solv->installed))
+ if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
continue;
if (!s->recommends)
continue;
queue_push(&solv->branches, -level);
}
p = dq.elements[0];
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing recommended %s\n", solvid2str(pool, p));
- queue_push(&solv->recommendations, p);
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
olevel = level;
level = setpropagatelearn(solv, level, p, 0, 0);
if (level <= olevel || solv->decisionq.count < decisioncount)
break; /* had a problem above, quit loop */
}
map_free(&dqmap);
-
+ if (level == 0)
+ break;
continue; /* back to main loop so that all deps are checked */
}
}
- if (solv->dupmap_all && solv->installed)
+ solv->decisioncnt_orphan = solv->decisionq.count;
+ if (solv->dupmap_all && solv->installed)
{
int installedone = 0;
/* let's see if we can install some unsupported package */
- POOL_DEBUG(SAT_DEBUG_SOLVER, "deciding orphaned packages\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
for (i = 0; i < solv->orphaned.count; i++)
{
p = solv->orphaned.elements[i];
if (solv->decisionmap[p])
continue; /* already decided */
- olevel = level;
if (solv->droporphanedmap_all)
continue;
if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
continue;
- POOL_DEBUG(SAT_DEBUG_SOLVER, "keeping orphaned %s\n", solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
+ olevel = level;
level = setpropagatelearn(solv, level, p, 0, 0);
installedone = 1;
if (level < olevel)
break;
}
if (installedone || i < solv->orphaned.count)
- continue; /* back to main loop */
+ {
+ if (level == 0)
+ break;
+ continue; /* back to main loop */
+ }
for (i = 0; i < solv->orphaned.count; i++)
{
p = solv->orphaned.elements[i];
if (solv->decisionmap[p])
continue; /* already decided */
- POOL_DEBUG(SAT_DEBUG_SOLVER, "removing orphaned %s\n", solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
olevel = level;
level = setpropagatelearn(solv, level, -p, 0, 0);
if (level < olevel)
break;
}
if (i < solv->orphaned.count)
- continue; /* back to main loop */
+ {
+ if (level == 0)
+ break;
+ continue; /* back to main loop */
+ }
+ }
+
+ if (solv->installed && solv->cleandepsmap.size)
+ {
+ if (cleandeps_check_mistakes(solv, level))
+ {
+ level = 1; /* restart from scratch */
+ systemlevel = level + 1;
+ continue;
+ }
}
if (solv->solution_callback)
if (solv->branches.elements[i - 1] < 0)
break;
p = solv->branches.elements[i];
- POOL_DEBUG(SAT_DEBUG_SOLVER, "branching with %s\n", solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
queue_empty(&dq);
for (j = i + 1; j < solv->branches.count; j++)
queue_push(&dq, solv->branches.elements[j]);
assert(why >= 0);
level = setpropagatelearn(solv, level, p, disablerules, why);
if (level == 0)
- {
- queue_free(&dq);
- queue_free(&dqs);
- return;
- }
+ break;
continue;
}
/* all branches done, we're finally finished */
break;
}
- /* minimization step */
+ /* auto-minimization step */
if (solv->branches.count)
{
int l = 0, lasti = -1, lastl = -1;
/* kill old solvable so that we do not loop */
p = solv->branches.elements[lasti];
solv->branches.elements[lasti] = 0;
- POOL_DEBUG(SAT_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, solvid2str(pool, p));
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
minimizationsteps++;
level = lastl;
olevel = level;
level = setpropagatelearn(solv, level, p, disablerules, why);
if (level == 0)
- {
- queue_free(&dq);
- queue_free(&dqs);
- return;
- }
+ break;
continue; /* back to main loop */
}
}
break;
}
- POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
- POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
+ POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
queue_free(&dq);
queue_free(&dqs);
+ if (level == 0)
+ {
+ /* unsolvable */
+ solv->decisioncnt_update = solv->decisionq.count;
+ solv->decisioncnt_keep = solv->decisionq.count;
+ solv->decisioncnt_resolve = solv->decisionq.count;
+ solv->decisioncnt_weak = solv->decisionq.count;
+ solv->decisioncnt_orphan = solv->decisionq.count;
+ }
#if 0
- solver_printdecisionq(solv, SAT_DEBUG_RESULT);
+ solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
#endif
}
Rule *r;
Id *decisionmap = solv->decisionmap;
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "removedisabledconflicts\n");
queue_empty(removed);
for (i = 0; i < solv->decisionq.count; i++)
{
if (r->d < 0 && decisionmap[-p])
{
/* rule is now disabled, remove from decisionmap */
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "removing conflict for package %s[%d]\n", solvid2str(pool, -p), -p);
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
queue_push(removed, -p);
queue_push(removed, decisionmap[-p]);
decisionmap[-p] = 0;
}
if (new)
{
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "re-conflicting package %s[%d]\n", solvid2str(pool, -new), -new);
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
decisionmap[-new] = -1;
new = 0;
n = 0; /* redo all rules */
/* main() */
-static void
-findrecommendedsuggested(Solver *solv)
-{
- Pool *pool = solv->pool;
- Queue redoq, disabledq;
- int goterase, i;
- Solvable *s;
- Rule *r;
- Map obsmap;
-
- map_init(&obsmap, pool->nsolvables);
- if (solv->installed)
- {
- Id obs, *obsp, p, po, ppo;
- for (p = solv->installed->start; p < solv->installed->end; p++)
- {
- s = pool->solvables + p;
- if (s->repo != solv->installed || !s->obsoletes)
- continue;
- if (solv->decisionmap[p] <= 0)
- continue;
- if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
- continue;
- obsp = s->repo->idarraydata + s->obsoletes;
- /* foreach obsoletes */
- while ((obs = *obsp++) != 0)
- FOR_PROVIDES(po, ppo, obs)
- MAPSET(&obsmap, po);
- }
- }
-
- queue_init(&redoq);
- queue_init(&disabledq);
- goterase = 0;
- /* disable all erase jobs (including weak "keep uninstalled" rules) */
- for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
- {
- if (r->d < 0) /* disabled ? */
- continue;
- if (r->p >= 0) /* install job? */
- continue;
- queue_push(&disabledq, i);
- solver_disablerule(solv, r);
- goterase++;
- }
-
- if (goterase)
- {
- enabledisablelearntrules(solv);
- removedisabledconflicts(solv, &redoq);
- }
-
- /*
- * find recommended packages
- */
-
- /* if redoq.count == 0 we already found all recommended in the
- * solver run */
- if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
- {
- Id rec, *recp, p, pp;
-
- /* create map of all recommened packages */
- solv->recommends_index = -1;
- MAPZERO(&solv->recommendsmap);
- for (i = 0; i < solv->decisionq.count; i++)
- {
- p = solv->decisionq.elements[i];
- if (p < 0)
- continue;
- s = pool->solvables + p;
- if (s->recommends)
- {
- recp = s->repo->idarraydata + s->recommends;
- while ((rec = *recp++) != 0)
- {
- FOR_PROVIDES(p, pp, rec)
- if (solv->decisionmap[p] > 0)
- break;
- if (p)
- {
- if (!solv->dontshowinstalledrecommended)
- {
- FOR_PROVIDES(p, pp, rec)
- if (solv->decisionmap[p] > 0)
- MAPSET(&solv->recommendsmap, p);
- }
- continue; /* p != 0: already fulfilled */
- }
- FOR_PROVIDES(p, pp, rec)
- MAPSET(&solv->recommendsmap, p);
- }
- }
- }
- for (i = 1; i < pool->nsolvables; i++)
- {
- if (solv->decisionmap[i] < 0)
- continue;
- if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
- continue;
- if (MAPTST(&obsmap, i))
- continue;
- s = pool->solvables + i;
- if (!MAPTST(&solv->recommendsmap, i))
- {
- if (!s->supplements)
- continue;
- if (!pool_installable(pool, s))
- continue;
- if (!solver_is_supplementing(solv, s))
- continue;
- }
- if (solv->dontinstallrecommended)
- queue_push(&solv->recommendations, i);
- else
- queue_pushunique(&solv->recommendations, i);
- }
- /* we use MODE_SUGGEST here so that repo prio is ignored */
- policy_filter_unwanted(solv, &solv->recommendations, POLICY_MODE_SUGGEST);
- }
-
- /*
- * find suggested packages
- */
-
- if (1)
- {
- Id sug, *sugp, p, pp;
-
- /* create map of all suggests that are still open */
- solv->recommends_index = -1;
- MAPZERO(&solv->suggestsmap);
- for (i = 0; i < solv->decisionq.count; i++)
- {
- p = solv->decisionq.elements[i];
- if (p < 0)
- continue;
- s = pool->solvables + p;
- if (s->suggests)
- {
- sugp = s->repo->idarraydata + s->suggests;
- while ((sug = *sugp++) != 0)
- {
- FOR_PROVIDES(p, pp, sug)
- if (solv->decisionmap[p] > 0)
- break;
- if (p)
- {
- if (!solv->dontshowinstalledrecommended)
- {
- FOR_PROVIDES(p, pp, sug)
- if (solv->decisionmap[p] > 0)
- MAPSET(&solv->suggestsmap, p);
- }
- continue; /* already fulfilled */
- }
- FOR_PROVIDES(p, pp, sug)
- MAPSET(&solv->suggestsmap, p);
- }
- }
- }
- for (i = 1; i < pool->nsolvables; i++)
- {
- if (solv->decisionmap[i] < 0)
- continue;
- if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
- continue;
- if (MAPTST(&obsmap, i))
- continue;
- s = pool->solvables + i;
- if (!MAPTST(&solv->suggestsmap, i))
- {
- if (!s->enhances)
- continue;
- if (!pool_installable(pool, s))
- continue;
- if (!solver_is_enhancing(solv, s))
- continue;
- }
- queue_push(&solv->suggestions, i);
- }
- policy_filter_unwanted(solv, &solv->suggestions, POLICY_MODE_SUGGEST);
- }
-
- /* undo removedisabledconflicts */
- if (redoq.count)
- undo_removedisabledconflicts(solv, &redoq);
- queue_free(&redoq);
-
- /* undo job rule disabling */
- for (i = 0; i < disabledq.count; i++)
- solver_enablerule(solv, solv->rules + disabledq.elements[i]);
- queue_free(&disabledq);
- map_free(&obsmap);
-}
-
void
solver_calculate_noobsmap(Pool *pool, Queue *job, Map *noobsmap)
{
select = how & SOLVER_SELECTMASK;
if (!noobsmap->size)
map_grow(noobsmap, pool->nsolvables);
+ if (select == SOLVER_SOLVABLE_ALL)
+ {
+ FOR_POOL_SOLVABLES(p)
+ MAPSET(noobsmap, p);
+ }
+ else if (select == SOLVER_SOLVABLE_REPO)
+ {
+ Solvable *s;
+ Repo *repo = pool_id2repo(pool, what);
+ if (repo)
+ FOR_REPO_SOLVABLES(repo, p, s)
+ MAPSET(noobsmap, p);
+ }
FOR_JOB_SELECT(p, pp, select, what)
MAPSET(noobsmap, p);
}
queue_push(&solv->weakruleq, solv->nrules - 1);
}
-/*
- *
- * solve job queue
- *
- */
+static inline void
+add_cleandeps_package(Solver *solv, Id p)
+{
+ if (!solv->cleandeps_updatepkgs)
+ {
+ solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->cleandeps_updatepkgs);
+ }
+ queue_pushunique(solv->cleandeps_updatepkgs, p);
+}
-void
-solver_solve(Solver *solv, Queue *job)
+static void
+add_update_target(Solver *solv, Id p, Id how)
{
Pool *pool = solv->pool;
+ Solvable *s = pool->solvables + p;
Repo *installed = solv->installed;
- int i;
- int oldnrules;
- Map addedmap; /* '1' == have rpm-rules for solvable */
- Map installcandidatemap;
- Id how, what, select, name, weak, p, pp, d;
- Queue q;
- Solvable *s;
- Rule *r;
- int now, solve_start;
- int hasdupjob = 0;
-
- solve_start = sat_timems(0);
-
- /* log solver options */
- POOL_DEBUG(SAT_DEBUG_STATS, "solver started\n");
- POOL_DEBUG(SAT_DEBUG_STATS, "fixsystem=%d updatesystem=%d dosplitprovides=%d, noupdateprovide=%d noinfarchcheck=%d\n", solv->fixsystem, solv->updatesystem, solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
- POOL_DEBUG(SAT_DEBUG_STATS, "distupgrade=%d distupgrade_removeunsupported=%d\n", solv->distupgrade, solv->distupgrade_removeunsupported);
- POOL_DEBUG(SAT_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange);
- POOL_DEBUG(SAT_DEBUG_STATS, "promoteepoch=%d, novirtualconflicts=%d, allowselfconflicts=%d\n", pool->promoteepoch, pool->novirtualconflicts, pool->allowselfconflicts);
- POOL_DEBUG(SAT_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors);
- POOL_DEBUG(SAT_DEBUG_STATS, "dontinstallrecommended=%d, ignorealreadyrecommended=%d, dontshowinstalledrecommended=%d\n", solv->dontinstallrecommended, solv->ignorealreadyrecommended, solv->dontshowinstalledrecommended);
-
- /* create whatprovides if not already there */
- if (!pool->whatprovides)
- pool_createwhatprovides(pool);
-
- /* create obsolete index */
- policy_create_obsolete_index(solv);
+ Id pi, pip;
+ if (!solv->update_targets)
+ {
+ solv->update_targets = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->update_targets);
+ }
+ if (s->repo == installed)
+ {
+ queue_push2(solv->update_targets, p, p);
+ return;
+ }
+ FOR_PROVIDES(pi, pip, s->name)
+ {
+ Solvable *si = pool->solvables + pi;
+ if (si->repo != installed || si->name != s->name)
+ continue;
+ if (how & SOLVER_FORCEBEST)
+ {
+ if (!solv->bestupdatemap.size)
+ map_grow(&solv->bestupdatemap, installed->end - installed->start);
+ MAPSET(&solv->bestupdatemap, pi - installed->start);
+ }
+ if (how & SOLVER_CLEANDEPS)
+ add_cleandeps_package(solv, pi);
+ queue_push2(solv->update_targets, pi, p);
+ /* check if it's ok to keep the installed package */
+ if (s->evr == si->evr && solvable_identical(s, si))
+ queue_push2(solv->update_targets, pi, pi);
+ }
+ if (s->obsoletes)
+ {
+ Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
+ while ((obs = *obsp++) != 0)
+ {
+ FOR_PROVIDES(pi, pip, obs)
+ {
+ Solvable *si = pool->solvables + pi;
+ if (si->repo != installed)
+ continue;
+ if (si->name == s->name)
+ continue; /* already handled above */
+ if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
+ continue;
+ if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
+ continue;
+ if (how & SOLVER_FORCEBEST)
+ {
+ if (!solv->bestupdatemap.size)
+ map_grow(&solv->bestupdatemap, installed->end - installed->start);
+ MAPSET(&solv->bestupdatemap, pi - installed->start);
+ }
+ if (how & SOLVER_CLEANDEPS)
+ add_cleandeps_package(solv, pi);
+ queue_push2(solv->update_targets, pi, p);
+ }
+ }
+ }
+}
- /* remember job */
- queue_free(&solv->job);
- queue_init_clone(&solv->job, job);
+static int
+transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
+{
+ const Id *a = ap;
+ const Id *b = bp;
+ if (a[0] - b[0])
+ return a[0] - b[0];
+ return a[1] - b[1];
+}
- /* initialize with legacy values */
- solv->fixmap_all = solv->fixsystem;
- solv->updatemap_all = solv->updatesystem;
- solv->droporphanedmap_all = solv->distupgrade_removeunsupported;
- solv->dupmap_all = solv->distupgrade;
+static void
+transform_update_targets(Solver *solv)
+{
+ Repo *installed = solv->installed;
+ Queue *update_targets = solv->update_targets;
+ int i, j;
+ Id p, q, lastp, lastq;
+
+ if (!update_targets->count)
+ {
+ queue_free(update_targets);
+ solv->update_targets = solv_free(update_targets);
+ return;
+ }
+ if (update_targets->count > 2)
+ solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
+ queue_insertn(update_targets, 0, installed->end - installed->start);
+ lastp = lastq = 0;
+ for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
+ {
+ if ((p = update_targets->elements[i]) != lastp)
+ {
+ if (!solv->updatemap.size)
+ map_grow(&solv->updatemap, installed->end - installed->start);
+ MAPSET(&solv->updatemap, p - installed->start);
+ update_targets->elements[j++] = 0; /* finish old set */
+ update_targets->elements[p - installed->start] = j; /* start new set */
+ lastp = p;
+ lastq = 0;
+ }
+ if ((q = update_targets->elements[i + 1]) != lastq)
+ {
+ update_targets->elements[j++] = q;
+ lastq = q;
+ }
+ }
+ queue_truncate(update_targets, j);
+ queue_push(update_targets, 0); /* finish last set */
+}
+
+
+static void
+addedmap2deduceq(Solver *solv, Map *addedmap)
+{
+ Pool *pool = solv->pool;
+ int i, j;
+ Id p;
+ Rule *r;
+
+ queue_empty(&solv->addedmap_deduceq);
+ for (i = 2, j = solv->rpmrules_end - 1; i < pool->nsolvables && j > 0; j--)
+ {
+ r = solv->rules + j;
+ if (r->p >= 0)
+ continue;
+ if ((r->d == 0 || r->d == -1) && r->w2 < 0)
+ continue;
+ p = -r->p;
+ if (!MAPTST(addedmap, p))
+ {
+ /* should never happen, but... */
+ if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
+ queue_push(&solv->addedmap_deduceq, -p);
+ continue;
+ }
+ for (; i < p; i++)
+ if (MAPTST(addedmap, i))
+ queue_push(&solv->addedmap_deduceq, i);
+ if (i == p)
+ i++;
+ }
+ for (; i < pool->nsolvables; i++)
+ if (MAPTST(addedmap, i))
+ queue_push(&solv->addedmap_deduceq, i);
+ j = 0;
+ for (i = 2; i < pool->nsolvables; i++)
+ if (MAPTST(addedmap, i))
+ j++;
+}
+
+static void
+deduceq2addedmap(Solver *solv, Map *addedmap)
+{
+ int j;
+ Id p;
+ Rule *r;
+ for (j = solv->rpmrules_end - 1; j > 0; j--)
+ {
+ r = solv->rules + j;
+ if (r->d < 0 && r->p)
+ solver_enablerule(solv, r);
+ if (r->p >= 0)
+ continue;
+ if ((r->d == 0 || r->d == -1) && r->w2 < 0)
+ continue;
+ p = -r->p;
+ MAPSET(addedmap, p);
+ }
+ for (j = 0; j < solv->addedmap_deduceq.count; j++)
+ {
+ p = solv->addedmap_deduceq.elements[j];
+ if (p > 0)
+ MAPSET(addedmap, p);
+ else
+ MAPCLR(addedmap, p);
+ }
+}
+
+
+/*
+ *
+ * solve job queue
+ *
+ */
+
+int
+solver_solve(Solver *solv, Queue *job)
+{
+ Pool *pool = solv->pool;
+ Repo *installed = solv->installed;
+ int i;
+ int oldnrules, initialnrules;
+ Map addedmap; /* '1' == have rpm-rules for solvable */
+ Map installcandidatemap;
+ Id how, what, select, name, weak, p, pp, d;
+ Queue q;
+ Solvable *s;
+ Rule *r;
+ int now, solve_start;
+ int hasdupjob = 0;
+ int hasbestinstalljob = 0;
+
+ solve_start = solv_timems(0);
+
+ /* log solver options */
+ POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
+ POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allownamechange=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allownamechange, solv->allowarchchange, solv->allowvendorchange);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
+
+ /* create whatprovides if not already there */
+ if (!pool->whatprovides)
+ pool_createwhatprovides(pool);
+
+ /* create obsolete index */
+ policy_create_obsolete_index(solv);
+
+ /* remember job */
+ queue_free(&solv->job);
+ queue_init_clone(&solv->job, job);
+ solv->pooljobcnt = pool->pooljobs.count;
+ if (pool->pooljobs.count)
+ {
+ queue_insertn(&solv->job, 0, pool->pooljobs.count);
+ memcpy(solv->job.elements, pool->pooljobs.elements, pool->pooljobs.count * sizeof(Id));
+ }
+ job = &solv->job;
+
+ /* free old stuff */
+ if (solv->update_targets)
+ {
+ queue_free(solv->update_targets);
+ solv->update_targets = solv_free(solv->update_targets);
+ }
+ if (solv->cleandeps_updatepkgs)
+ {
+ queue_free(solv->cleandeps_updatepkgs);
+ solv->cleandeps_updatepkgs = solv_free(solv->cleandeps_updatepkgs);
+ }
+ queue_empty(&solv->ruleassertions);
+ solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
+ solv->choicerules_ref = solv_free(solv->choicerules_ref);
+ if (solv->noupdate.size)
+ map_empty(&solv->noupdate);
+ if (solv->noobsoletes.size)
+ {
+ map_free(&solv->noobsoletes);
+ map_init(&solv->noobsoletes, 0);
+ }
+ solv->updatemap_all = 0;
+ if (solv->updatemap.size)
+ {
+ map_free(&solv->updatemap);
+ map_init(&solv->updatemap, 0);
+ }
+ solv->bestupdatemap_all = 0;
+ if (solv->bestupdatemap.size)
+ {
+ map_free(&solv->bestupdatemap);
+ map_init(&solv->bestupdatemap, 0);
+ }
+ solv->fixmap_all = 0;
+ if (solv->fixmap.size)
+ {
+ map_free(&solv->fixmap);
+ map_init(&solv->fixmap, 0);
+ }
+ solv->dupmap_all = 0;
+ if (solv->dupmap.size)
+ {
+ map_free(&solv->dupmap);
+ map_init(&solv->dupmap, 0);
+ }
+ if (solv->dupinvolvedmap.size)
+ {
+ map_free(&solv->dupinvolvedmap);
+ map_init(&solv->dupinvolvedmap, 0);
+ }
+ solv->droporphanedmap_all = 0;
+ if (solv->droporphanedmap.size)
+ {
+ map_free(&solv->droporphanedmap);
+ map_init(&solv->droporphanedmap, 0);
+ }
+ if (solv->cleandepsmap.size)
+ {
+ map_free(&solv->cleandepsmap);
+ map_init(&solv->cleandepsmap, 0);
+ }
+
+ queue_empty(&solv->weakruleq);
+ solv->watches = solv_free(solv->watches);
+ queue_empty(&solv->ruletojob);
+ if (solv->decisionq.count)
+ memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
+ queue_empty(&solv->decisionq);
+ queue_empty(&solv->decisionq_why);
+ solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
+ queue_empty(&solv->learnt_why);
+ queue_empty(&solv->learnt_pool);
+ queue_empty(&solv->branches);
+ solv->propagate_index = 0;
+ queue_empty(&solv->problems);
+ queue_empty(&solv->solutions);
+ queue_empty(&solv->orphaned);
+ solv->stats_learned = solv->stats_unsolvable = 0;
+ if (solv->recommends_index)
+ {
+ map_empty(&solv->recommendsmap);
+ map_empty(&solv->suggestsmap);
+ solv->recommends_index = 0;
+ }
+ solv->multiversionupdaters = solv_free(solv->multiversionupdaters);
+
/*
* create basic rule set of all involved packages
map_init(&installcandidatemap, pool->nsolvables);
queue_init(&q);
- now = sat_timems(0);
+ now = solv_timems(0);
/*
* create rules for all package that could be involved with the solving
* so called: rpm rules
*
*/
+ initialnrules = solv->rpmrules_end ? solv->rpmrules_end : 1;
+ if (initialnrules > 1)
+ deduceq2addedmap(solv, &addedmap);
+ if (solv->nrules != initialnrules)
+ solver_shrinkrules(solv, initialnrules);
+ solv->nrules = initialnrules;
+ solv->rpmrules_end = 0;
+
if (installed)
{
/* check for update/verify jobs as they need to be known early */
switch (how & SOLVER_JOBMASK)
{
case SOLVER_VERIFY:
- if (select == SOLVER_SOLVABLE_ALL)
+ if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
solv->fixmap_all = 1;
FOR_JOB_SELECT(p, pp, select, what)
{
s = pool->solvables + p;
- if (!solv->installed || s->repo != solv->installed)
+ if (s->repo != installed)
continue;
if (!solv->fixmap.size)
- map_grow(&solv->fixmap, solv->installed->end - solv->installed->start);
- MAPSET(&solv->fixmap, p - solv->installed->start);
+ map_grow(&solv->fixmap, installed->end - installed->start);
+ MAPSET(&solv->fixmap, p - installed->start);
}
break;
case SOLVER_UPDATE:
if (select == SOLVER_SOLVABLE_ALL)
- solv->updatemap_all = 1;
- FOR_JOB_SELECT(p, pp, select, what)
{
- s = pool->solvables + p;
- if (!solv->installed || s->repo != solv->installed)
- continue;
- if (!solv->updatemap.size)
- map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
- MAPSET(&solv->updatemap, p - solv->installed->start);
+ solv->updatemap_all = 1;
+ if (how & SOLVER_FORCEBEST)
+ solv->bestupdatemap_all = 1;
+ if (how & SOLVER_CLEANDEPS)
+ {
+ FOR_REPO_SOLVABLES(installed, p, s)
+ add_cleandeps_package(solv, p);
+ }
+ }
+ else if (select == SOLVER_SOLVABLE_REPO)
+ {
+ Repo *repo = pool_id2repo(pool, what);
+ if (!repo)
+ break;
+ if (repo == installed && !(how & SOLVER_TARGETED))
+ {
+ solv->updatemap_all = 1;
+ if (how & SOLVER_FORCEBEST)
+ solv->bestupdatemap_all = 1;
+ if (how & SOLVER_CLEANDEPS)
+ {
+ FOR_REPO_SOLVABLES(installed, p, s)
+ add_cleandeps_package(solv, p);
+ }
+ break;
+ }
+ if (solv->noautotarget && !(how & SOLVER_TARGETED))
+ break;
+ /* targeted update */
+ FOR_REPO_SOLVABLES(repo, p, s)
+ add_update_target(solv, p, how);
+ }
+ else
+ {
+ if (!(how & SOLVER_TARGETED))
+ {
+ int targeted = 1;
+ FOR_JOB_SELECT(p, pp, select, what)
+ {
+ s = pool->solvables + p;
+ if (s->repo != installed)
+ continue;
+ if (!solv->updatemap.size)
+ map_grow(&solv->updatemap, installed->end - installed->start);
+ MAPSET(&solv->updatemap, p - installed->start);
+ if (how & SOLVER_FORCEBEST)
+ {
+ if (!solv->bestupdatemap.size)
+ map_grow(&solv->bestupdatemap, installed->end - installed->start);
+ MAPSET(&solv->bestupdatemap, p - installed->start);
+ }
+ if (how & SOLVER_CLEANDEPS)
+ add_cleandeps_package(solv, p);
+ targeted = 0;
+ }
+ if (!targeted || solv->noautotarget)
+ break;
+ }
+ FOR_JOB_SELECT(p, pp, select, what)
+ add_update_target(solv, p, how);
}
break;
default:
}
}
+ if (solv->update_targets)
+ transform_update_targets(solv);
+
oldnrules = solv->nrules;
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
FOR_REPO_SOLVABLES(installed, p, s)
solver_addrpmrulesforsolvable(solv, s, &addedmap);
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for updaters of installed solvables ***\n");
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
oldnrules = solv->nrules;
FOR_REPO_SOLVABLES(installed, p, s)
solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
}
/*
* (to be installed or removed)
*/
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
oldnrules = solv->nrules;
for (i = 0; i < job->count; i += 2)
{
{
solv->dupmap_all = 1;
solv->updatemap_all = 1;
+ if (how & SOLVER_FORCEBEST)
+ solv->bestupdatemap_all = 1;
}
if (!solv->dupmap_all)
hasdupjob = 1;
break;
}
}
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
/*
* add rules for suggests, enhances
*/
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for suggested/enhanced packages ***\n");
oldnrules = solv->nrules;
solver_addrpmrulesforweak(solv, &addedmap);
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
/*
* first pass done, we now have all the rpm rules we need.
* as an empty system (remove all packages) is a valid solution
*/
- IF_POOLDEBUG (SAT_DEBUG_STATS)
+ IF_POOLDEBUG (SOLV_DEBUG_STATS)
{
int possible = 0, installable = 0;
for (i = 1; i < pool->nsolvables; i++)
if (MAPTST(&addedmap, i))
possible++;
}
- POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
}
- solver_unifyrules(solv); /* remove duplicate rpm rules */
- solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
+ if (solv->nrules > initialnrules)
+ solver_unifyrules(solv); /* remove duplicate rpm rules */
+ solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
- POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule memory usage: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
- POOL_DEBUG(SAT_DEBUG_STATS, "rpm rule creation took %d ms\n", sat_timems(now));
+ if (solv->nrules > initialnrules)
+ addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
+
+ POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
/* create dup maps if needed. We need the maps early to create our
* update rules */
* best effort mode
*/
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
solv->featurerules = solv->nrules; /* mark start of feature rules */
if (installed)
{
* except that downgrades/archchanges/vendorchanges are not allowed
*/
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
solv->updaterules = solv->nrules;
if (installed)
assert(solv->dupmap_all && !sr->p);
continue;
}
- if (!solver_samerule(solv, r, sr))
- {
- /* identical rule, kill unneeded one */
- if (solv->allowuninstall)
- {
- /* keep feature rule, make it weak */
- memset(r, 0, sizeof(*r));
- queue_push(&solv->weakruleq, sr - solv->rules);
- }
- else
- {
- /* keep update rule */
- memset(sr, 0, sizeof(*sr));
- }
- }
- else if (solv->allowuninstall)
- {
- /* make both feature and update rule weak */
- queue_push(&solv->weakruleq, r - solv->rules);
- queue_push(&solv->weakruleq, sr - solv->rules);
- }
+ if (!solver_rulecmp(solv, r, sr))
+ memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
else
- solver_disablerule(solv, sr);
+ solver_disablerule(solv, sr); /* disable feature rule */
}
/* consistency check: we added a rule for _every_ installed solvable */
assert(solv->nrules - solv->updaterules == installed->end - installed->start);
* now add all job rules
*/
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
-
solv->jobrules = solv->nrules;
for (i = 0; i < job->count; i += 2)
{
oldnrules = solv->nrules;
+ if (i && i == solv->pooljobcnt)
+ POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
how = job->elements[i];
what = job->elements[i + 1];
weak = how & SOLVER_WEAK;
switch (how & SOLVER_JOBMASK)
{
case SOLVER_INSTALL:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
+ map_grow(&solv->cleandepsmap, installed->end - installed->start);
if (select == SOLVER_SOLVABLE)
{
p = what;
p = queue_shift(&q); /* get first candidate */
d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
}
+ /* force install of namespace supplements hack */
+ if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
+ {
+ Reldep *rd = GETRELDEP(pool, what);
+ if (rd->flags == REL_NAMESPACE)
+ {
+ p = SYSTEMSOLVABLE;
+ if (!solv->installsuppdepq)
+ {
+ solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->installsuppdepq);
+ }
+ queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
+ }
+ }
solver_addjobrule(solv, p, d, i, weak);
+ if (how & SOLVER_FORCEBEST)
+ hasbestinstalljob = 1;
break;
case SOLVER_ERASE:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
- if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && solv->installed)
- map_grow(&solv->cleandepsmap, solv->installed->end - solv->installed->start);
- if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
- {
- /* special case for "erase a specific solvable": we also
- * erase all other solvables with that name, so that they
- * don't get picked up as replacement */
- /* XXX: look also at packages that obsolete this package? */
- name = pool->solvables[what].name;
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
+ if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
+ map_grow(&solv->cleandepsmap, installed->end - installed->start);
+ /* specific solvable: by id or by nevra */
+ name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
+ if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
+ {
+ FOR_POOL_SOLVABLES(p)
+ solver_addjobrule(solv, -p, 0, i, weak);
+ }
+ else if (select == SOLVER_SOLVABLE_REPO)
+ {
+ Repo *repo = pool_id2repo(pool, what);
+ if (repo)
+ FOR_REPO_SOLVABLES(repo, p, s)
+ solver_addjobrule(solv, -p, 0, i, weak);
+ }
+ FOR_JOB_SELECT(p, pp, select, what)
+ {
+ s = pool->solvables + p;
+ if (installed && s->repo == installed)
+ name = !name ? s->name : -1;
+ solver_addjobrule(solv, -p, 0, i, weak);
+ }
+ /* special case for "erase a specific solvable": we also
+ * erase all other solvables with that name, so that they
+ * don't get picked up as replacement.
+ * name is > 0 if exactly one installed solvable matched.
+ */
+ /* XXX: look also at packages that obsolete this package? */
+ if (name > 0)
+ {
+ int j, k;
+ k = solv->nrules;
FOR_PROVIDES(p, pp, name)
{
- if (p == what)
- continue;
s = pool->solvables + p;
if (s->name != name)
continue;
/* keep other versions installed */
- if (s->repo == solv->installed)
+ if (s->repo == installed)
continue;
/* keep installcandidates of other jobs */
if (MAPTST(&installcandidatemap, p))
continue;
- solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
+ /* don't add the same rule twice */
+ for (j = oldnrules; j < k; j++)
+ if (solv->rules[j].p == -p)
+ break;
+ if (j == k)
+ solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
}
}
- FOR_JOB_SELECT(p, pp, select, what)
- solver_addjobrule(solv, -p, 0, i, weak);
break;
case SOLVER_UPDATE:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
break;
case SOLVER_VERIFY:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
break;
case SOLVER_WEAKENDEPS:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
if (select != SOLVER_SOLVABLE)
break;
s = pool->solvables + what;
weaken_solvable_deps(solv, what);
break;
case SOLVER_NOOBSOLETES:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sno obsolete %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
break;
case SOLVER_LOCK:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
- FOR_JOB_SELECT(p, pp, select, what)
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ if (select == SOLVER_SOLVABLE_ALL)
{
- s = pool->solvables + p;
- solver_addjobrule(solv, installed && s->repo == installed ? p : -p, 0, i, weak);
+ FOR_POOL_SOLVABLES(p)
+ solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
+ }
+ else if (select == SOLVER_SOLVABLE_REPO)
+ {
+ Repo *repo = pool_id2repo(pool, what);
+ if (repo)
+ FOR_REPO_SOLVABLES(repo, p, s)
+ solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
}
+ FOR_JOB_SELECT(p, pp, select, what)
+ solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
break;
case SOLVER_DISTUPGRADE:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
break;
case SOLVER_DROP_ORPHANED:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
- if (select == SOLVER_SOLVABLE_ALL)
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
+ if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
solv->droporphanedmap_all = 1;
FOR_JOB_SELECT(p, pp, select, what)
{
}
break;
case SOLVER_USERINSTALLED:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
break;
default:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: unknown job\n");
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
break;
}
* debug
*/
- IF_POOLDEBUG (SAT_DEBUG_JOB)
+ IF_POOLDEBUG (SOLV_DEBUG_JOB)
{
int j;
if (solv->nrules == oldnrules)
- POOL_DEBUG(SAT_DEBUG_JOB, " - no rule created\n");
+ POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
for (j = oldnrules; j < solv->nrules; j++)
{
- POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
- solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
+ POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
+ solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
}
}
}
solv->infarchrules = solv->infarchrules_end = solv->nrules;
if (hasdupjob)
- {
- solver_addduprules(solv, &addedmap);
- solver_freedupmaps(solv); /* no longer needed */
- }
+ solver_addduprules(solv, &addedmap);
else
solv->duprules = solv->duprules_end = solv->nrules;
+ if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
+ solver_addbestrules(solv, hasbestinstalljob);
+ else
+ solv->bestrules = solv->bestrules_end = solv->nrules;
+
+ if (hasdupjob)
+ solver_freedupmaps(solv); /* no longer needed */
+
if (1)
solver_addchoicerules(solv);
else
solv->choicerules = solv->choicerules_end = solv->nrules;
+ if (0)
+ {
+ for (i = solv->featurerules; i < solv->nrules; i++)
+ solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
+ }
/* all rules created
* --------------------------------------------------------------
* prepare for solving
map_free(&installcandidatemap);
queue_free(&q);
- POOL_DEBUG(SAT_DEBUG_STATS, "%d rpm rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules\n", solv->rpmrules_end - 1, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules, solv->choicerules_end - solv->choicerules);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "%d rpm rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->rpmrules_end - 1, solv->updaterules_end - solv->updaterules, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules, solv->choicerules_end - solv->choicerules, solv->bestrules_end - solv->bestrules);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
/* create weak map */
map_init(&solv->weakrulemap, solv->nrules);
MAPSET(&solv->weakrulemap, p);
}
+ /* enable cleandepsmap creation if we have updatepkgs */
+ if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
+ map_grow(&solv->cleandepsmap, installed->end - installed->start);
+ /* no mistakes */
+ if (solv->cleandeps_mistakes)
+ {
+ queue_free(solv->cleandeps_mistakes);
+ solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
+ }
+
/* all new rules are learnt after this point */
solv->learntrules = solv->nrules;
/* disable update rules that conflict with our job */
solver_disablepolicyrules(solv);
- /* make decisions based on job/update assertions */
+ /* make initial decisions based on assertion rules */
makeruledecisions(solv);
- POOL_DEBUG(SAT_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
/*
* ********************************************
* ********************************************
*/
- now = sat_timems(0);
+ now = solv_timems(0);
solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
- POOL_DEBUG(SAT_DEBUG_STATS, "solver took %d ms\n", sat_timems(now));
+ POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
/*
- * calculate recommended/suggested packages
+ * prepare solution queue if there were problems
*/
- findrecommendedsuggested(solv);
+ solver_prepare_solutions(solv);
+
+ POOL_DEBUG(SOLV_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
+
+ /* return number of problems */
+ return solv->problems.count ? solv->problems.count / 2 : 0;
+}
+
+Transaction *
+solver_create_transaction(Solver *solv)
+{
+ return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->noobsoletes);
+}
+
+void solver_get_orphaned(Solver *solv, Queue *orphanedq)
+{
+ queue_free(orphanedq);
+ queue_init_clone(orphanedq, &solv->orphaned);
+}
+
+void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
+{
+ Pool *pool = solv->pool;
+ Queue redoq, disabledq;
+ int goterase, i;
+ Solvable *s;
+ Rule *r;
+ Map obsmap;
+
+ if (!recommendationsq && !suggestionsq)
+ return;
+
+ map_init(&obsmap, pool->nsolvables);
+ if (solv->installed)
+ {
+ Id obs, *obsp, p, po, ppo;
+ for (p = solv->installed->start; p < solv->installed->end; p++)
+ {
+ s = pool->solvables + p;
+ if (s->repo != solv->installed || !s->obsoletes)
+ continue;
+ if (solv->decisionmap[p] <= 0)
+ continue;
+ if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
+ continue;
+ obsp = s->repo->idarraydata + s->obsoletes;
+ /* foreach obsoletes */
+ while ((obs = *obsp++) != 0)
+ FOR_PROVIDES(po, ppo, obs)
+ MAPSET(&obsmap, po);
+ }
+ }
+
+ queue_init(&redoq);
+ queue_init(&disabledq);
+ goterase = 0;
+ /* disable all erase jobs (including weak "keep uninstalled" rules) */
+ for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
+ {
+ if (r->d < 0) /* disabled ? */
+ continue;
+ if (r->p >= 0) /* install job? */
+ continue;
+ queue_push(&disabledq, i);
+ solver_disablerule(solv, r);
+ goterase++;
+ }
+
+ if (goterase)
+ {
+ enabledisablelearntrules(solv);
+ removedisabledconflicts(solv, &redoq);
+ }
/*
- * prepare solution queue if there were problems
+ * find recommended packages
*/
- solver_prepare_solutions(solv);
+ if (recommendationsq)
+ {
+ Id rec, *recp, p, pp;
+
+ queue_empty(recommendationsq);
+ /* create map of all recommened packages */
+ solv->recommends_index = -1;
+ MAPZERO(&solv->recommendsmap);
+
+ /* put all packages the solver already chose in the map */
+ if (solv->decisioncnt_weak)
+ {
+ for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
+ {
+ Id why;
+ why = solv->decisionq_why.elements[i];
+ if (why)
+ continue; /* forced by unit rule */
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ continue;
+ MAPSET(&solv->recommendsmap, p);
+ }
+ }
+
+ for (i = 0; i < solv->decisionq.count; i++)
+ {
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ continue;
+ s = pool->solvables + p;
+ if (s->recommends)
+ {
+ recp = s->repo->idarraydata + s->recommends;
+ while ((rec = *recp++) != 0)
+ {
+ FOR_PROVIDES(p, pp, rec)
+ if (solv->decisionmap[p] > 0)
+ break;
+ if (p)
+ {
+ if (!noselected)
+ {
+ FOR_PROVIDES(p, pp, rec)
+ if (solv->decisionmap[p] > 0)
+ MAPSET(&solv->recommendsmap, p);
+ }
+ continue; /* p != 0: already fulfilled */
+ }
+ FOR_PROVIDES(p, pp, rec)
+ MAPSET(&solv->recommendsmap, p);
+ }
+ }
+ }
+ for (i = 1; i < pool->nsolvables; i++)
+ {
+ if (solv->decisionmap[i] < 0)
+ continue;
+ if (solv->decisionmap[i] > 0 && noselected)
+ continue;
+ if (MAPTST(&obsmap, i))
+ continue;
+ s = pool->solvables + i;
+ if (!MAPTST(&solv->recommendsmap, i))
+ {
+ if (!s->supplements)
+ continue;
+ if (!pool_installable(pool, s))
+ continue;
+ if (!solver_is_supplementing(solv, s))
+ continue;
+ }
+ queue_push(recommendationsq, i);
+ }
+ /* we use MODE_SUGGEST here so that repo prio is ignored */
+ policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
+ }
/*
- * finally prepare transaction info
+ * find suggested packages
*/
- transaction_calculate(&solv->trans, &solv->decisionq, &solv->noobsoletes);
+
+ if (suggestionsq)
+ {
+ Id sug, *sugp, p, pp;
- POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
- POOL_DEBUG(SAT_DEBUG_STATS, "solver_solve took %d ms\n", sat_timems(solve_start));
+ queue_empty(suggestionsq);
+ /* create map of all suggests that are still open */
+ solv->recommends_index = -1;
+ MAPZERO(&solv->suggestsmap);
+ for (i = 0; i < solv->decisionq.count; i++)
+ {
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ continue;
+ s = pool->solvables + p;
+ if (s->suggests)
+ {
+ sugp = s->repo->idarraydata + s->suggests;
+ while ((sug = *sugp++) != 0)
+ {
+ FOR_PROVIDES(p, pp, sug)
+ if (solv->decisionmap[p] > 0)
+ break;
+ if (p)
+ {
+ if (!noselected)
+ {
+ FOR_PROVIDES(p, pp, sug)
+ if (solv->decisionmap[p] > 0)
+ MAPSET(&solv->suggestsmap, p);
+ }
+ continue; /* already fulfilled */
+ }
+ FOR_PROVIDES(p, pp, sug)
+ MAPSET(&solv->suggestsmap, p);
+ }
+ }
+ }
+ for (i = 1; i < pool->nsolvables; i++)
+ {
+ if (solv->decisionmap[i] < 0)
+ continue;
+ if (solv->decisionmap[i] > 0 && noselected)
+ continue;
+ if (MAPTST(&obsmap, i))
+ continue;
+ s = pool->solvables + i;
+ if (!MAPTST(&solv->suggestsmap, i))
+ {
+ if (!s->enhances)
+ continue;
+ if (!pool_installable(pool, s))
+ continue;
+ if (!solver_is_enhancing(solv, s))
+ continue;
+ }
+ queue_push(suggestionsq, i);
+ }
+ policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
+ }
+
+ /* undo removedisabledconflicts */
+ if (redoq.count)
+ undo_removedisabledconflicts(solv, &redoq);
+ queue_free(&redoq);
+
+ /* undo job rule disabling */
+ for (i = 0; i < disabledq.count; i++)
+ solver_enablerule(solv, solv->rules + disabledq.elements[i]);
+ queue_free(&disabledq);
+ map_free(&obsmap);
}
+
/***********************************************************************/
/* disk usage computations */
}
void
+solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
+{
+ pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
+}
+
+void
solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
{
+ Pool *pool = solv->pool;
Map installedmap;
- solver_create_state_maps(solv, &installedmap, 0);
- pool_trivial_installable_noobsoletesmap(solv->pool, &installedmap, pkgs, res, solv->noobsoletes.size ? &solv->noobsoletes : 0);
+ int i;
+ pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
+ pool_trivial_installable_noobsoletesmap(pool, &installedmap, pkgs, res, solv->noobsoletes.size ? &solv->noobsoletes : 0);
+ for (i = 0; i < res->count; i++)
+ if (res->elements[i] != -1)
+ {
+ Solvable *s = pool->solvables + pkgs->elements[i];
+ if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
+ res->elements[i] = -1;
+ }
map_free(&installedmap);
}
+/*-------------------------------------------------------------------
+ *
+ * decision introspection
+ */
+
+int
+solver_get_decisionlevel(Solver *solv, Id p)
+{
+ return solv->decisionmap[p];
+}
+
+void
+solver_get_decisionqueue(Solver *solv, Queue *decisionq)
+{
+ queue_free(decisionq);
+ queue_init_clone(decisionq, &solv->decisionq);
+}
+
+int
+solver_get_lastdecisionblocklevel(Solver *solv)
+{
+ Id p;
+ if (solv->decisionq.count == 0)
+ return 0;
+ p = solv->decisionq.elements[solv->decisionq.count - 1];
+ if (p < 0)
+ p = -p;
+ return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
+}
+
+void
+solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
+{
+ Id p;
+ int i;
+
+ queue_empty(decisionq);
+ for (i = 0; i < solv->decisionq.count; i++)
+ {
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ p = -p;
+ if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
+ break;
+ }
+ if (i == solv->decisionq.count)
+ return;
+ for (i = 0; i < solv->decisionq.count; i++)
+ {
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ p = -p;
+ if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
+ queue_push(decisionq, p);
+ else
+ break;
+ }
+}
+
+int
+solver_describe_decision(Solver *solv, Id p, Id *infop)
+{
+ int i;
+ Id pp, why;
+
+ if (infop)
+ *infop = 0;
+ if (!solv->decisionmap[p])
+ return SOLVER_REASON_UNRELATED;
+ pp = solv->decisionmap[p] < 0 ? -p : p;
+ for (i = 0; i < solv->decisionq.count; i++)
+ if (solv->decisionq.elements[i] == pp)
+ break;
+ if (i == solv->decisionq.count) /* just in case... */
+ return SOLVER_REASON_UNRELATED;
+ why = solv->decisionq_why.elements[i];
+ if (why > 0)
+ {
+ if (infop)
+ *infop = why;
+ return SOLVER_REASON_UNIT_RULE;
+ }
+ why = -why;
+ if (i < solv->decisioncnt_update)
+ {
+ if (i == 0)
+ {
+ if (infop)
+ *infop = SYSTEMSOLVABLE;
+ return SOLVER_REASON_KEEP_INSTALLED;
+ }
+ if (infop)
+ *infop = why;
+ return SOLVER_REASON_RESOLVE_JOB;
+ }
+ if (i < solv->decisioncnt_keep)
+ {
+ if (why == 0 && pp < 0)
+ return SOLVER_REASON_CLEANDEPS_ERASE;
+ if (infop)
+ {
+ if (why >= solv->updaterules && why < solv->updaterules_end)
+ *infop = why - solv->updaterules;
+ else if (why >= solv->featurerules && why < solv->featurerules_end)
+ *infop = why - solv->featurerules;
+ }
+ return SOLVER_REASON_UPDATE_INSTALLED;
+ }
+ if (i < solv->decisioncnt_resolve)
+ {
+ if (why == 0 && pp < 0)
+ return SOLVER_REASON_CLEANDEPS_ERASE;
+ if (infop)
+ {
+ if (why >= solv->updaterules && why < solv->updaterules_end)
+ *infop = why - solv->updaterules;
+ else if (why >= solv->featurerules && why < solv->featurerules_end)
+ *infop = why - solv->featurerules;
+ }
+ return SOLVER_REASON_KEEP_INSTALLED;
+ }
+ if (i < solv->decisioncnt_weak)
+ {
+ if (infop)
+ *infop = why;
+ return SOLVER_REASON_RESOLVE;
+ }
+ if (solv->decisionq.count < solv->decisioncnt_orphan)
+ return SOLVER_REASON_WEAKDEP;
+ return SOLVER_REASON_RESOLVE_ORPHAN;
+}
+
+
+void
+solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
+{
+ Pool *pool = solv->pool;
+ int i;
+ int level = solv->decisionmap[p];
+ int decisionno;
+ Solvable *s;
+
+ queue_empty(whyq);
+ if (level < 0)
+ return; /* huh? */
+ for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
+ if (solv->decisionq.elements[decisionno] == p)
+ break;
+ if (decisionno == solv->decisionq.count)
+ return; /* huh? */
+ if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
+ return; /* huh? */
+
+ /* 1) list all packages that recommend us */
+ for (i = 1; i < pool->nsolvables; i++)
+ {
+ Id *recp, rec, pp2, p2;
+ if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
+ continue;
+ s = pool->solvables + i;
+ if (!s->recommends)
+ continue;
+ if (!solv->addalreadyrecommended && s->repo == solv->installed)
+ continue;
+ recp = s->repo->idarraydata + s->recommends;
+ while ((rec = *recp++) != 0)
+ {
+ int found = 0;
+ FOR_PROVIDES(p2, pp2, rec)
+ {
+ if (p2 == p)
+ found = 1;
+ else
+ {
+ /* if p2 is already installed, this recommends is ignored */
+ if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
+ break;
+ }
+ }
+ if (!p2 && found)
+ {
+ queue_push(whyq, SOLVER_REASON_RECOMMENDED);
+ queue_push2(whyq, p2, rec);
+ }
+ }
+ }
+ /* 2) list all supplements */
+ s = pool->solvables + p;
+ if (s->supplements && level > 0)
+ {
+ Id *supp, sup, pp2, p2;
+ /* this is a hack. to use solver_dep_fulfilled we temporarily clear
+ * everything above our level in the decisionmap */
+ for (i = decisionno; i < solv->decisionq.count; i++ )
+ {
+ p2 = solv->decisionq.elements[i];
+ if (p2 > 0)
+ solv->decisionmap[p2] = -solv->decisionmap[p2];
+ }
+ supp = s->repo->idarraydata + s->supplements;
+ while ((sup = *supp++) != 0)
+ if (solver_dep_fulfilled(solv, sup))
+ {
+ int found = 0;
+ /* let's see if this is an easy supp */
+ FOR_PROVIDES(p2, pp2, sup)
+ {
+ if (!solv->addalreadyrecommended && solv->installed)
+ {
+ if (pool->solvables[p2].repo == solv->installed)
+ continue;
+ }
+ if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
+ {
+ queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
+ queue_push2(whyq, p2, sup);
+ found = 1;
+ }
+ }
+ if (!found)
+ {
+ /* hard case, just note dependency with no package */
+ queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
+ queue_push2(whyq, 0, sup);
+ }
+ }
+ for (i = decisionno; i < solv->decisionq.count; i++)
+ {
+ p2 = solv->decisionq.elements[i];
+ if (p2 > 0)
+ solv->decisionmap[p2] = -solv->decisionmap[p2];
+ }
+ }
+}
+
+void
+pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
+{
+ Id p, pp;
+ how &= SOLVER_SELECTMASK;
+ queue_empty(pkgs);
+ if (how == SOLVER_SOLVABLE_ALL)
+ {
+ FOR_POOL_SOLVABLES(p)
+ queue_push(pkgs, p);
+ }
+ else if (how == SOLVER_SOLVABLE_REPO)
+ {
+ Repo *repo = pool_id2repo(pool, what);
+ Solvable *s;
+ if (repo)
+ FOR_REPO_SOLVABLES(repo, p, s)
+ queue_push(pkgs, p);
+ }
+ else
+ {
+ FOR_JOB_SELECT(p, pp, how, what)
+ queue_push(pkgs, p);
+ }
+}
+
+int
+pool_isemptyupdatejob(Pool *pool, Id how, Id what)
+{
+ Id p, pp, pi, pip;
+ Id select = how & SOLVER_SELECTMASK;
+ if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
+ return 0;
+ if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
+ return 0;
+ if (!pool->installed)
+ return 1;
+ FOR_JOB_SELECT(p, pp, select, what)
+ if (pool->solvables[p].repo == pool->installed)
+ return 0;
+ /* hard work */
+ FOR_JOB_SELECT(p, pp, select, what)
+ {
+ Solvable *s = pool->solvables + p;
+ FOR_PROVIDES(pi, pip, s->name)
+ {
+ Solvable *si = pool->solvables + pi;
+ if (si->repo != pool->installed || si->name != s->name)
+ continue;
+ return 0;
+ }
+ if (s->obsoletes)
+ {
+ Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
+ while ((obs = *obsp++) != 0)
+ {
+ FOR_PROVIDES(pi, pip, obs)
+ {
+ Solvable *si = pool->solvables + pi;
+ if (si->repo != pool->installed)
+ continue;
+ if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
+ continue;
+ if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
+ continue;
+ return 0;
+ }
+ }
+ }
+ }
+ return 1;
+}