#include <assert.h>
#include "solver.h"
+#include "solver_private.h"
#include "bitmap.h"
#include "pool.h"
#include "util.h"
-#include "evr.h"
#include "policy.h"
+#include "poolarch.h"
#include "solverdebug.h"
-
-#define CODE10 0 /* set to '1' to enable patch atoms */
+#include "cplxdeps.h"
+#include "linkedpkg.h"
#define RULES_BLOCK 63
+
/********************************************************************
*
* dependency check helpers
/*-------------------------------------------------------------------
* 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.
+ * Map m is the map used when called from dep_possible.
*/
+static int
+solver_is_updating(Solver *solv, Id p)
+{
+ /* check if the update rule is true */
+ Pool *pool = solv->pool;
+ Rule *r;
+ Id l, pp;
+ if (solv->decisionmap[p] >= 0)
+ return 0; /* old package stayed */
+ r = solv->rules + solv->updaterules + (p - solv->installed->start);
+ FOR_RULELITERALS(l, pp, r)
+ if (l > 0 && l != p && solv->decisionmap[l] > 0)
+ return 1;
+ return 0;
+}
+
int
-solver_splitprovides(Solver *solv, Id dep)
+solver_splitprovides(Solver *solv, Id dep, Map *m)
{
Pool *pool = solv->pool;
- Id p, *pp;
+ Id p, pp;
Reldep *rd;
Solvable *s;
rd = GETRELDEP(pool, dep);
if (rd->flags != REL_WITH)
return 0;
- FOR_PROVIDES(p, pp, dep)
+ /*
+ * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
+ * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
+ * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
+ * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
+ * we filter the package name further down anyway).
+ */
+ if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
+ pp = pool_searchlazywhatprovidesq(pool, rd->evr);
+ else
+ pp = pool_whatprovides(pool, dep);
+ while ((p = pool->whatprovidesdata[pp++]) != 0)
{
+ /* 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)
+ continue;
+ /* check if the package is updated. if m is set, we're called from dep_possible */
+ if (m || solver_is_updating(solv, p))
return 1;
}
return 0;
}
-/*-------------------------------------------------------------------
- * solver_dep_installed
- */
-
-int
-solver_dep_installed(Solver *solv, Id dep)
+/* mirrors solver_dep_fulfilled, but returns 2 if a new package
+ * was involved */
+static int
+solver_dep_fulfilled_alreadyinstalled(Solver *solv, Id dep)
{
-#if 0
Pool *pool = solv->pool;
- Id p, *pp;
+ Id p, pp;
+ int r;
if (ISRELDEP(dep))
{
Reldep *rd = GETRELDEP(pool, dep);
if (rd->flags == REL_AND)
+ {
+ int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
+ if (!r1)
+ return 0;
+ r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
+ if (!r2)
+ return 0;
+ return r1 == 2 || r2 == 2 ? 2 : 1;
+ }
+ if (rd->flags == REL_OR)
{
- if (!solver_dep_installed(solv, rd->name))
+ int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
+ r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
+ if (!r1 && !r2)
return 0;
- return solver_dep_installed(solv, rd->evr);
+ return r1 == 2 || r2 == 2 ? 2 : 1;
+ }
+ if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
+ return solver_splitprovides(solv, rd->evr, 0);
+ if (rd->flags == REL_NAMESPACE && solv->installsuppdepq)
+ {
+ Queue *q = solv->installsuppdepq;
+ int i;
+ for (i = 0; i < q->count; i++)
+ if (q->elements[i] == dep || q->elements[i] == rd->name)
+ return 2;
}
- if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
- return solver_dep_installed(solv, rd->evr);
}
+ r = 0;
FOR_PROVIDES(p, pp, dep)
- {
- if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
- return 1;
- }
-#endif
- return 0;
+ if (solv->decisionmap[p] > 0)
+ {
+ Solvable *s = pool->solvables + p;
+ if (s->repo && s->repo != solv->installed)
+ return 2;
+ r = 1;
+ }
+ return r;
}
+static int
+solver_is_supplementing_alreadyinstalled(Solver *solv, Solvable *s)
+{
+ Id sup, *supp;
+ supp = s->repo->idarraydata + s->supplements;
+ while ((sup = *supp++) != 0)
+ if (solver_dep_fulfilled_alreadyinstalled(solv, sup) == 2)
+ return 1;
+ return 0;
+}
-/*-------------------------------------------------------------------
- * Check if dependenc is possible
- *
- * this mirrors solver_dep_fulfilled
- * but uses map m instead of the decisionmap
- */
-
-static inline int
-dep_possible(Solver *solv, Id dep, Map *m)
+static Id
+autouninstall(Solver *solv, Id *problem)
{
Pool *pool = solv->pool;
- Id p, *pp;
+ int i;
+ int lastfeature = 0, lastupdate = 0;
+ Id v;
+ Id extraflags = -1;
- if (ISRELDEP(dep))
+ for (i = 0; (v = problem[i]) != 0; i++)
{
- Reldep *rd = GETRELDEP(pool, dep);
- if (rd->flags == REL_AND)
+ if (v < 0)
+ extraflags &= solv->job.elements[-v - 1];
+ if (v >= solv->updaterules && v < solv->updaterules_end)
{
- if (!dep_possible(solv, rd->name, m))
- return 0;
- return dep_possible(solv, rd->evr, m);
+ /* check if identical to feature rule, we don't like that */
+ Rule *r = solv->rules + solv->featurerules + (v - solv->updaterules);
+ if (!r->p)
+ {
+ /* update rule == feature rule */
+ if (v > lastfeature)
+ lastfeature = v;
+ continue;
+ }
+ if (v > lastupdate)
+ lastupdate = v;
}
- 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);
}
- FOR_PROVIDES(p, pp, dep)
+ 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)
{
- if (MAPTST(m, p))
- return 1;
+ /* add the package to the updatepkgs list, this will automatically turn
+ * on cleandeps mode */
+ Id p = solv->rules[v].p;
+ if (!solv->cleandeps_updatepkgs)
+ {
+ 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);
+ }
}
- return 0;
+ return v;
}
-/********************************************************************
- *
- * Rule handling
- *
- * - unify rules, remove duplicates
- */
-
-static Pool *unifyrules_sortcmp_data;
+/************************************************************************/
-/*-------------------------------------------------------------------
- *
- * compare rules for unification sort
+/*
+ * enable/disable learnt rules
*
+ * we have enabled or disabled some of our rules. We now reenable all
+ * of our learnt rules except the ones that were learnt from rules that
+ * are now disabled.
*/
-
-static int
-unifyrules_sortcmp(const void *ap, const void *bp)
+static void
+enabledisablelearntrules(Solver *solv)
{
- Pool *pool = unifyrules_sortcmp_data;
- Rule *a = (Rule *)ap;
- Rule *b = (Rule *)bp;
- Id *ad, *bd;
- int x;
-
- x = a->p - b->p;
- if (x)
- return x; /* p differs */
-
- /* identical p */
- if (a->d == 0 && b->d == 0)
- return a->w2 - b->w2; /* assertion: return w2 diff */
-
- if (a->d == 0) /* a is assertion, b not */
- {
- x = a->w2 - pool->whatprovidesdata[b->d];
- return x ? x : -1;
- }
+ Pool *pool = solv->pool;
+ Rule *r;
+ Id why, *whyp;
+ int i;
- if (b->d == 0) /* b is assertion, a not */
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
+ for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
{
- x = pool->whatprovidesdata[a->d] - b->w2;
- return x ? x : 1;
+ whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
+ while ((why = *whyp++) != 0)
+ {
+ assert(why > 0 && why < i);
+ if (solv->rules[why].d < 0)
+ break;
+ }
+ /* why != 0: we found a disabled rule, disable the learnt rule */
+ if (why && r->d >= 0)
+ {
+ IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
+ {
+ 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 (SOLV_DEBUG_SOLUTIONS)
+ {
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
+ solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
+ }
+ solver_enablerule(solv, r);
+ }
}
-
- /* compare whatprovidesdata */
- ad = pool->whatprovidesdata + a->d;
- bd = pool->whatprovidesdata + b->d;
- while (*bd)
- if ((x = *ad++ - *bd++) != 0)
- return x;
- return *ad;
}
-/*-------------------------------------------------------------------
+/*
+ * make assertion rules into decisions
*
- * unify rules
- * go over all rules and remove duplicates
+ * 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
-unifyrules(Solver *solv)
+makeruledecisions(Solver *solv)
{
Pool *pool = solv->pool;
- int i, j;
- Rule *ir, *jr;
+ int i, ri, ii;
+ Rule *r, *rr;
+ Id v, vv;
+ int decisionstart;
+ int record_proof = 1;
+ int oldproblemcount;
+ int havedisabled = 0;
- if (solv->nrules <= 1) /* nothing to unify */
- return;
+ /* 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 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;
+ }
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
+ /* note that the ruleassertions queue is ordered */
+ for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ {
+ ri = solv->ruleassertions.elements[ii];
+ r = solv->rules + ri;
- /* sort rules first */
- unifyrules_sortcmp_data = solv->pool;
- qsort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp);
+ 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;
+ }
- /* prune rules
- * i = unpruned
- * j = pruned
- */
- jr = 0;
- for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
- {
- if (jr && !unifyrules_sortcmp(ir, jr))
- continue; /* prune! */
- jr = solv->rules + j++; /* keep! */
- if (ir != jr)
- *jr = *ir;
- }
+ if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
+ continue;
- /* reduced count from nrules to j rules */
- POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
+ /* do weak rules in phase 2 */
+ if (ri < solv->learntrules && solv->weakrulemap.size && MAPTST(&solv->weakrulemap, ri))
+ continue;
- /* adapt rule buffer */
- solv->nrules = j;
- solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
- /*
- * debug: statistics
- */
- IF_POOLDEBUG (SAT_DEBUG_STATS)
- {
- int binr = 0;
- int lits = 0;
- Id *dp;
- Rule *r;
+ v = r->p;
+ vv = v > 0 ? v : -v;
- for (i = 1; i < solv->nrules; i++)
- {
- r = solv->rules + i;
- if (r->d == 0)
- binr++;
- else
+ if (!solv->decisionmap[vv]) /* if not yet decided */
{
- dp = solv->pool->whatprovidesdata + r->d;
- while (*dp++)
- lits++;
+ 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;
}
- }
- POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
- POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
- }
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
-}
-#if 0
+ /* 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;
-/*
- * hash rule
- */
+ /*
+ * 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
+ */
-static Hashval
-hashrule(Solver *solv, Id p, Id d, int n)
-{
- unsigned int x = (unsigned int)p;
- int *dp;
+ 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;
+ }
- if (n <= 1)
- return (x * 37) ^ (unsigned int)d;
- dp = solv->pool->whatprovidesdata + d;
- while (*dp)
- x = (x * 37) ^ (unsigned int)*dp++;
- return x;
-}
-#endif
+ /*
+ * 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);
-/*
- * add rule
- * p = direct literal; always < 0 for installed rpm rules
- * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
- *
- *
- * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
- *
- * p < 0 : pkg id of A
- * d > 0 : Offset in whatprovidesdata (list of providers of b)
- *
- * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
- * p < 0 : pkg id of A
- * d < 0 : Id of solvable (e.g. B1)
- *
- * d == 0: unary rule, assertion => (A) or (-A)
- *
- * Install: p > 0, d = 0 (A) user requested install
- * Remove: p < 0, d = 0 (-A) user requested remove
- * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
- * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
- * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
- * ? p > 0, d < 0 (A|-B)
- * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
- *
- * resulting watches:
- * ------------------
- * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
- * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
- * every other : w1 = p, w2 = whatprovidesdata[d];
- * Disabled rule: w1 = 0
- *
- * always returns a rule for non-rpm rules
- */
+ /*
+ * conflict with a pkg rule ?
+ */
+ if (solv->decisionq_why.elements[i] < solv->pkgrules_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 pkg 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 */
+ }
-static Rule *
-addrule(Solver *solv, Id p, Id d)
-{
- Pool *pool = solv->pool;
- Rule *r = 0;
- Id *dp = 0;
+ /*
+ * conflict with another job or update/feature rule
+ */
- int n = 0; /* number of literals in rule - 1
- 0 = direct assertion (single literal)
- 1 = binary rule
- >1 =
- */
+ /* 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);
- /* it often happenes that requires lead to adding the same rpm rule
- * multiple times, so we prune those duplicates right away to make
- * the work for unifyrules a bit easier */
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
- if (solv->nrules /* we already have rules */
- && !solv->rpmrules_end) /* but are not done with rpm rules */
- {
- r = solv->rules + solv->nrules - 1; /* get the last added rule */
- if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
- return r;
- }
+ /*
+ * 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 (solv->weakrulemap.size && 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);
- /*
- * compute number of literals (n) in rule
- */
-
- if (d < 0)
- {
- /* always a binary rule */
- if (p == d)
- return 0; /* ignore self conflict */
- n = 1;
- }
- else if (d > 0)
- {
- for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
- if (*dp == -p)
- return 0; /* rule is self-fulfilling */
-
- if (n == 1) /* have single provider */
- d = dp[-1]; /* take single literal */
- }
+ if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
+ solv->problems.count = oldproblemcount;
-#if 0
- if (n == 0 && !solv->rpmrules_end)
- {
- /* this is a rpm rule assertion, we do not have to allocate it */
- /* it can be identified by a level of 1 and a zero reason */
- /* we must not drop those rules from the decisionq when rewinding! */
- assert(p < 0);
- assert(solv->decisionmap[-p] == 0 || solv->decisionmap[-p] == -1);
- if (solv->decisionmap[-p])
- return 0; /* already got that one */
- queue_push(&solv->decisionq, p);
- queue_push(&solv->decisionq_why, 0);
- solv->decisionmap[-p] = -1;
- return 0;
- }
-#endif
+ 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;
- if (n == 1 && p > d)
- {
- /* smallest literal first so we can find dups */
- n = p; p = d; d = n; /* p <-> d */
- n = 1; /* re-set n, was used as temp var */
- }
+ /*
+ * phase 2: now do the weak assertions
+ */
+ if (!solv->weakrulemap.size)
+ break; /* no weak rules, no phase 2 */
+ 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;
- /*
- * check for duplicate
- */
-
- /* check if the last added rule (r) is exactly the same as what we're looking for. */
- if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
- return r; /* binary rule */
+ 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;
- /* have n-ary rule with same first literal, check other literals */
- if (r && n > 1 && r->d && r->p == p)
- {
- /* Rule where d is an offset in whatprovidesdata */
- Id *dp2;
- if (d == r->d)
- return r;
- dp2 = pool->whatprovidesdata + r->d;
- for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
- if (*dp != *dp2)
- break;
- if (*dp == *dp2)
- return r;
- }
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
+ solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
- /*
- * allocate new rule
- */
+ 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! */
+ }
+}
- /* extend rule buffer */
- solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
- r = solv->rules + solv->nrules++; /* point to rule space */
- /*
- * r = new rule
- */
-
- r->p = p;
- if (n == 0)
- {
- /* direct assertion, no watch needed */
- r->d = 0;
- r->w1 = p;
- r->w2 = 0;
- }
- else if (n == 1)
- {
- /* binary rule */
- r->d = 0;
- r->w1 = p;
- r->w2 = d;
- }
- else
- {
- r->d = d;
- r->w1 = p;
- r->w2 = pool->whatprovidesdata[d];
- }
- r->n1 = 0;
- r->n2 = 0;
-
- IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
- {
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
- solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
- }
-
- return r;
-}
-
-/*-------------------------------------------------------------------
- * disable rule
- */
+/********************************************************************/
+/* watches */
-static inline void
-disablerule(Solver *solv, Rule *r)
-{
- if (r->d >= 0)
- r->d = -r->d - 1;
-}
/*-------------------------------------------------------------------
- * enable rule
- */
-
-static inline void
-enablerule(Solver *solv, Rule *r)
-{
- if (r->d < 0)
- r->d = -r->d - 1;
-}
-
-
-/**********************************************************************************/
-
-/* a problem is an item on the solver's problem list. It can either be >0, in that
- * case it is a update rule, or it can be <0, which makes it refer to a job
- * consisting of multiple job rules.
+ * makewatches
+ *
+ * initial setup for all watches
*/
static void
-disableproblem(Solver *solv, Id v)
+makewatches(Solver *solv)
{
Rule *r;
int i;
- Id *jp;
+ int nsolvables = solv->pool->nsolvables;
- if (v > 0)
+ solv_free(solv->watches);
+ /* lower half for removals, upper half for installs */
+ solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
+ for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
{
- disablerule(solv, solv->rules + v);
- return;
+ 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;
}
- v = -(v + 1);
- jp = solv->ruletojob.elements;
- for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
- if (*jp == v)
- disablerule(solv, r);
}
+
/*-------------------------------------------------------------------
- * enableproblem
+ *
+ * add watches (for a new learned rule)
+ * sets up watches for a single rule
+ *
+ * see also makewatches() above.
*/
-static void
-enableproblem(Solver *solv, Id v)
+static inline void
+addwatches_rule(Solver *solv, Rule *r)
{
- Rule *r;
- int i;
- Id *jp;
+ int nsolvables = solv->pool->nsolvables;
- if (v > 0)
- {
- if (v >= solv->featurerules && v < solv->featurerules_end)
- {
- /* do not enable feature rule if update rule is enabled */
- r = solv->rules + (v - solv->featurerules + solv->updaterules);
- if (r->d >= 0)
- return;
- }
- enablerule(solv, solv->rules + v);
- if (v >= solv->updaterules && v < solv->updaterules_end)
- {
- /* disable feature rule when enabling update rule */
- r = solv->rules + (v - solv->updaterules + solv->featurerules);
- if (r->p)
- disablerule(solv, r);
- }
- return;
- }
- v = -(v + 1);
- jp = solv->ruletojob.elements;
- for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
- if (*jp == v)
- enablerule(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;
+}
-/************************************************************************/
+/********************************************************************/
/*
- * make assertion rules into decisions
- *
- * go through update and job rules and add direct assertions
- * to the decisionqueue. If we find a conflict, disable rules and
- * add them to problem queue.
+ * rule propagation
*/
-static void
-makeruledecisions(Solver *solv)
+
+/* shortcuts to check if a literal (positive or negative) assignment
+ * evaluates to 'true' or 'false'
+ */
+#define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
+#define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
+#define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
+
+/*-------------------------------------------------------------------
+ *
+ * propagate
+ *
+ * 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.
+ *
+ * return : 0 = everything is OK
+ * rule = conflict found in this rule
+ */
+
+static Rule *
+propagate(Solver *solv, int level)
{
Pool *pool = solv->pool;
- int i, ri, ii;
- Rule *r, *rr;
- Id v, vv;
- int decisionstart;
+ Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
+ Rule *r; /* rule */
+ Id p, pkg, other_watch;
+ Id *dp;
+ Id *decisionmap = solv->decisionmap;
+ Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
- decisionstart = solv->decisionq.count;
- for (ii = 0; ii < solv->ruleassertions.count; ii++)
+ /* foreach non-propagated decision */
+ while (solv->propagate_index < solv->decisionq.count)
{
- 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;
+ /*
+ * 'pkg' was just decided
+ * negate because our watches trigger if literal goes FALSE
+ */
+ pkg = -solv->decisionq.elements[solv->propagate_index++];
- if (!solv->decisionmap[vv]) /* if not yet decided */
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
+ {
+ 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 */
+ for (rp = watches + pkg; *rp; rp = next_rp)
{
- /*
- * 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)
+ r = solv->rules + *rp;
+ if (r->d < 0)
{
- Solvable *s = solv->pool->solvables + vv;
- if (v < 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", solvable2str(solv->pool, s));
+ /* rule is disabled, goto next */
+ if (pkg == r->w1)
+ next_rp = &r->n1;
else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "installing %s (assertion)\n", solvable2str(solv->pool, s));
+ next_rp = &r->n2;
+ continue;
}
- 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)
- {
- /* conflict with a learnt rule */
- /* can happen when packages cannot be installed for
- * multiple reasons. */
- /* we disable the learnt rule in this case */
- 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 */
-
- /*
- * conflict with system solvable ?
- */
-
- if (v == -SYSTEMSOLVABLE) {
- /* conflict with system solvable */
- queue_push(&solv->problems, solv->learnt_pool.count);
- queue_push(&solv->learnt_pool, ri);
- queue_push(&solv->learnt_pool, 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);
- disableproblem(solv, v);
- continue;
- }
-
- assert(solv->decisionq_why.elements[i]);
-
- /*
- * conflict with an rpm rule ?
- */
-
- if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
- {
- /* conflict with rpm rule assertion */
- 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);
- 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);
- disableproblem(solv, v);
- continue;
- }
-
- /*
- * conflict with another job or update/feature rule
- */
-
- /* 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);
-
- 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);
- 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;
- }
- ii = -1; /* restarts loop at 0 */
- }
- /*
- * 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 (!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])
- {
- 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)
+ IF_POOLDEBUG (SOLV_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));
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
+ solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
}
- continue;
- }
- /*
- * 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);
- disablerule(solv, r);
- }
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
-}
-
-
-/*-------------------------------------------------------------------
- * enable/disable learnt rules
- *
- * we have enabled or disabled some of our rules. We now reenable all
- * of our learnt rules but the ones that were learnt from rules that
- * are now disabled.
- */
-static void
-enabledisablelearntrules(Solver *solv)
-{
- Pool *pool = solv->pool;
- Rule *r;
- Id why, *whyp;
- int i;
- POOL_DEBUG(SAT_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];
- while ((why = *whyp++) != 0)
- {
- assert(why > 0 && why < i);
- if (solv->rules[why].d < 0)
- break;
- }
- /* why != 0: we found a disabled rule, disable the learnt rule */
- if (why && r->d >= 0)
- {
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ /*
+ * 'pkg' was just decided (was set to FALSE), so this rule
+ * may now be unit.
+ */
+ /* find the other watch */
+ if (pkg == r->w1)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
- solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+ other_watch = r->w2;
+ next_rp = &r->n1;
}
- disablerule(solv, r);
- }
- else if (!why && r->d < 0)
- {
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ else
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
- solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+ other_watch = r->w1;
+ next_rp = &r->n2;
}
- enablerule(solv, r);
- }
- }
-}
-
-
-/*-------------------------------------------------------------------
- * enable weak rules
- *
- * Enable all rules, except learnt rules, which are
- * - disabled and weak (set in weakrulemap)
- *
- */
-
-void
-enableweakrules(Solver *solv)
-{
- int i;
- Rule *r;
-
- for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
- {
- if (r->d >= 0) /* skip non-direct literals */
- continue;
- if (!MAPTST(&solv->weakrulemap, i))
- continue;
- enablerule(solv, r);
- }
-}
-
-/* FIXME: bad code ahead, replace as soon as possible */
-/* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
+ /*
+ * if the other watch is true we have nothing to do
+ */
+ if (DECISIONMAP_TRUE(other_watch))
+ continue;
-/*-------------------------------------------------------------------
- * disable update rules
- */
+ /*
+ * The other literal is FALSE or UNDEF
+ *
+ */
-static void
-disableupdaterules(Solver *solv, Queue *job, int jobidx)
-{
- Pool *pool = solv->pool;
- int i, j;
- Id how, what, p, *pp;
- Solvable *s;
- Repo *installed;
- Rule *r;
- Id lastjob = -1;
-
- installed = solv->installed;
- if (!installed)
- return;
-
- if (jobidx != -1)
- {
- how = job->elements[jobidx] & ~SOLVER_WEAK;
- switch(how)
- {
- case SOLVER_INSTALL_SOLVABLE:
- case SOLVER_ERASE_SOLVABLE:
- case SOLVER_ERASE_SOLVABLE_NAME:
- case SOLVER_ERASE_SOLVABLE_PROVIDES:
- break;
- default:
- return;
- }
- }
- /* go through all enabled job rules */
- MAPZERO(&solv->noupdate);
- for (i = solv->jobrules; i < solv->jobrules_end; i++)
- {
- r = solv->rules + i;
- if (r->d < 0) /* disabled? */
- continue;
- j = solv->ruletojob.elements[i - solv->jobrules];
- if (j == lastjob)
- continue;
- lastjob = j;
- how = job->elements[j] & ~SOLVER_WEAK;
- what = job->elements[j + 1];
- switch(how)
- {
- case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
- s = pool->solvables + what;
- if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
- break;
- FOR_PROVIDES(p, pp, s->name)
- {
- if (pool->solvables[p].name != s->name)
- continue;
- if (pool->solvables[p].repo == installed)
- MAPSET(&solv->noupdate, p - installed->start);
- }
- break;
- case SOLVER_ERASE_SOLVABLE:
- s = pool->solvables + what;
- if (s->repo == installed)
- MAPSET(&solv->noupdate, what - installed->start);
- break;
- case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
- case SOLVER_ERASE_SOLVABLE_PROVIDES:
- FOR_PROVIDES(p, pp, what)
+ if (r->d)
{
- if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- if (pool->solvables[p].repo == installed)
- MAPSET(&solv->noupdate, p - installed->start);
- }
- break;
- default:
- break;
- }
- }
+ /* Not a binary clause, try to move our watch.
+ *
+ * Go over all literals and find one that is
+ * not other_watch
+ * and not FALSE
+ *
+ * (TRUE is also ok, in that case the rule is fulfilled)
+ * As speed matters here we do not use the FOR_RULELITERALS
+ * macro.
+ */
+ if (r->p /* we have a 'p' */
+ && r->p != other_watch /* which is not watched */
+ && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
+ {
+ p = r->p;
+ }
+ else /* go find a 'd' to make 'true' */
+ {
+ /* foreach p in 'd'
+ we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
+ */
+ for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
+ {
+ if (p != other_watch /* which is not watched */
+ && !DECISIONMAP_FALSE(p)) /* and not FALSE */
+ break;
+ }
+ }
- /* fixup update rule status */
- if (jobidx != -1)
- {
- /* we just disabled job #jobidx. enable all update rules
- * that aren't disabled by the remaining job rules */
- how = job->elements[jobidx] & ~SOLVER_WEAK;
- what = job->elements[jobidx + 1];
- switch(how)
- {
- case SOLVER_INSTALL_SOLVABLE:
- s = pool->solvables + what;
- FOR_PROVIDES(p, pp, s->name)
- {
- if (pool->solvables[p].name != s->name)
- continue;
- if (pool->solvables[p].repo != installed)
- continue;
- if (MAPTST(&solv->noupdate, p - installed->start))
- continue;
- r = solv->rules + solv->updaterules + (p - installed->start);
- if (r->d >= 0)
- continue;
- enablerule(solv, r);
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ if (p)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
- solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+ /*
+ * if we found some p that is UNDEF or TRUE, move
+ * watch to it
+ */
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
+ {
+ if (p > 0)
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
+ else
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
+ }
+
+ *rp = *next_rp;
+ next_rp = rp;
+
+ if (pkg == r->w1)
+ {
+ r->w1 = p;
+ r->n1 = watches[p];
+ }
+ else
+ {
+ r->w2 = p;
+ r->n2 = watches[p];
+ }
+ watches[p] = r - solv->rules;
+ continue;
}
- }
- break;
- case SOLVER_ERASE_SOLVABLE:
- s = pool->solvables + what;
- if (s->repo != installed)
- break;
- if (MAPTST(&solv->noupdate, what - installed->start))
- break;
- r = solv->rules + solv->updaterules + (what - installed->start);
- if (r->d >= 0)
- break;
- enablerule(solv, r);
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ /* search failed, thus all unwatched literals are FALSE */
+
+ } /* not binary */
+
+ /*
+ * 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 (SOLV_DEBUG_PROPAGATE)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
- solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
+ solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
}
- break;
- case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
- case SOLVER_ERASE_SOLVABLE_PROVIDES:
- FOR_PROVIDES(p, pp, what)
+
+ if (other_watch > 0)
+ decisionmap[other_watch] = level; /* install! */
+ else
+ decisionmap[-other_watch] = -level; /* remove! */
+
+ queue_push(&solv->decisionq, other_watch);
+ queue_push(&solv->decisionq_why, r - solv->rules);
+
+ IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
{
- if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- if (pool->solvables[p].repo != installed)
- continue;
- if (MAPTST(&solv->noupdate, p - installed->start))
- continue;
- r = solv->rules + solv->updaterules + (p - installed->start);
- if (r->d >= 0)
- continue;
- enablerule(solv, r);
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
- {
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
- solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
- }
+ if (other_watch > 0)
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
+ else
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
}
- break;
- default:
- break;
- }
- return;
- }
- for (i = 0; i < installed->nsolvables; i++)
- {
- r = solv->rules + solv->updaterules + i;
- if (r->d >= 0 && MAPTST(&solv->noupdate, i))
- disablerule(solv, r); /* was enabled, need to disable */
- r = solv->rules + solv->featurerules + i;
- if (r->d >= 0 && MAPTST(&solv->noupdate, i))
- disablerule(solv, r); /* was enabled, need to disable */
- }
+ } /* foreach rule involving 'pkg' */
+
+ } /* while we have non-decided decisions */
+
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
+
+ return 0; /* all is well */
}
-#if CODE10
+
+/********************************************************************/
+/* Analysis */
+
/*-------------------------------------------------------------------
- * add patch atom requires
+ *
+ * revert
+ * revert decisionq to a level
*/
static void
-addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
+revert(Solver *solv, int level)
{
Pool *pool = solv->pool;
- Id fre, *frep, p, *pp, ndp;
- Solvable *ps;
- Queue fq;
- Id qbuf[64];
- int i, used = 0;
-
- queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
- queue_push(&fq, -(s - pool->solvables));
- for (; *dp; dp++)
- queue_push(&fq, *dp);
- ndp = pool_queuetowhatprovides(pool, &fq);
- frep = s->repo->idarraydata + s->freshens;
- while ((fre = *frep++) != 0)
+ Id v, vv;
+ while (solv->decisionq.count)
{
- FOR_PROVIDES(p, pp, fre)
- {
- ps = pool->solvables + p;
- addrule(solv, -p, ndp);
- used = 1;
- if (!MAPTST(m, p))
- queue_push(q, p);
- }
+ v = solv->decisionq.elements[solv->decisionq.count - 1];
+ vv = v > 0 ? v : -v;
+ if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
+ break;
+ 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--;
+ solv->propagate_index = solv->decisionq.count;
}
- if (used)
+ while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
+ solv->branches.count -= solv->branches.elements[solv->branches.count - 2];
+ if (solv->recommends_index > solv->decisionq.count)
+ solv->recommends_index = -1; /* rebuild recommends/suggests maps */
+ if (solv->decisionq.count < solv->decisioncnt_jobs)
+ solv->decisioncnt_jobs = 0;
+ if (solv->decisionq.count < solv->decisioncnt_update)
+ solv->decisioncnt_update = 0;
+ if (solv->decisionq.count < solv->decisioncnt_keep)
+ solv->decisioncnt_keep = 0;
+ if (solv->decisionq.count < solv->decisioncnt_resolve)
+ solv->decisioncnt_resolve = 0;
+ if (solv->decisionq.count < solv->decisioncnt_weak)
+ solv->decisioncnt_weak= 0;
+ if (solv->decisionq.count < solv->decisioncnt_orphan)
+ solv->decisioncnt_orphan = 0;
+}
+
+/*-------------------------------------------------------------------
+ *
+ * watch2onhighest - put watch2 on literal with highest level
+ */
+
+static inline void
+watch2onhighest(Solver *solv, Rule *r)
+{
+ int l, wl = 0;
+ Id d, v, *dp;
+
+ d = r->d < 0 ? -r->d - 1 : r->d;
+ if (!d)
+ return; /* binary rule, both watches are set */
+ dp = solv->pool->whatprovidesdata + d;
+ while ((v = *dp++) != 0)
{
- for (i = 1; i < fq.count; i++)
+ l = solv->decisionmap[v < 0 ? -v : v];
+ if (l < 0)
+ l = -l;
+ if (l > wl)
{
- p = fq.elements[i];
- if (!MAPTST(m, p))
- queue_push(q, p);
+ r->w2 = dp[-1];
+ wl = l;
}
}
- queue_free(&fq);
}
-#endif
/*-------------------------------------------------------------------
- *
- * add (install) rules for solvable
- *
- * s: Solvable for which to add rules
- * m: m[s] = 1 for solvables which have rules, prevent rule duplication
- *
- * Algorithm: 'visit all nodes of a graph'. The graph nodes are
- * solvables, the edges their dependencies.
- * Starting from an installed solvable, this will create all rules
- * representing the graph created by the solvables dependencies.
- *
- * for unfulfilled requirements, conflicts, obsoletes,....
- * add a negative assertion for solvables that are not installable
- *
- * It will also create rules for all solvables referenced by 's'
- * i.e. descend to all providers of requirements of 's'
*
+ * analyze
+ * and learn
*/
-static void
-addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
+static int
+analyze(Solver *solv, int level, Rule *c, Rule **lrp)
{
Pool *pool = solv->pool;
- Repo *installed = solv->installed;
-
- /* 'work' queue. keeps Ids of solvables we still have to work on.
- And buffer for it. */
- Queue workq;
- Id workqbuf[64];
-
- int i;
- /* if to add rules for broken deps ('rpm -V' functionality)
- * 0 = yes, 1 = no
- */
- int dontfix;
-#if CODE10
- int patchatom;
-#endif
- /* Id var and pointer for each dependency
- * (not used in parallel)
- */
- Id req, *reqp;
- Id con, *conp;
- Id obs, *obsp;
- Id rec, *recp;
- Id sug, *sugp;
- /* var and ptr for loops */
- Id p, *pp;
- /* ptr to 'whatprovides' */
- Id *dp;
- /* Id for current solvable 's' */
- Id n;
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
+ Queue q;
+ Rule *r;
+ Id q_buf[8];
+ int rlevel = 1;
+ Map seen; /* global? */
+ Id p = 0, pp, v, vv, why;
+ int l, i, idx;
+ int num = 0, l1num = 0;
+ int learnt_why = solv->learnt_pool.count;
+ Id *decisionmap = solv->decisionmap;
- queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
- queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
+ queue_init_buffer(&q, q_buf, sizeof(q_buf)/sizeof(*q_buf));
- /* loop until there's no more work left */
- while (workq.count)
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
+ map_init(&seen, pool->nsolvables);
+ idx = solv->decisionq.count;
+ for (;;)
{
- /*
- * n: Id of solvable
- * s: Pointer to solvable
- */
-
- n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
- if (MAPTST(m, n)) /* continue if already visited */
- continue;
-
- MAPSET(m, n); /* mark as visited */
- s = pool->solvables + n; /* s = Solvable in question */
-
- dontfix = 0;
- if (installed /* Installed system available */
- && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
- && s->repo == installed) /* solvable is installed? */
- {
- dontfix = 1; /* dont care about broken rpm deps */
- }
-
- if (!dontfix
- && s->arch != ARCH_SRC
- && s->arch != ARCH_NOSRC
- && !pool_installable(pool, s))
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
+ solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
+ queue_push(&solv->learnt_pool, c - solv->rules);
+ FOR_RULELITERALS(v, pp, c)
{
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
- addrule(solv, -n, 0); /* uninstallable */
+ if (DECISIONMAP_TRUE(v)) /* the one true literal */
+ continue;
+ vv = v > 0 ? v : -v;
+ if (MAPTST(&seen, vv))
+ continue;
+ MAPSET(&seen, vv); /* mark that we also need to look at this literal */
+ l = solv->decisionmap[vv];
+ if (l < 0)
+ l = -l;
+ if (l == 1)
+ l1num++; /* need to do this one in level1 pass */
+ else if (l == level)
+ num++; /* need to do this one as well */
+ else
+ {
+ queue_push(&q, v); /* not level1 or conflict level, add to new rule */
+ if (l > rlevel)
+ rlevel = l;
+ }
}
-#if CODE10
- patchatom = 0;
- if (s->freshens && !s->supplements)
+l1retry:
+ if (!num && !--l1num)
+ break; /* all literals done */
+
+ /* find the next literal to investigate */
+ /* (as num + l1num > 0, we know that we'll always find one) */
+ for (;;)
{
- const char *name = id2str(pool, s->name);
- if (name[0] == 'a' && !strncmp(name, "atom:", 5))
- patchatom = 1;
+ assert(idx > 0);
+ v = solv->decisionq.elements[--idx];
+ vv = v > 0 ? v : -v;
+ if (MAPTST(&seen, vv))
+ break;
}
-#endif
-
- /*-----------------------------------------
- * check requires of s
- */
+ MAPCLR(&seen, vv);
- if (s->requires)
+ if (num && --num == 0)
{
- reqp = s->repo->idarraydata + s->requires;
- while ((req = *reqp++) != 0) /* go through all requires */
+ /* done with normal literals, now start level 1 literal processing */
+ p = -v; /* so that v doesn't get lost */
+ if (!l1num)
+ break;
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
+ /* clear non-l1 bits from seen map */
+ for (i = 0; i < q.count; i++)
{
- if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
- continue;
-
- /* find list of solvables providing 'req' */
- dp = pool_whatprovides(pool, req);
+ v = q.elements[i];
+ MAPCLR(&seen, v > 0 ? v : -v);
+ }
+ /* only level 1 marks left in seen map */
+ l1num++; /* as l1retry decrements it */
+ goto l1retry;
+ }
- if (*dp == SYSTEMSOLVABLE) /* always installed */
- continue;
-
-#if CODE10
- if (patchatom)
- {
- addpatchatomrequires(solv, s, dp, &workq, m);
- continue;
- }
-#endif
- if (dontfix)
- {
- /* the strategy here is to not insist on dependencies
- * that are already broken. so if we find one provider
- * that was already installed, we know that the
- * dependency was not broken before so we enforce it */
-
- /* check if any of the providers for 'req' is installed */
- for (i = 0; (p = dp[i]) != 0; i++)
- {
- if (pool->solvables[p].repo == installed)
- break; /* provider was installed */
- }
- /* didn't find an installed provider: previously broken dependency */
- if (!p)
- {
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
- continue;
- }
- }
-
- if (!*dp)
- {
- /* nothing provides req! */
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
- addrule(solv, -n, 0); /* mark requestor as uninstallable */
- continue;
- }
-
- IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
- {
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
- for (i = 0; dp[i]; i++)
- POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvable2str(pool, pool->solvables + dp[i]));
- }
-
- /* add 'requires' dependency */
- /* rule: (-requestor|provider1|provider2|...|providerN) */
- addrule(solv, -n, dp - pool->whatprovidesdata);
-
- /* descend the dependency tree
- push all non-visited providers on the work queue */
- for (; *dp; dp++)
- {
- if (!MAPTST(m, *dp))
- queue_push(&workq, *dp);
- }
-
- } /* while, requirements of n */
-
- } /* if, requirements */
-
- /* that's all we check for src packages */
- if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
- continue;
-
- /*-----------------------------------------
- * check conflicts of s
- */
-
- if (s->conflicts)
- {
- conp = s->repo->idarraydata + s->conflicts;
- /* foreach conflicts of 's' */
- while ((con = *conp++) != 0)
- {
- /* foreach providers of a conflict of 's' */
- FOR_PROVIDES(p, pp, con)
- {
- /* dontfix: dont care about conflicts with already installed packs */
- if (dontfix && pool->solvables[p].repo == installed)
- continue;
- /* p == n: self conflict */
- if (p == n && !solv->allowselfconflicts)
- p = 0; /* make it a negative assertion, aka 'uninstallable' */
- /* rule: -n|-p: either solvable _or_ provider of conflict */
- addrule(solv, -n, -p);
- }
- }
- }
-
- /*-----------------------------------------
- * check obsoletes if not installed
- * (only installation will trigger the obsoletes in rpm)
- */
- if (!installed || pool->solvables[n].repo != installed)
- { /* not installed */
- int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
- if (s->obsoletes && !noobs)
- {
- obsp = s->repo->idarraydata + s->obsoletes;
- /* foreach obsoletes */
- while ((obs = *obsp++) != 0)
- {
- /* foreach provider of an obsoletes of 's' */
- FOR_PROVIDES(p, pp, obs)
- {
- if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
- && !pool_match_nevr(pool, pool->solvables + p, obs))
- continue;
- addrule(solv, -n, -p);
- }
- }
- }
- FOR_PROVIDES(p, pp, s->name)
- {
- Solvable *ps = pool->solvables + p;
- /* we still obsolete packages with same nevra, like rpm does */
- /* (actually, rpm mixes those packages. yuck...) */
- if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
- continue;
- if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
- continue;
- addrule(solv, -n, -p);
- }
- }
+ why = solv->decisionq_why.elements[idx];
+ if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
+ goto l1retry;
+ c = solv->rules + why;
+ }
+ map_free(&seen);
+ assert(p != 0);
+ assert(rlevel > 0 && rlevel < level);
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
+ {
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
+ for (i = 0; i < q.count; i++)
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, q.elements[i]);
+ }
+ /* push end marker on learnt reasons stack */
+ queue_push(&solv->learnt_pool, 0);
+ solv->stats_learned++;
- /*-----------------------------------------
- * add recommends to the work queue
- */
- if (s->recommends)
- {
- recp = s->repo->idarraydata + s->recommends;
- while ((rec = *recp++) != 0)
- {
- FOR_PROVIDES(p, pp, rec)
- if (!MAPTST(m, p))
- queue_push(&workq, p);
- }
- }
- if (s->suggests)
- {
- sugp = s->repo->idarraydata + s->suggests;
- while ((sug = *sugp++) != 0)
- {
- FOR_PROVIDES(p, pp, sug)
- if (!MAPTST(m, p))
- queue_push(&workq, p);
- }
- }
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, rlevel);
+ level = rlevel;
+ revert(solv, level);
+ if (q.count < 2)
+ {
+ Id d = q.count ? q.elements[0] : 0;
+ queue_free(&q);
+ r = solver_addrule(solv, p, d, 0);
+ }
+ else
+ {
+ Id d = pool_queuetowhatprovides(pool, &q);
+ queue_free(&q);
+ r = solver_addrule(solv, p, 0, d);
+ }
+ assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
+ queue_push(&solv->learnt_why, learnt_why);
+ if (r->w2)
+ {
+ /* needs watches */
+ watch2onhighest(solv, r);
+ addwatches_rule(solv, r);
+ }
+ else
+ {
+ /* rule is an assertion */
+ queue_push(&solv->ruleassertions, r - solv->rules);
}
- queue_free(&workq);
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
+ *lrp = r;
+ return level;
}
/*-------------------------------------------------------------------
- *
- * Add package rules for weak rules
*
- * m: visited solvables
+ * solver_reset
+ *
+ * reset all solver decisions
+ * called after rules have been enabled/disabled
*/
-static void
-addrpmrulesforweak(Solver *solv, Map *m)
+void
+solver_reset(Solver *solv)
{
- Pool *pool = solv->pool;
- Solvable *s;
- Id sup, *supp;
- int i, n;
+ int i;
+ Id v;
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
- /* foreach solvable in pool */
- for (i = n = 1; n < pool->nsolvables; i++, n++)
+ /* rewind all decisions */
+ for (i = solv->decisionq.count - 1; i >= 0; i--)
{
- if (i == pool->nsolvables) /* wrap i */
- i = 1;
- if (MAPTST(m, i)) /* been there */
- continue;
-
- s = pool->solvables + i;
- if (!pool_installable(pool, s)) /* only look at installable ones */
- continue;
-
- sup = 0;
- if (s->supplements)
- {
- /* find possible supplements */
- supp = s->repo->idarraydata + s->supplements;
- while ((sup = *supp++) != ID_NULL)
- if (dep_possible(solv, sup, m))
- break;
- }
-
- /* if nothing found, check for freshens
- * (patterns use this)
- */
- if (!sup && s->freshens)
- {
- supp = s->repo->idarraydata + s->freshens;
- while ((sup = *supp++) != ID_NULL)
- if (dep_possible(solv, sup, m))
- break;
- }
-
- /* if nothing found, check for enhances */
- if (!sup && s->enhances)
- {
- supp = s->repo->idarraydata + s->enhances;
- while ((sup = *supp++) != ID_NULL)
- if (dep_possible(solv, sup, m))
- break;
- }
- /* if notthing found, goto next solvables */
- if (!sup)
- continue;
- addrpmrulesforsolvable(solv, s, m);
- n = 0;
+ v = solv->decisionq.elements[i];
+ solv->decisionmap[v > 0 ? v : -v] = 0;
}
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
-}
-
-
-/*-------------------------------------------------------------------
- *
- * add package rules for possible updates
- *
- * s: solvable
- * m: map of already visited solvables
- * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
- */
+ queue_empty(&solv->decisionq_why);
+ queue_empty(&solv->decisionq);
+ solv->recommends_index = -1;
+ solv->propagate_index = 0;
+ solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
+ queue_empty(&solv->branches);
-static void
-addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
-{
- Pool *pool = solv->pool;
- int i;
- /* queue and buffer for it */
- Queue qs;
- Id qsbuf[64];
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
-
- queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
- /* find update candidates for 's' */
- policy_findupdatepackages(solv, s, &qs, allow_all);
- /* add rule for 's' if not already done */
- if (!MAPTST(m, s - pool->solvables))
- addrpmrulesforsolvable(solv, s, m);
- /* foreach update candidate, add rule if not already done */
- for (i = 0; i < qs.count; i++)
- if (!MAPTST(m, qs.elements[i]))
- addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
- queue_free(&qs);
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
+ /* adapt learnt rule status to new set of enabled/disabled rules */
+ enabledisablelearntrules(solv);
}
/*-------------------------------------------------------------------
- *
- * add rule for update
- * (A|A1|A2|A3...) An = update candidates for A
*
- * s = (installed) solvable
+ * analyze_unsolvable_rule
+ *
+ * recursion helper used by analyze_unsolvable
*/
static void
-addupdaterule(Solver *solv, Solvable *s, int allow_all)
+analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
{
- /* installed packages get a special upgrade allowed rule */
Pool *pool = solv->pool;
- Id d;
- Queue qs;
- Id qsbuf[64];
+ int i;
+ Id why = r - solv->rules;
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
+ 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)
+ analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
+ return;
+ }
+ if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, why))
+ if (!*lastweakp || why > *lastweakp)
+ *lastweakp = why;
+ /* do not add pkg rules to problem */
+ if (why < solv->pkgrules_end)
+ return;
+ /* turn rule into problem */
+ if (why >= solv->jobrules && why < solv->jobrules_end)
+ why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
+ /* normalize dup/infarch rules */
+ if (why > solv->infarchrules && why < solv->infarchrules_end)
+ {
+ Id name = pool->solvables[-solv->rules[why].p].name;
+ while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
+ why--;
+ }
+ if (why > solv->duprules && why < solv->duprules_end)
+ {
+ Id name = pool->solvables[-solv->rules[why].p].name;
+ while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
+ why--;
+ }
- queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
- /* find update candidates for 's' */
- policy_findupdatepackages(solv, s, &qs, allow_all);
- if (qs.count == 0) /* no updaters found */
- d = 0; /* assertion (keep installed) */
- else
- d = pool_queuetowhatprovides(pool, &qs); /* intern computed queue */
- queue_free(&qs);
- addrule(solv, s - pool->solvables, d); /* allow update of s */
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
+ /* return if problem already countains our rule */
+ if (solv->problems.count)
+ {
+ for (i = solv->problems.count - 1; i >= 0; i--)
+ if (solv->problems.elements[i] == 0) /* end of last problem reached? */
+ break;
+ else if (solv->problems.elements[i] == why)
+ return;
+ }
+ queue_push(&solv->problems, why);
}
-/********************************************************************/
-/* watches */
-
-
/*-------------------------------------------------------------------
- * makewatches
*
- * initial setup for all watches
+ * analyze_unsolvable (called from setpropagatelearn)
+ *
+ * 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-pkg 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 -1 if disablerules is not set or disable
+ * _all_ of the problem rules and return 0.
+ *
+ * return: 0 - disabled some rules, try again
+ * -1 - hopeless
*/
-static void
-makewatches(Solver *solv)
+static int
+analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
{
+ Pool *pool = solv->pool;
Rule *r;
- int i;
- int nsolvables = solv->pool->nsolvables;
+ Map involved; /* global to speed things up? */
+ Map rseen;
+ Id pp, v, vv, why;
+ int i, idx;
+ Id *decisionmap = solv->decisionmap;
+ int oldproblemcount;
+ int oldlearntpoolcount;
+ Id lastweak;
+ int record_proof = 1;
- 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
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
+ solv->stats_unsolvable++;
+ oldproblemcount = solv->problems.count;
+ oldlearntpoolcount = solv->learnt_pool.count;
+
+ /* make room for proof index */
+ /* must update it later, as analyze_unsolvable_rule would confuse
+ * it with a rule index if we put the real value in already */
+ queue_push(&solv->problems, 0);
+
+ r = cr;
+ map_init(&involved, pool->nsolvables);
+ map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
+ if (record_proof)
+ queue_push(&solv->learnt_pool, r - solv->rules);
+ lastweak = 0;
+ analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
+ FOR_RULELITERALS(v, pp, r)
{
- if (!r->w2) /* assertions do not need watches */
+ if (DECISIONMAP_TRUE(v)) /* the one true literal */
+ continue;
+ vv = v > 0 ? v : -v;
+ MAPSET(&involved, vv);
+ }
+ idx = solv->decisionq.count;
+ while (idx > 0)
+ {
+ v = solv->decisionq.elements[--idx];
+ vv = v > 0 ? v : -v;
+ if (!MAPTST(&involved, vv) || vv == SYSTEMSOLVABLE)
continue;
+ why = solv->decisionq_why.elements[idx];
+ assert(why > 0);
+ if (record_proof)
+ queue_push(&solv->learnt_pool, why);
+ r = solv->rules + why;
+ analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
+ FOR_RULELITERALS(v, pp, r)
+ {
+ if (DECISIONMAP_TRUE(v)) /* the one true literal */
+ continue;
+ vv = v > 0 ? v : -v;
+ MAPSET(&involved, vv);
+ }
+ }
+ map_free(&involved);
+ map_free(&rseen);
+ queue_push(&solv->problems, 0); /* mark end of this problem */
- /* see addwatches_rule(solv, r) */
- r->n1 = solv->watches[nsolvables + r->w1];
- solv->watches[nsolvables + r->w1] = r - solv->rules;
+ if (lastweak)
+ {
+ /* disable last weak rule */
+ solv->problems.count = oldproblemcount;
+ solv->learnt_pool.count = oldlearntpoolcount;
+ if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
+ v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
+ else
+ v = 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);
+ solver_reset(solv);
+ return 0;
+ }
- r->n2 = solv->watches[nsolvables + r->w2];
- solv->watches[nsolvables + r->w2] = r - solv->rules;
+ 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 0;
}
+
+ /* finish proof */
+ if (record_proof)
+ {
+ queue_push(&solv->learnt_pool, 0);
+ solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
+ }
+
+ /* + 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]);
+ /* XXX: might want to enable all weak rules again */
+ solver_reset(solv);
+ return 0;
+ }
+ POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
+ return -1;
}
/*-------------------------------------------------------------------
*
- * add watches (for rule)
- * sets up watches for a single rule
- *
- * see also makewatches()
+ * setpropagatelearn
+ *
+ * add free decision (solvable to install) to decisionq
+ * increase level and propagate decision
+ * return if no conflict.
+ *
+ * in conflict case, analyze conflict rule, add resulting
+ * rule to learnt rule set, make decision from learnt
+ * rule (always unit) and re-propagate.
+ *
+ * returns the new solver level or -1 if unsolvable
+ *
*/
-static inline void
-addwatches_rule(Solver *solv, Rule *r)
+static int
+setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
{
- int nsolvables = solv->pool->nsolvables;
-
- r->n1 = solv->watches[nsolvables + r->w1];
- solv->watches[nsolvables + r->w1] = r - solv->rules;
+ Pool *pool = solv->pool;
+ Rule *r, *lr;
- r->n2 = solv->watches[nsolvables + r->w2];
- solv->watches[nsolvables + r->w2] = r - solv->rules;
+ if (decision)
+ {
+ level++;
+ if (decision > 0)
+ solv->decisionmap[decision] = level;
+ else
+ solv->decisionmap[-decision] = -level;
+ queue_push(&solv->decisionq, decision);
+ queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
+ }
+ assert(ruleid >= 0 && level > 0);
+ for (;;)
+ {
+ r = propagate(solv, level);
+ if (!r)
+ break;
+ if (level == 1)
+ return analyze_unsolvable(solv, r, disablerules);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
+ level = analyze(solv, level, r, &lr);
+ /* the new rule is unit by design */
+ decision = lr->p;
+ solv->decisionmap[decision > 0 ? decision : -decision] = decision > 0 ? level : -level;
+ queue_push(&solv->decisionq, decision);
+ queue_push(&solv->decisionq_why, lr - solv->rules);
+ IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
+ {
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
+ solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, decision);
+ POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
+ solver_printrule(solv, SOLV_DEBUG_ANALYZE, lr);
+ }
+ }
+ return level;
}
+static void
+reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
+{
+ Pool *pool = solv->pool;
+ int i, j, haveone = 0, dqcount = dq->count;
+ int decisionqcount = solv->decisionq.count;
+ Id p;
+ Solvable *s;
-/********************************************************************/
-/*
- * rule propagation
+ /* at the time we process jobrules the installed packages are not kept yet */
+ /* reorder so that "future-supplemented" packages come first */
+ FOR_REPO_SOLVABLES(solv->installed, p, s)
+ {
+ if (MAPTST(&solv->noupdate, p - solv->installed->start))
+ continue;
+ if (solv->decisionmap[p] == 0)
+ {
+ if (s->recommends || s->suggests)
+ queue_push(&solv->decisionq, p);
+ solv->decisionmap[p] = level + 1;
+ haveone = 1;
+ }
+ }
+ if (!haveone)
+ return;
+ policy_update_recommendsmap(solv);
+ for (i = 0; i < dqcount; i++)
+ {
+ p = dq->elements[i];
+ if (!(pool->solvables[p].repo == solv->installed || MAPTST(&solv->suggestsmap, p) || solver_is_enhancing(solv, pool->solvables + p)))
+ {
+ queue_push(dq, p);
+ dq->elements[i] = 0;
+ }
+ }
+ dqcount = dq->count;
+ for (i = 0; i < dqcount; i++)
+ {
+ p = dq->elements[i];
+ if (p && !(pool->solvables[p].repo == solv->installed || MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
+ {
+ queue_push(dq, p);
+ dq->elements[i] = 0;
+ }
+ }
+ for (i = j = 0; i < dq->count; i++)
+ if (dq->elements[i])
+ dq->elements[j++] = dq->elements[i];
+ queue_truncate(dq, j);
+ FOR_REPO_SOLVABLES(solv->installed, p, s)
+ if (solv->decisionmap[p] == level + 1)
+ solv->decisionmap[p] = 0;
+ if (solv->decisionq.count != decisionqcount)
+ {
+ solv->recommends_index = -1;
+ queue_truncate(&solv->decisionq, decisionqcount);
+ }
+}
+
+/*-------------------------------------------------------------------
+ *
+ * branch handling
*/
+static void
+createbranch(Solver *solv, int level, Queue *dq, Id p, Id data)
+{
+ Pool *pool = solv->pool;
+ int i;
+ IF_POOLDEBUG (SOLV_DEBUG_POLICY)
+ {
+ POOL_DEBUG (SOLV_DEBUG_POLICY, "creating a branch:\n");
+ for (i = 0; i < dq->count; i++)
+ POOL_DEBUG (SOLV_DEBUG_POLICY, " - %s\n", pool_solvid2str(pool, dq->elements[i]));
+ }
+ queue_push(&solv->branches, -dq->elements[0]);
+ for (i = 1; i < dq->count; i++)
+ queue_push(&solv->branches, dq->elements[i]);
+ queue_push2(&solv->branches, p, data);
+ queue_push2(&solv->branches, dq->count + 4, level);
+}
-/* shortcuts to check if a literal (positive or negative) assignment
- * evaluates to 'true' or 'false'
- */
-#define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
-#define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
-#define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
+static int
+takebranch(Solver *solv, int pos, int end, const char *msg, int disablerules)
+{
+ Pool *pool = solv->pool;
+ int level;
+ Id p, why;
+#if 0
+ {
+ int i;
+ printf("branch group level %d [%d-%d] %d %d:\n", solv->branches.elements[end - 1], start, end, solv->branches.elements[end - 4], solv->branches.elements[end - 3]);
+ for (i = end - solv->branches.elements[end - 2]; i < end - 4; i++)
+ printf("%c %c%s\n", i == pos ? 'x' : ' ', solv->branches.elements[i] >= 0 ? ' ' : '-', pool_solvid2str(pool, solv->branches.elements[i] >= 0 ? solv->branches.elements[i] : -solv->branches.elements[i]));
+ }
+#endif
+ level = solv->branches.elements[end - 1];
+ p = solv->branches.elements[pos];
+ solv->branches.elements[pos] = -p;
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "%s %d -> %d with %s\n", msg, solv->decisionmap[p], level, pool_solvid2str(pool, p));
+ /* hack: set level to zero so that revert does not remove the branch */
+ solv->branches.elements[end - 1] = 0;
+ revert(solv, level);
+ solv->branches.elements[end - 1] = level;
+ /* hack: revert simply sets the count, so we can still access the reverted elements */
+ why = -solv->decisionq_why.elements[solv->decisionq_why.count];
+ assert(why >= 0);
+ return setpropagatelearn(solv, level, p, disablerules, why);
+}
/*-------------------------------------------------------------------
- *
- * propagate
*
- * 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.
- *
- * return : 0 = everything is OK
- * rule = conflict found in this rule
+ * select and install
+ *
+ * install best package from the queue. We add an extra package, inst, if
+ * provided. See comment in weak install section.
+ *
+ * returns the new solver level or -1 if unsolvable
+ *
*/
-static Rule *
-propagate(Solver *solv, int level)
+static int
+selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
{
Pool *pool = solv->pool;
- Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
- Rule *r; /* rule */
- Id p, pkg, other_watch;
- Id *dp;
- Id *decisionmap = solv->decisionmap;
-
- Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
+ Id p;
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
+ if (dq->count > 1)
+ policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
+ /* if we're resolving job rules and didn't resolve the installed packages yet,
+ * do some special supplements ordering */
+ if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed && !solv->focus_installed)
+ reorder_dq_for_jobrules(solv, level, dq);
+ /* if we have multiple candidates we open a branch */
+ if (dq->count > 1)
+ createbranch(solv, level, dq, 0, ruleid);
+ p = dq->elements[0];
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
+ return setpropagatelearn(solv, level, p, disablerules, ruleid);
+}
- /* foreach non-propagated decision */
- while (solv->propagate_index < solv->decisionq.count)
- {
- /*
- * 'pkg' was just decided
- * negate because our watches trigger if literal goes FALSE
- */
- pkg = -solv->decisionq.elements[solv->propagate_index++];
-
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
- solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
- }
- /* foreach rule where 'pkg' is now FALSE */
- for (rp = watches + pkg; *rp; rp = next_rp)
- {
- r = solv->rules + *rp;
- if (r->d < 0)
- {
- /* rule is disabled, goto next */
- if (pkg == r->w1)
- next_rp = &r->n1;
- else
- next_rp = &r->n2;
- continue;
- }
+/********************************************************************/
+/* Main solver interface */
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- POOL_DEBUG(SAT_DEBUG_PROPAGATE," watch triggered ");
- solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
- }
- /* 'pkg' was just decided (was set to FALSE)
- *
- * now find other literal watch, check clause
- * and advance on linked list
- */
- if (pkg == r->w1)
- {
- other_watch = r->w2;
- next_rp = &r->n1;
- }
- else
- {
- other_watch = r->w1;
- next_rp = &r->n2;
- }
-
- /*
- * This term is already true (through the other literal)
- * so we have nothing to do
- */
- if (DECISIONMAP_TRUE(other_watch))
- continue;
+/*-------------------------------------------------------------------
+ *
+ * solver_create
+ * create solver structure
+ *
+ * pool: all available solvables
+ * installed: installed Solvables
+ *
+ *
+ * Upon solving, rules are created to flag the Solvables
+ * of the 'installed' Repo as installed.
+ */
- /*
- * The other literal is FALSE or UNDEF
- *
- */
-
- if (r->d)
- {
- /* Not a binary clause, try to move our watch.
- *
- * Go over all literals and find one that is
- * not other_watch
- * and not FALSE
- *
- * (TRUE is also ok, in that case the rule is fulfilled)
- */
- if (r->p /* we have a 'p' */
- && r->p != other_watch /* which is not watched */
- && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
- {
- p = r->p;
- }
- else /* go find a 'd' to make 'true' */
- {
- /* foreach p in 'd'
- we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
- */
- for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
- {
- if (p != other_watch /* which is not watched */
- && !DECISIONMAP_FALSE(p)) /* and not FALSE */
- break;
- }
- }
+Solver *
+solver_create(Pool *pool)
+{
+ Solver *solv;
+ solv = (Solver *)solv_calloc(1, sizeof(Solver));
+ solv->pool = pool;
+ solv->installed = pool->installed;
- if (p)
- {
- /*
- * if we found some p that is UNDEF or TRUE, move
- * watch to it
- */
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- if (p > 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables + p));
- else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
- }
-
- *rp = *next_rp;
- next_rp = rp;
-
- if (pkg == r->w1)
- {
- r->w1 = p;
- r->n1 = watches[p];
- }
- else
- {
- r->w2 = p;
- r->n2 = watches[p];
- }
- watches[p] = r - solv->rules;
- continue;
- }
- /* search failed, thus all unwatched literals are FALSE */
-
- } /* not binary */
-
- /*
- * unit clause found, set literal other_watch to TRUE
- */
+ solv->allownamechange = 1;
- if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
- return r; /* eek, a conflict! */
-
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " unit ");
- solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
- }
+ solv->dup_allowdowngrade = 1;
+ solv->dup_allownamechange = 1;
+ solv->dup_allowarchchange = 1;
+ solv->dup_allowvendorchange = 1;
- if (other_watch > 0)
- decisionmap[other_watch] = level; /* install! */
- else
- decisionmap[-other_watch] = -level; /* remove! */
-
- queue_push(&solv->decisionq, other_watch);
- queue_push(&solv->decisionq_why, r - solv->rules);
+ solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
- IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
- {
- Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
- if (other_watch > 0)
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to install %s\n", solvable2str(pool, s));
- else
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, " -> decided to conflict %s\n", solvable2str(pool, s));
- }
-
- } /* foreach rule involving 'pkg' */
-
- } /* while we have non-decided decisions */
-
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
+ queue_init(&solv->ruletojob);
+ queue_init(&solv->decisionq);
+ queue_init(&solv->decisionq_why);
+ queue_init(&solv->problems);
+ queue_init(&solv->orphaned);
+ queue_init(&solv->learnt_why);
+ queue_init(&solv->learnt_pool);
+ queue_init(&solv->branches);
+ queue_init(&solv->weakruleq);
+ queue_init(&solv->ruleassertions);
+ queue_init(&solv->addedmap_deduceq);
- return 0; /* all is well */
-}
+ queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
+ map_init(&solv->recommendsmap, pool->nsolvables);
+ map_init(&solv->suggestsmap, pool->nsolvables);
+ map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
+ solv->recommends_index = 0;
-/********************************************************************/
-/* Analysis */
+ solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
+ solv->nrules = 1;
+ solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
+ memset(solv->rules, 0, sizeof(Rule));
+
+ return solv;
+}
-/*-------------------------------------------------------------------
- *
- * analyze
- * and learn
- */
static int
-analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
+resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
{
Pool *pool = solv->pool;
- Queue r;
- int rlevel = 1;
- Map seen; /* global? */
- Id d, v, vv, *dp, why;
- int l, i, idx;
- int num = 0, l1num = 0;
- int learnt_why = solv->learnt_pool.count;
- Id *decisionmap = solv->decisionmap;
-
- queue_init(&r);
+ int oldlevel = level;
+ int i, olevel;
+ Rule *r;
- POOL_DEBUG(SAT_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
- map_init(&seen, pool->nsolvables);
- idx = solv->decisionq.count;
- for (;;)
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
+ if (!solv->decisioncnt_jobs)
+ solv->decisioncnt_jobs = solv->decisionq.count;
+ for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
{
- IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
- solver_printruleclass(solv, SAT_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;
- /* go through all literals of the rule */
- for (i = -1; ; i++)
+ Id l, pp;
+ if (r->d < 0) /* ignore disabled rules */
+ continue;
+ queue_empty(dq);
+ FOR_RULELITERALS(l, pp, r)
{
- if (i == -1)
- v = c->p;
- else if (d == 0)
- v = i ? 0 : c->w2;
- else
- v = *dp++;
- if (v == 0)
- break;
-
- if (DECISIONMAP_TRUE(v)) /* the one true literal */
- continue;
- vv = v > 0 ? v : -v;
- if (MAPTST(&seen, vv))
- continue;
- l = solv->decisionmap[vv];
if (l < 0)
- l = -l;
- MAPSET(&seen, vv);
- if (l == 1)
- l1num++; /* need to do this one in level1 pass */
- else if (l == level)
- num++; /* need to do this one as well */
+ {
+ if (solv->decisionmap[-l] <= 0)
+ break;
+ }
else
{
- queue_push(&r, v); /* not level1 or conflict level, add to new rule */
- if (l > rlevel)
- rlevel = l;
+ if (solv->decisionmap[l] > 0)
+ break;
+ if (solv->decisionmap[l] == 0)
+ queue_push(dq, l);
}
}
-l1retry:
- if (!num && !--l1num)
- break; /* all level 1 literals done */
- for (;;)
+ if (l || !dq->count)
+ continue;
+ /* prune to installed if not updating */
+ if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
+ !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
{
- assert(idx > 0);
- v = solv->decisionq.elements[--idx];
- vv = v > 0 ? v : -v;
- if (MAPTST(&seen, vv))
- break;
+ int j, k;
+ for (j = k = 0; j < dq->count; j++)
+ {
+ Solvable *s = pool->solvables + dq->elements[j];
+ if (s->repo == solv->installed)
+ {
+ dq->elements[k++] = dq->elements[j];
+ if (solv->updatemap.size && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
+ {
+ k = 0; /* package wants to be updated, do not prune */
+ break;
+ }
+ }
+ }
+ if (k)
+ dq->count = k;
}
- MAPCLR(&seen, vv);
- if (num && --num == 0)
+ olevel = level;
+ level = selectandinstall(solv, level, dq, disablerules, i);
+ if (level <= olevel)
{
- *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);
- for (i = 0; i < r.count; i++)
+ if (level == olevel)
{
- v = r.elements[i];
- MAPCLR(&seen, v > 0 ? v : -v);
+ i--;
+ r--;
+ continue; /* try something else */
}
- /* only level 1 marks left */
- l1num++;
- goto l1retry;
+ if (level < oldlevel)
+ return level;
+ /* redo from start of jobrules */
+ i = solv->jobrules - 1;
+ r = solv->rules + i;
}
- why = solv->decisionq_why.elements[idx];
- if (!why) /* just in case, maye for SYSTEMSOLVABLE */
- goto l1retry;
- c = solv->rules + why;
- }
- map_free(&seen);
-
- if (r.count == 0)
- *dr = 0;
- else if (r.count == 1 && r.elements[0] < 0)
- *dr = r.elements[0];
- else
- *dr = pool_queuetowhatprovides(pool, &r);
- IF_POOLDEBUG (SAT_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);
- for (i = 0; i < r.count; i++)
- solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
}
- /* push end marker on learnt reasons stack */
- queue_push(&solv->learnt_pool, 0);
- if (whyp)
- *whyp = learnt_why;
- solv->stats_learned++;
- return rlevel;
+ return level;
}
-
/*-------------------------------------------------------------------
- *
- * reset_solver
- *
- * reset the solver decisions to right after the rpm rules.
- * called after rules have been enabled/disabled
+ *
+ * solver_free
*/
-static void
-reset_solver(Solver *solv)
+static inline void
+queuep_free(Queue **qp)
{
- Pool *pool = solv->pool;
- int i;
- Id v;
+ if (!*qp)
+ return;
+ queue_free(*qp);
+ *qp = solv_free(*qp);
+}
- /* rewind decisions to direct rpm rule assertions */
- for (i = solv->decisionq.count - 1; i >= solv->directdecisions; i--)
+static inline void
+map_zerosize(Map *m)
+{
+ if (m->size)
{
- v = solv->decisionq.elements[i];
- solv->decisionmap[v > 0 ? v : -v] = 0;
+ map_free(m);
+ map_init(m, 0);
}
+}
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions done reduced from %d to %d\n", solv->decisionq.count, solv->directdecisions);
-
- solv->decisionq_why.count = solv->directdecisions;
- solv->decisionq.count = solv->directdecisions;
- solv->recommends_index = -1;
- solv->propagate_index = 0;
-
- /* adapt learnt rule status to new set of enabled/disabled rules */
- enabledisablelearntrules(solv);
+void
+solver_free(Solver *solv)
+{
+ queue_free(&solv->job);
+ queue_free(&solv->ruletojob);
+ queue_free(&solv->decisionq);
+ queue_free(&solv->decisionq_why);
+ queue_free(&solv->learnt_why);
+ queue_free(&solv->learnt_pool);
+ queue_free(&solv->problems);
+ queue_free(&solv->solutions);
+ queue_free(&solv->orphaned);
+ queue_free(&solv->branches);
+ queue_free(&solv->weakruleq);
+ queue_free(&solv->ruleassertions);
+ queue_free(&solv->addedmap_deduceq);
+ queuep_free(&solv->cleandeps_updatepkgs);
+ queuep_free(&solv->cleandeps_mistakes);
+ queuep_free(&solv->update_targets);
+ queuep_free(&solv->installsuppdepq);
+ queuep_free(&solv->recommendscplxq);
+ queuep_free(&solv->suggestscplxq);
+ queuep_free(&solv->brokenorphanrules);
- /* redo all job/update decisions */
- makeruledecisions(solv);
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
+ map_free(&solv->recommendsmap);
+ map_free(&solv->suggestsmap);
+ map_free(&solv->noupdate);
+ map_free(&solv->weakrulemap);
+ map_free(&solv->multiversion);
+
+ 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);
+
+ solv_free(solv->decisionmap);
+ solv_free(solv->rules);
+ solv_free(solv->watches);
+ solv_free(solv->obsoletes);
+ solv_free(solv->obsoletes_data);
+ solv_free(solv->specialupdaters);
+ solv_free(solv->choicerules_ref);
+ solv_free(solv->bestrules_pkg);
+ solv_free(solv->yumobsrules_info);
+ solv_free(solv->instbuddy);
+ 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;
+ case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
+ return solv->dup_allowdowngrade;
+ case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
+ return solv->dup_allownamechange;
+ case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
+ return solv->dup_allowarchchange;
+ case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
+ return solv->dup_allowvendorchange;
+ case SOLVER_FLAG_KEEP_ORPHANS:
+ return solv->keep_orphans;
+ case SOLVER_FLAG_BREAK_ORPHANS:
+ return solv->break_orphans;
+ case SOLVER_FLAG_FOCUS_INSTALLED:
+ return solv->focus_installed;
+ case SOLVER_FLAG_YUM_OBSOLETES:
+ return solv->do_yum_obsoletes;
+ case SOLVER_FLAG_NEED_UPDATEPROVIDE:
+ return solv->needupdateprovide;
+ default:
+ break;
+ }
+ return -1;
+}
-/*-------------------------------------------------------------------
- *
- * analyze_unsolvable_rule
- */
+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;
+ case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
+ solv->dup_allowdowngrade = value;
+ break;
+ case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
+ solv->dup_allownamechange = value;
+ break;
+ case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
+ solv->dup_allowarchchange = value;
+ break;
+ case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
+ solv->dup_allowvendorchange = value;
+ break;
+ case SOLVER_FLAG_KEEP_ORPHANS:
+ solv->keep_orphans = value;
+ break;
+ case SOLVER_FLAG_BREAK_ORPHANS:
+ solv->break_orphans = value;
+ break;
+ case SOLVER_FLAG_FOCUS_INSTALLED:
+ solv->focus_installed = value;
+ break;
+ case SOLVER_FLAG_YUM_OBSOLETES:
+ solv->do_yum_obsoletes = value;
+ break;
+ case SOLVER_FLAG_NEED_UPDATEPROVIDE:
+ solv->needupdateprovide = value;
+ break;
+ default:
+ break;
+ }
+ return old;
+}
-static void
-analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
+static int
+cleandeps_check_mistakes(Solver *solv)
{
Pool *pool = solv->pool;
+ Rule *r;
+ Id p, pp;
int i;
- Id why = r - solv->rules;
+ int mademistake = 0;
- IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
- solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
- if (solv->learntrules && 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)
- analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp);
- return;
- }
- if (MAPTST(&solv->weakrulemap, why))
- if (!*lastweakp || why > *lastweakp)
- *lastweakp = why;
- /* do not add rpm rules to problem */
- if (why < solv->rpmrules_end)
- return;
- /* turn rule into problem */
- if (why >= solv->jobrules && why < solv->jobrules_end)
- why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
- /* return if problem already countains our rule */
- if (solv->problems.count)
+ if (!solv->cleandepsmap.size)
+ return 0;
+ /* check for mistakes */
+ for (i = solv->installed->start; i < solv->installed->end; i++)
{
- for (i = solv->problems.count - 1; i >= 0; i--)
- if (solv->problems.elements[i] == 0) /* end of last problem reached? */
+ 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;
- else if (solv->problems.elements[i] == why)
- return;
+ 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;
}
- queue_push(&solv->problems, why);
+ 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);
+}
-/*-------------------------------------------------------------------
- *
- * analyze_unsolvable
- *
- * return: 1 - disabled some rules, try again
- * 0 - hopeless
- */
+#ifdef ENABLE_COMPLEX_DEPS
-static int
-analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
+static void
+add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
{
Pool *pool = solv->pool;
- Rule *r;
- Map seen; /* global to speed things up? */
- Id d, v, vv, *dp, why;
- int l, i, idx;
- Id *decisionmap = solv->decisionmap;
- int oldproblemcount;
- int oldlearntpoolcount;
- Id lastweak;
-
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
- solv->stats_unsolvable++;
- oldproblemcount = solv->problems.count;
- oldlearntpoolcount = solv->learnt_pool.count;
-
- /* make room for proof index */
- /* must update it later, as analyze_unsolvable_rule would confuse
- * it with a rule index if we put the real value in already */
- queue_push(&solv->problems, 0);
+ int oldcnt = dq->count;
+ int cutcnt, blkcnt;
+ Id p;
+ int i, j;
- r = cr;
- map_init(&seen, pool->nsolvables);
- queue_push(&solv->learnt_pool, r - solv->rules);
- lastweak = 0;
- analyze_unsolvable_rule(solv, r, &lastweak);
- d = r->d < 0 ? -r->d - 1 : r->d;
- dp = d ? pool->whatprovidesdata + d : 0;
- for (i = -1; ; i++)
- {
- if (i == -1)
- v = r->p;
- else if (d == 0)
- v = i ? 0 : r->w2;
- else
- v = *dp++;
- if (v == 0)
- break;
- if (DECISIONMAP_TRUE(v)) /* the one true literal */
- continue;
- vv = v > 0 ? v : -v;
- l = solv->decisionmap[vv];
- if (l < 0)
- l = -l;
- MAPSET(&seen, vv);
- }
- idx = solv->decisionq.count;
- while (idx > 0)
+#if 0
+ printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
+#endif
+ i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
+ return;
+ cutcnt = dq->count;
+ for (i = oldcnt; i < cutcnt; i++)
{
- v = solv->decisionq.elements[--idx];
- vv = v > 0 ? v : -v;
- if (!MAPTST(&seen, vv))
- continue;
- why = solv->decisionq_why.elements[idx];
- queue_push(&solv->learnt_pool, why);
- r = solv->rules + why;
- analyze_unsolvable_rule(solv, r, &lastweak);
- d = r->d < 0 ? -r->d - 1 : r->d;
- dp = d ? pool->whatprovidesdata + d : 0;
- for (i = -1; ; i++)
+ blkcnt = dq->count;
+ for (; (p = dq->elements[i]) != 0; i++)
{
- if (i == -1)
- v = r->p;
- else if (d == 0)
- v = i ? 0 : r->w2;
- else
- v = *dp++;
- if (v == 0)
- break;
- if (DECISIONMAP_TRUE(v)) /* the one true literal */
+ if (p < 0)
+ {
+ if (solv->decisionmap[-p] <= 0)
+ break;
continue;
- vv = v > 0 ? v : -v;
- l = solv->decisionmap[vv];
- if (l < 0)
- l = -l;
- MAPSET(&seen, vv);
+ }
+ if (solv->decisionmap[p] > 0)
+ {
+ queue_truncate(dq, blkcnt);
+ break;
+ }
+ if (dqmap)
+ {
+ if (!MAPTST(dqmap, p))
+ continue;
+ }
+ else
+ {
+ if (solv->decisionmap[p] < 0)
+ continue;
+ if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
+ continue;
+ }
+ queue_push(dq, p);
}
+ while (dq->elements[i])
+ i++;
}
- map_free(&seen);
- queue_push(&solv->problems, 0); /* mark end of this problem */
-
- if (lastweak)
- {
- /* disable last weak rule */
- solv->problems.count = oldproblemcount;
- solv->learnt_pool.count = oldlearntpoolcount;
- r = solv->rules + lastweak;
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
- solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
- disablerule(solv, r);
- reset_solver(solv);
- return 1;
- }
-
- /* finish proof */
- queue_push(&solv->learnt_pool, 0);
- solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
-
- if (disablerules)
+ queue_deleten(dq, oldcnt, cutcnt - oldcnt);
+ /* unify */
+ if (dq->count != oldcnt)
{
- for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
- disableproblem(solv, solv->problems.elements[i]);
- /* XXX: might want to enable all weak rules again */
- reset_solver(solv);
- return 1;
+ for (j = oldcnt; j < dq->count; j++)
+ {
+ p = dq->elements[j];
+ for (i = 0; i < j; i++)
+ if (dq->elements[i] == p)
+ {
+ dq->elements[j] = 0;
+ break;
+ }
+ }
+ for (i = j = oldcnt; j < dq->count; j++)
+ if (dq->elements[j])
+ dq->elements[i++] = dq->elements[j];
+ queue_truncate(dq, i);
}
- POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
- return 0;
+#if 0
+ printf("RETURN:\n");
+ for (i = oldcnt; i < dq->count; i++)
+ printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
+#endif
}
-
-/********************************************************************/
-/* Decision revert */
-
-/*-------------------------------------------------------------------
- *
- * revert
- * revert decision at level
- */
-
static void
-revert(Solver *solv, int level)
+do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
{
Pool *pool = solv->pool;
- Id v, vv;
- while (solv->decisionq.count)
+ Queue dq;
+ Id p;
+ int i, blk;
+
+#if 0
+ printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
+#endif
+ queue_init(&dq);
+ i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
{
- v = solv->decisionq.elements[solv->decisionq.count - 1];
- 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--;
- solv->decisionmap[vv] = 0;
- solv->decisionq.count--;
- solv->decisionq_why.count--;
- solv->propagate_index = solv->decisionq.count;
+ queue_free(&dq);
+ return;
}
- while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
+ for (i = 0; i < dq.count; i++)
{
- solv->branches.count--;
- while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
- solv->branches.count--;
- }
- solv->recommends_index = -1;
-}
-
-
-/*-------------------------------------------------------------------
- *
- * watch2onhighest - put watch2 on literal with highest level
- */
-
-static inline void
-watch2onhighest(Solver *solv, Rule *r)
-{
- int l, wl = 0;
- Id d, v, *dp;
-
- d = r->d < 0 ? -r->d - 1 : r->d;
- if (!d)
- return; /* binary rule, both watches are set */
- dp = solv->pool->whatprovidesdata + d;
- while ((v = *dp++) != 0)
- {
- l = solv->decisionmap[v < 0 ? -v : v];
- if (l < 0)
- l = -l;
- if (l > wl)
- {
- r->w2 = dp[-1];
- wl = l;
- }
- }
-}
-
-
-/*-------------------------------------------------------------------
- *
- * setpropagatelearn
- *
- * add free decision (solvable to install) to decisionq
- * increase level and propagate decision
- * return if no conflict.
- *
- * in conflict case, analyze conflict rule, add resulting
- * rule to learnt rule set, make decision from learnt
- * rule (always unit) and re-propagate.
- *
- * returns the new solver level or 0 if unsolvable
- *
- */
-
-static int
-setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
-{
- Pool *pool = solv->pool;
- Rule *r;
- Id p = 0, d = 0;
- int l, why;
-
- if (decision)
- {
- level++;
- if (decision > 0)
- solv->decisionmap[decision] = level;
- else
- solv->decisionmap[-decision] = -level;
- queue_push(&solv->decisionq, decision);
- queue_push(&solv->decisionq_why, 0);
- }
- for (;;)
- {
- r = propagate(solv, level);
- if (!r)
- break;
- if (level == 1)
- return analyze_unsolvable(solv, r, disablerules);
- POOL_DEBUG(SAT_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);
- level = l;
- revert(solv, level);
- r = addrule(solv, p, d); /* p requires d */
- assert(r);
- assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
- queue_push(&solv->learnt_why, why);
- if (d)
- {
- /* at least 2 literals, needs watches */
- watch2onhighest(solv, r);
- addwatches_rule(solv, r);
- }
- else
+ blk = i;
+ for (; (p = dq.elements[i]) != 0; i++)
{
- /* learnt rule is an assertion */
- queue_push(&solv->ruleassertions, r - solv->rules);
- }
- 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)
- {
- 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);
+ if (p < 0)
+ {
+ if (solv->decisionmap[-p] <= 0)
+ break;
+ continue;
+ }
+ if (solv->decisionmap[p] > 0)
+ {
+ if (noselected)
+ break;
+ MAPSET(m, p);
+ for (i++; (p = dq.elements[i]) != 0; i++)
+ if (p > 0 && solv->decisionmap[p] > 0)
+ MAPSET(m, p);
+ p = 1;
+ break;
+ }
}
- }
- return level;
-}
-
-
-/*-------------------------------------------------------------------
- *
- * select and install
- *
- * install best package from the queue. We add an extra package, inst, if
- * provided. See comment in weak install section.
- *
- * returns the new solver level or 0 if unsolvable
- *
- */
-
-static int
-selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
-{
- Pool *pool = solv->pool;
- Id p;
- int i;
-
- if (dq->count > 1 || inst)
- policy_filter_unwanted(solv, dq, inst, POLICY_MODE_CHOOSE);
-
- i = 0;
- if (dq->count > 1)
- {
- /* choose the supplemented one */
- for (i = 0; i < dq->count; i++)
- if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
- break;
- if (i == dq->count)
+ if (!p)
{
- for (i = 1; i < dq->count; i++)
- queue_push(&solv->branches, dq->elements[i]);
- queue_push(&solv->branches, -level);
- i = 0;
+ for (i = blk; (p = dq.elements[i]) != 0; i++)
+ if (p > 0)
+ MAPSET(m, p);
}
+ while (dq.elements[i])
+ i++;
}
- p = dq->elements[i];
-
- POOL_DEBUG(SAT_DEBUG_POLICY, "installing %s\n", solvable2str(pool, pool->solvables + p));
-
- return setpropagatelearn(solv, level, p, disablerules);
+ queue_free(&dq);
}
-
-/********************************************************************/
-/* Main solver interface */
-
+#endif
/*-------------------------------------------------------------------
- *
- * solver_create
- * create solver structure
- *
- * pool: all available solvables
- * installed: installed Solvables
*
- *
- * Upon solving, rules are created to flag the Solvables
- * of the 'installed' Repo as installed.
- */
-
-Solver *
-solver_create(Pool *pool, Repo *installed)
-{
- Solver *solv;
- solv = (Solver *)sat_calloc(1, sizeof(Solver));
- solv->pool = pool;
- solv->installed = installed;
-
- 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->learnt_why);
- queue_init(&solv->learnt_pool);
- queue_init(&solv->branches);
- queue_init(&solv->covenantq);
- queue_init(&solv->weakruleq);
- queue_init(&solv->ruleassertions);
-
- map_init(&solv->recommendsmap, pool->nsolvables);
- map_init(&solv->suggestsmap, pool->nsolvables);
- map_init(&solv->noupdate, installed ? installed->end - installed->start : 0);
- solv->recommends_index = 0;
-
- solv->decisionmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
- solv->nrules = 1;
- solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
- memset(solv->rules, 0, sizeof(Rule));
-
- return solv;
-}
-
-
-/*-------------------------------------------------------------------
- *
- * solver_free
- */
-
-void
-solver_free(Solver *solv)
-{
- queue_free(&solv->ruletojob);
- queue_free(&solv->decisionq);
- queue_free(&solv->decisionq_why);
- queue_free(&solv->learnt_why);
- queue_free(&solv->learnt_pool);
- queue_free(&solv->problems);
- queue_free(&solv->suggestions);
- queue_free(&solv->recommendations);
- queue_free(&solv->branches);
- queue_free(&solv->covenantq);
- queue_free(&solv->weakruleq);
- queue_free(&solv->ruleassertions);
-
- map_free(&solv->recommendsmap);
- map_free(&solv->suggestsmap);
- map_free(&solv->noupdate);
- map_free(&solv->weakrulemap);
- map_free(&solv->noobsoletes);
-
- sat_free(solv->decisionmap);
- sat_free(solv->rules);
- sat_free(solv->watches);
- sat_free(solv->obsoletes);
- sat_free(solv->obsoletes_data);
- sat_free(solv);
-}
-
-
-/*-------------------------------------------------------------------
- *
- * run_solver
+ * solver_run_sat
*
* all rules have been set up, now actually run the solver
*
*/
-static void
-run_solver(Solver *solv, int disablerules, int doweak)
+void
+solver_run_sat(Solver *solv, int disablerules, int doweak)
{
Queue dq; /* local decisionqueue */
Queue dqs; /* local decisionqueue for supplements */
int i, j, n;
Solvable *s;
Pool *pool = solv->pool;
- Id p, *dp;
+ Id p, pp, *dp, postponed;
+ 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_STATS, "initial decisions: %d\n", solv->decisionq.count);
-
- IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
- solver_printdecisions(solv);
-
/* start SAT algorithm */
- level = 1;
+ level = 0;
systemlevel = level + 1;
- POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
queue_init(&dq);
queue_init(&dqs);
/*
* here's the main loop:
- * 1) propagate new decisions (only needed for level 1)
- * 2) try to keep installed packages
- * 3) fulfill all unresolved rules
- * 4) install recommended packages
- * 5) minimalize solution if we had choices
+ * 1) decide assertion rules and propagate
+ * 2) fulfill jobs
+ * 3) try to keep installed packages
+ * 4) fulfill all unresolved rules
+ * 5) install recommended packages
+ * 6) minimalize solution if we had choices
* if we encounter a problem, we rewind to a safe level and restart
* with step 1
*/
-
+
+ minimizationsteps = 0;
for (;;)
{
/*
- * propagate
+ * initial propagation of the assertions
*/
-
- if (level == 1)
+ if (level <= 0)
{
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
+ if (level < 0)
+ break;
+ makeruledecisions(solv);
+ level = 1;
+ if (!disablerules && solv->problems.count)
+ {
+ level = -1;
+ break;
+ }
+ POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "initial propagate (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);
- return;
+ level = analyze_unsolvable(solv, r, disablerules);
+ continue;
}
+ systemlevel = level + 1;
}
/*
- * installed packages
+ * resolve jobs first (unless focus_installed is set)
*/
+ if (level < systemlevel && !solv->focus_installed)
+ {
+ olevel = level;
+ level = resolve_jobrules(solv, level, disablerules, &dq);
+ if (level < olevel)
+ continue;
+ systemlevel = level + 1;
+ }
- if (level < systemlevel && solv->installed && solv->installed->nsolvables)
+
+ /*
+ * installed packages
+ */
+ if (!solv->decisioncnt_update)
+ solv->decisioncnt_update = solv->decisionq.count;
+ if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
{
- if (!solv->updatesystem)
+ Repo *installed = solv->installed;
+ int pass;
+
+ 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++)
{
- /*
- * Normal run (non-updating)
- * Keep as many packages installed as possible
- */
- POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
-
- for (i = solv->installed->start; i < solv->installed->end; i++)
+ int passlevel = level;
+ Id *specialupdaters = solv->specialupdaters;
+ if (pass == 1 && !solv->decisioncnt_keep)
+ solv->decisioncnt_keep = solv->decisionq.count;
+ /* start with installedpos, the position that gave us problems the last time */
+ for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
{
+ Rule *rr;
+ Id d;
+
+ if (i == installed->end)
+ i = installed->start;
s = pool->solvables + i;
-
- /* skip if not installed */
- if (s->repo != solv->installed)
+ if (s->repo != installed)
continue;
-
- /* skip if already decided */
- if (solv->decisionmap[i] != 0)
- continue;
-
- POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
-
- olevel = level;
- level = setpropagatelearn(solv, level, i, disablerules);
- if (level == 0) /* unsolvable */
+ if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
+ continue; /* already decided */
+ if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
+ continue; /* updates first */
+ r = solv->rules + solv->updaterules + (i - installed->start);
+ rr = r;
+ if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
+ rr -= solv->installed->end - solv->installed->start;
+ if (!rr->p) /* identical to update rule? */
+ rr = r;
+ if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
+ continue; /* orpaned package */
+
+ /* check if we should update this package to the latest version
+ * noupdate is set for erase jobs, in that case we want to deinstall
+ * the installed package and not replace it with a newer version
+ * rr->p != i is for dup jobs where the installed package cannot be kept */
+ queue_empty(&dq);
+ if (!MAPTST(&solv->noupdate, i - installed->start) && (solv->decisionmap[i] < 0 || solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || (rr->p && rr->p != i)))
{
- queue_free(&dq);
- return;
+ if (!rr->p)
+ {
+ /* specialupdater with no update/feature rule */
+ for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
+ {
+ if (solv->decisionmap[p] > 0)
+ {
+ dq.count = 0;
+ break;
+ }
+ if (!solv->decisionmap[p])
+ queue_push(&dq, p);
+ }
+ }
+ else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
+ {
+ /* special multiversion handling, make sure best version is chosen */
+ if (rr->p == i && solv->decisionmap[i] >= 0)
+ queue_push(&dq, i);
+ while ((p = pool->whatprovidesdata[d++]) != 0)
+ if (solv->decisionmap[p] >= 0)
+ queue_push(&dq, p);
+ 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)
+ {
+ 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
+ {
+ /* update to best package of the update rule */
+ FOR_RULELITERALS(p, pp, rr)
+ {
+ if (solv->decisionmap[p] > 0)
+ {
+ dq.count = 0; /* already fulfilled */
+ break;
+ }
+ if (!solv->decisionmap[p])
+ queue_push(&dq, p);
+ }
+ }
+ }
+ 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;
+ level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
+ if (level <= olevel)
+ {
+ if (level < passlevel)
+ break; /* trouble */
+ if (level < olevel)
+ n = installed->start; /* redo all */
+ i--;
+ n--;
+ continue;
+ }
+ }
+ /* if still undecided keep package */
+ if (solv->decisionmap[i] == 0)
+ {
+ olevel = level;
+ if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
+ {
+#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(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
+ level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
+ }
+ if (level <= olevel)
+ {
+ if (level < passlevel)
+ break; /* trouble */
+ if (level < olevel)
+ n = installed->start; /* redo all */
+ i--;
+ n--;
+ continue; /* retry with learnt rule */
+ }
}
- if (level <= olevel)
- break;
}
- if (i < solv->installed->end)
- continue;
- }
-
- POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
-
- for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
- {
- Rule *rr;
- Id d;
- s = pool->solvables + i;
-
- /* skip if not installed (can't update) */
- if (s->repo != solv->installed)
- continue;
- /* skip if already decided */
- if (solv->decisionmap[i] > 0)
- continue;
-
- /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
- if (MAPTST(&solv->noupdate, i - solv->installed->start))
- continue;
-
- queue_empty(&dq);
- rr = r;
- if (rr->d < 0) /* disabled -> look at feature rule ? */
- rr -= solv->installed->end - solv->installed->start;
- if (!rr->p) /* identical to update rule? */
- rr = r;
- d = (rr->d < 0) ? -rr->d - 1 : rr->d;
- if (d == 0)
+ if (n < installed->end)
{
- if (!rr->w2 || solv->decisionmap[rr->w2] > 0)
- continue;
- /* decide w2 if yet undecided */
- if (solv->decisionmap[rr->w2] == 0)
- queue_push(&dq, rr->w2);
+ installedpos = i; /* retry problem solvable next time */
+ break; /* ran into trouble */
}
- else
- {
- dp = pool->whatprovidesdata + d;
- while ((p = *dp++) != 0)
- {
- if (solv->decisionmap[p] > 0)
- break;
- /* decide p if yet undecided */
- if (solv->decisionmap[p] == 0)
- queue_push(&dq, p);
- }
- if (p)
- continue;
- }
- if (!dq.count && solv->decisionmap[i] != 0)
- continue;
- olevel = level;
- /* FIXME: it is handled a bit different because we do not want
- * to have it pruned just because it is not recommened.
- * we should not prune installed packages instead
- */
- level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
- if (level == 0)
- {
- queue_free(&dq);
- return;
- }
- if (level <= olevel)
- break;
+ installedpos = installed->start; /* reset installedpos */
}
- if (i < solv->installed->end)
+ systemlevel = level + 1;
+ if (pass < 2)
+ continue; /* had trouble, retry */
+ }
+ if (!solv->decisioncnt_keep)
+ solv->decisioncnt_keep = solv->decisionq.count;
+
+ if (level < systemlevel && solv->focus_installed)
+ {
+ olevel = level;
+ level = resolve_jobrules(solv, level, disablerules, &dq);
+ if (level < olevel)
continue;
- systemlevel = level;
+ systemlevel = level + 1;
}
+ if (level < systemlevel)
+ systemlevel = level;
+
/*
* decide
*/
-
- POOL_DEBUG(SAT_DEBUG_STATS, "deciding unresolved rules\n");
+ if (!solv->decisioncnt_resolve)
+ solv->decisioncnt_resolve = solv->decisionq.count;
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
+ postponed = 0;
for (i = 1, n = 1; ; i++, n++)
{
- if (n == solv->nrules)
- break;
+ if (n >= solv->nrules)
+ {
+ if (postponed <= 0)
+ break;
+ i = postponed;
+ postponed = -1;
+ n = 1;
+ }
if (i == solv->nrules)
i = 1;
r = solv->rules + i;
if (r->d < 0) /* ignore disabled rules */
continue;
- queue_empty(&dq);
+ if (r->p < 0) /* most common cases first */
+ {
+ if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
+ continue;
+ }
+ if (dq.count)
+ queue_empty(&dq);
if (r->d == 0)
{
/* binary or unary rule */
- /* need two positive undecided literals */
- if (r->p < 0 || r->w2 <= 0)
+ /* need two positive undecided literals, r->p already checked above */
+ if (r->w2 <= 0)
continue;
if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
continue;
* no positive literal is installed
* i.e. the rule is not fulfilled and we
* just need to decide on the positive literals
+ * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
*/
- if (r->p < 0)
- {
- if (solv->decisionmap[-r->p] <= 0)
- continue;
- }
- else
+ if (r->p >= 0)
{
if (solv->decisionmap[r->p] > 0)
continue;
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);
- olevel = level;
- level = selectandinstall(solv, level, &dq, 0, disablerules);
- if (level == 0)
+ /* prune to cleandeps packages */
+ if (solv->cleandepsmap.size && solv->installed)
{
- queue_free(&dq);
- return;
+ 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);
+ }
}
+
+ if (dq.count > 1 && postponed >= 0)
+ {
+ policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE_NOREORDER);
+ if (dq.count > 1)
+ {
+ if (!postponed)
+ postponed = i;
+ continue;
+ }
+ }
+
+ olevel = level;
+ level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
if (level < systemlevel)
- break;
+ break; /* trouble */
+ /* something changed, so look at all rules again */
n = 0;
- } /* for(), decide */
+ }
- if (n != solv->nrules) /* continue if level < systemlevel */
- continue;
+ if (n < solv->nrules) /* ran into trouble? */
+ continue; /* start over */
+
+ /* 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;
+ }
+ /* at this point we have a consistent system. now do the extras... */
+
+ if (!solv->decisioncnt_weak)
+ solv->decisioncnt_weak = solv->decisionq.count;
if (doweak)
{
int qcount;
- POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
- queue_empty(&dq);
- queue_empty(&dqs);
+ 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++)
{
if (solv->decisionmap[i] < 0)
if (solv->decisionmap[i] > 0)
{
/* installed, check for recommends */
- Id *recp, rec, *pp, p;
+ 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)
recp = s->repo->idarraydata + s->recommends;
while ((rec = *recp++) != 0)
{
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, rec))
+ {
+ add_complex_recommends(solv, rec, &dq, 0);
+ continue;
+ }
+#endif
qcount = dq.count;
FOR_PROVIDES(p, pp, rec)
{
}
else if (solv->decisionmap[p] == 0)
{
+ if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
+ continue;
queue_pushunique(&dq, p);
}
}
else
{
s = pool->solvables + i;
- if (!s->supplements && !s->freshens)
+ if (!s->supplements)
continue;
if (!pool_installable(pool, s))
continue;
if (!solver_is_supplementing(solv, s))
continue;
- if (solv->ignorealreadyrecommended && solv->installed)
- queue_pushunique(&dqs, i); /* needs filter */
- else
- queue_pushunique(&dq, i);
+ if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
+ continue;
+ queue_push(&dqs, i);
}
}
- if (solv->ignorealreadyrecommended && dqs.count)
+
+ /* filter out all packages obsoleted by installed packages */
+ /* this is no longer needed if we have reverse obsoletes */
+ if ((dqs.count || dq.count) && solv->installed)
{
- /* turn off all new packages */
- for (i = 0; i < solv->decisionq.count; i++)
+ Map obsmap;
+ Id obs, *obsp, po, ppo;
+
+ map_init(&obsmap, pool->nsolvables);
+ for (p = solv->installed->start; p < solv->installed->end; p++)
{
- p = solv->decisionq.elements[i];
- if (p < 0)
- continue;
s = pool->solvables + p;
- if (s->repo && s->repo != solv->installed)
- solv->decisionmap[p] = -solv->decisionmap[p];
+ if (s->repo != solv->installed || !s->obsoletes)
+ continue;
+ if (solv->decisionmap[p] <= 0)
+ continue;
+ if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
+ continue;
+ obsp = s->repo->idarraydata + s->obsoletes;
+ /* foreach obsoletes */
+ while ((obs = *obsp++) != 0)
+ FOR_PROVIDES(po, ppo, obs)
+ MAPSET(&obsmap, po);
}
+ for (i = j = 0; i < dqs.count; i++)
+ if (!MAPTST(&obsmap, dqs.elements[i]))
+ dqs.elements[j++] = dqs.elements[i];
+ dqs.count = j;
+ for (i = j = 0; i < dq.count; i++)
+ if (!MAPTST(&obsmap, dq.elements[i]))
+ dq.elements[j++] = dq.elements[i];
+ dq.count = j;
+ map_free(&obsmap);
+ }
+
+ /* filter out all already supplemented packages if requested */
+ if (!solv->addalreadyrecommended && dqs.count)
+ {
/* filter out old supplements */
- for (i = 0; i < dqs.count; i++)
+ for (i = j = 0; i < dqs.count; i++)
{
p = dqs.elements[i];
s = pool->solvables + p;
- if (!s->supplements && !s->freshens)
+ if (s->supplements && solver_is_supplementing_alreadyinstalled(solv, s))
+ dqs.elements[j++] = p;
+ }
+ dqs.count = j;
+ }
+
+ /* multiversion doesn't mix well with supplements.
+ * filter supplemented packages where we already decided
+ * to install a different version (see bnc#501088) */
+ if (dqs.count && solv->multiversion.size)
+ {
+ for (i = j = 0; i < dqs.count; i++)
+ {
+ p = dqs.elements[i];
+ if (MAPTST(&solv->multiversion, p))
+ {
+ Id p2, pp2;
+ s = pool->solvables + p;
+ FOR_PROVIDES(p2, pp2, s->name)
+ if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
+ break;
+ if (p2)
+ continue; /* ignore this package */
+ }
+ dqs.elements[j++] = p;
+ }
+ dqs.count = j;
+ }
+
+ /* make dq contain both recommended and supplemented pkgs */
+ if (dqs.count)
+ {
+ for (i = 0; i < dqs.count; i++)
+ queue_pushunique(&dq, dqs.elements[i]);
+ }
+
+ if (dq.count)
+ {
+ Map dqmap;
+ int decisioncount = solv->decisionq.count;
+
+ if (dq.count == 1)
+ {
+ /* simple case, just one package. no need to choose to best version */
+ p = dq.elements[0];
+ if (dqs.count)
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
+ else
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
+ level = setpropagatelearn(solv, level, p, 0, 0);
+ continue; /* back to main loop */
+ }
+
+ /* filter packages, this gives us the best versions */
+ policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
+
+ /* create map of result */
+ map_init(&dqmap, pool->nsolvables);
+ for (i = 0; i < dq.count; i++)
+ MAPSET(&dqmap, dq.elements[i]);
+
+ /* install all supplemented packages */
+ for (i = 0; i < dqs.count; i++)
+ {
+ p = dqs.elements[i];
+ if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
continue;
- if (!solver_is_supplementing(solv, s))
- queue_pushunique(&dq, 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)
+ break;
}
- /* undo turning off */
- for (i = 0; i < solv->decisionq.count; i++)
+ if (i < dqs.count || solv->decisionq.count < decisioncount)
{
+ map_free(&dqmap);
+ continue;
+ }
+
+ /* install all recommended packages */
+ /* more work as we want to created branches if multiple
+ * choices are valid */
+ for (i = 0; i < decisioncount; i++)
+ {
+ Id rec, *recp, pp;
p = solv->decisionq.elements[i];
if (p < 0)
continue;
s = pool->solvables + p;
- if (s->repo && s->repo != solv->installed)
- solv->decisionmap[p] = -solv->decisionmap[p];
+ if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
+ continue;
+ if (!s->recommends)
+ continue;
+ recp = s->repo->idarraydata + s->recommends;
+ while ((rec = *recp++) != 0)
+ {
+ queue_empty(&dq);
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, rec))
+ add_complex_recommends(solv, rec, &dq, &dqmap);
+ else
+#endif
+ FOR_PROVIDES(p, pp, rec)
+ {
+ if (solv->decisionmap[p] > 0)
+ {
+ dq.count = 0;
+ break;
+ }
+ else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
+ queue_push(&dq, p);
+ }
+ if (!dq.count)
+ continue;
+ if (dq.count > 1)
+ policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
+ /* if we have multiple candidates we open a branch */
+ if (dq.count > 1)
+ createbranch(solv, level, &dq, s - pool->solvables, rec);
+ p = dq.elements[0];
+ 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; /* we had to revert some decisions */
+ }
+ if (rec)
+ break; /* had a problem above, quit loop */
}
+ map_free(&dqmap);
+ continue; /* back to main loop so that all deps are checked */
}
- if (dq.count)
+ }
+
+ if (!solv->decisioncnt_orphan)
+ 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(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
+ for (i = 0; i < solv->orphaned.count; i++)
{
- if (dq.count > 1)
- policy_filter_unwanted(solv, &dq, 0, POLICY_MODE_RECOMMEND);
- p = dq.elements[0];
- POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended %s\n", solvable2str(pool, pool->solvables + p));
- queue_push(&solv->recommendations, p);
- level = setpropagatelearn(solv, level, p, 0);
- continue;
+ p = solv->orphaned.elements[i];
+ if (solv->decisionmap[p])
+ continue; /* already decided */
+ if (solv->droporphanedmap_all)
+ continue;
+ if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
+ continue;
+ 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 */
+ for (i = 0; i < solv->orphaned.count; i++)
+ {
+ p = solv->orphaned.elements[i];
+ if (solv->decisionmap[p])
+ continue; /* already decided */
+ 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 (solv->brokenorphanrules)
+ {
+ solver_check_brokenorphanrules(solv, &dq);
+ if (dq.count)
+ {
+ policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
+ for (i = 0; i < dq.count; i++)
+ {
+ p = dq.elements[i];
+ POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
+ olevel = level;
+ level = setpropagatelearn(solv, level, p, 0, 0);
+ if (level < olevel)
+ break;
+ }
+ continue;
+ }
+ }
+ }
+
+ /* one final pass to make sure we decided all installed packages */
+ if (solv->installed)
+ {
+ for (p = solv->installed->start; p < solv->installed->end; p++)
+ {
+ if (solv->decisionmap[p])
+ continue; /* already decided */
+ s = pool->solvables + p;
+ if (s->repo != solv->installed)
+ continue;
+ POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %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; /* back to main loop */
}
- if (solv->solution_callback)
+ if (solv->installed && solv->cleandepsmap.size && cleandeps_check_mistakes(solv))
+ {
+ solver_reset(solv);
+ level = 0; /* restart from scratch */
+ continue;
+ }
+
+ if (solv->solution_callback)
{
solv->solution_callback(solv, solv->solution_callback_data);
if (solv->branches.count)
{
- int i = solv->branches.count - 1;
- int l = -solv->branches.elements[i];
- for (; i > 0; i--)
- if (solv->branches.elements[i - 1] < 0)
- break;
- p = solv->branches.elements[i];
- POOL_DEBUG(SAT_DEBUG_STATS, "branching with %s\n", solvable2str(pool, pool->solvables + p));
- queue_empty(&dq);
- for (j = i + 1; j < solv->branches.count; j++)
- queue_push(&dq, solv->branches.elements[j]);
- solv->branches.count = i;
- level = l;
- revert(solv, level);
- if (dq.count > 1)
- for (j = 0; j < dq.count; j++)
- queue_push(&solv->branches, dq.elements[j]);
- olevel = level;
- level = setpropagatelearn(solv, level, p, disablerules);
- if (level == 0)
+ int l, endi = 0;
+ p = l = 0;
+ for (i = solv->branches.count - 1; i >= 0; i--)
{
- queue_free(&dq);
- return;
+ p = solv->branches.elements[i];
+ if (p > 0 && !l)
+ {
+ endi = i + 1;
+ l = p;
+ i -= 3; /* skip: p data count */
+ }
+ else if (p > 0)
+ break;
+ else if (p < 0)
+ l = 0;
+ }
+ if (i >= 0)
+ {
+ while (i > 0 && solv->branches.elements[i - 1] > 0)
+ i--;
+ level = takebranch(solv, i, endi, "branching", disablerules);
+ continue;
}
- continue;
}
/* all branches done, we're finally finished */
break;
}
- /* minimization step */
- if (solv->branches.count)
+ /* auto-minimization step */
+ if (solv->branches.count)
{
- int l = 0, lasti = -1, lastl = -1;
- p = 0;
- for (i = solv->branches.count - 1; i >= 0; i--)
+ int endi, lasti = -1, lastiend = -1;
+ if (solv->recommends_index < solv->decisionq.count)
+ policy_update_recommendsmap(solv);
+ for (endi = solv->branches.count; endi > 0;)
{
- p = solv->branches.elements[i];
- if (p < 0)
- l = -p;
- else if (p > 0 && solv->decisionmap[p] > l + 1)
+ int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
+ l = solv->branches.elements[endi - 1];
+ for (i = starti; i < endi - 4; i++)
+ {
+ p = solv->branches.elements[i];
+ if (p <= 0)
+ continue;
+ if (solv->decisionmap[p] > l)
+ {
+ lasti = i;
+ lastiend = endi;
+ lastsi = -1;
+ break;
+ }
+ if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
+ lastsi = i;
+ }
+ if (lastsi >= 0)
{
- lasti = i;
- lastl = l;
+ /* we have a recommended package that could not be installed */
+ /* take it if our current selection is not recommended */
+ for (i = starti; i < endi - 4; i++)
+ {
+ p = -solv->branches.elements[i];
+ if (p <= 0 || solv->decisionmap[p] != l + 1)
+ continue;
+ if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
+ {
+ lasti = lastsi;
+ lastiend = endi;
+ break;
+ }
+ }
}
+ endi = starti;
}
if (lasti >= 0)
{
- /* kill old solvable so that we do not loop */
- p = solv->branches.elements[lasti];
- solv->branches.elements[lasti] = 0;
- POOL_DEBUG(SAT_DEBUG_STATS, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, solvable2str(pool, pool->solvables + p));
-
- level = lastl;
- revert(solv, level);
- olevel = level;
- level = setpropagatelearn(solv, level, p, disablerules);
- if (level == 0)
- {
- queue_free(&dq);
- return;
- }
- continue;
+ minimizationsteps++;
+ level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
+ continue; /* back to main loop */
}
}
+ /* no minimization found, we're finally finished! */
break;
}
- POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
- POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
+ 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(SOLV_DEBUG_STATS, "done solving.\n\n");
queue_free(&dq);
queue_free(&dqs);
+ if (level < 0)
+ {
+ /* unsolvable */
+ solv->decisioncnt_jobs = solv->decisionq.count;
+ 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, SOLV_DEBUG_RESULT);
+#endif
+}
+
+
+/*-------------------------------------------------------------------
+ *
+ * remove disabled conflicts
+ *
+ * purpose: update the decisionmap after some rules were disabled.
+ * this is used to calculate the suggested/recommended package list.
+ * Also returns a "removed" list to undo the discisionmap changes.
+ */
+
+static void
+removedisabledconflicts(Solver *solv, Queue *removed)
+{
+ Pool *pool = solv->pool;
+ int i, n;
+ Id p, why, *dp;
+ Id new;
+ Rule *r;
+ Id *decisionmap = solv->decisionmap;
+
+ queue_empty(removed);
+ for (i = 0; i < solv->decisionq.count; i++)
+ {
+ p = solv->decisionq.elements[i];
+ if (p > 0)
+ continue; /* conflicts only, please */
+ why = solv->decisionq_why.elements[i];
+ if (why == 0)
+ {
+ /* no rule involved, must be a orphan package drop */
+ continue;
+ }
+ /* we never do conflicts on free decisions, so there
+ * must have been an unit rule */
+ assert(why > 0);
+ r = solv->rules + why;
+ if (r->d < 0 && decisionmap[-p])
+ {
+ /* rule is now disabled, remove from decisionmap */
+ 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 (!removed->count)
+ return;
+ /* we removed some confliced packages. some of them might still
+ * be in conflict, so search for unit rules and re-conflict */
+ new = 0;
+ for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
+ {
+ if (i == solv->nrules)
+ {
+ i = 1;
+ r = solv->rules + i;
+ }
+ if (r->d < 0)
+ continue;
+ if (!r->w2)
+ {
+ if (r->p < 0 && !decisionmap[-r->p])
+ new = r->p;
+ }
+ else if (!r->d)
+ {
+ /* binary rule */
+ if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
+ new = r->p;
+ else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
+ new = r->w2;
+ }
+ else
+ {
+ if (r->p < 0 && decisionmap[-r->p] == 0)
+ new = r->p;
+ if (new || DECISIONMAP_FALSE(r->p))
+ {
+ dp = pool->whatprovidesdata + r->d;
+ while ((p = *dp++) != 0)
+ {
+ if (new && p == new)
+ continue;
+ if (p < 0 && decisionmap[-p] == 0)
+ {
+ if (new)
+ {
+ new = 0;
+ break;
+ }
+ new = p;
+ }
+ else if (!DECISIONMAP_FALSE(p))
+ {
+ new = 0;
+ break;
+ }
+ }
+ }
+ }
+ if (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 */
+ }
+ }
+}
+
+static inline void
+undo_removedisabledconflicts(Solver *solv, Queue *removed)
+{
+ int i;
+ for (i = 0; i < removed->count; i += 2)
+ solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
+}
+
+
+/*-------------------------------------------------------------------
+ *
+ * weaken solvable dependencies
+ */
+
+static void
+weaken_solvable_deps(Solver *solv, Id p)
+{
+ int i;
+ Rule *r;
+
+ for (i = 1, r = solv->rules + i; i < solv->pkgrules_end; i++, r++)
+ {
+ if (r->p != -p)
+ continue;
+ if ((r->d == 0 || r->d == -1) && r->w2 < 0)
+ continue; /* conflict */
+ queue_push(&solv->weakruleq, i);
+ }
+}
+
+
+/********************************************************************/
+/* main() */
+
+
+void
+solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
+{
+ int i;
+ Id how, what, select;
+ Id p, pp;
+ for (i = 0; i < job->count; i += 2)
+ {
+ how = job->elements[i];
+ if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
+ continue;
+ what = job->elements[i + 1];
+ select = how & SOLVER_SELECTMASK;
+ if (!multiversionmap->size)
+ map_grow(multiversionmap, pool->nsolvables);
+ if (select == SOLVER_SOLVABLE_ALL)
+ {
+ FOR_POOL_SOLVABLES(p)
+ MAPSET(multiversionmap, p);
+ }
+ else if (select == SOLVER_SOLVABLE_REPO)
+ {
+ Solvable *s;
+ Repo *repo = pool_id2repo(pool, what);
+ if (repo)
+ FOR_REPO_SOLVABLES(repo, p, s)
+ MAPSET(multiversionmap, p);
+ }
+ FOR_JOB_SELECT(p, pp, select, what)
+ MAPSET(multiversionmap, p);
+ }
+}
+
+void
+solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
+{
+ solver_calculate_multiversionmap(pool, job, multiversionmap);
+}
+
+/*
+ * add a rule created by a job, record job number and weak flag
+ */
+static inline void
+solver_addjobrule(Solver *solv, Id p, Id p2, Id d, Id job, int weak)
+{
+ solver_addrule(solv, p, p2, d);
+ queue_push(&solv->ruletojob, job);
+ if (weak)
+ queue_push(&solv->weakruleq, solv->nrules - 1);
+}
+
+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);
+}
+
+static void
+add_update_target(Solver *solv, Id p, Id how)
+{
+ Pool *pool = solv->pool;
+ Solvable *s = pool->solvables + p;
+ Repo *installed = solv->installed;
+ 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);
+ }
+ }
+ }
+}
+
+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];
+}
+
+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, 0);
+ 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 */
}
-/*-------------------------------------------------------------------
- *
- * refine_suggestion
- *
- * at this point, all rules that led to conflicts are disabled.
- * we re-enable all rules of a problem set but rule "sug", then
- * continue to disable more rules until there as again a solution.
- */
-
-/* FIXME: think about conflicting assertions */
-
static void
-refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
+addedmap2deduceq(Solver *solv, Map *addedmap)
{
Pool *pool = solv->pool;
int i, j;
- Id v;
- Queue disabled;
- int disabledcnt;
+ Id p;
+ Rule *r;
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ queue_empty(&solv->addedmap_deduceq);
+ for (i = 2, j = solv->pkgrules_end - 1; i < pool->nsolvables && j > 0; j--)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
- for (i = 0; problem[i]; i++)
+ 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))
{
- if (problem[i] == sug)
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
- solver_printproblem(solv, problem[i]);
+ /* 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++;
}
- queue_init(&disabled);
- queue_empty(refined);
- queue_push(refined, sug);
-
- /* re-enable all problem rules with the exception of "sug"(gestion) */
- revert(solv, 1);
- reset_solver(solv);
-
- for (i = 0; problem[i]; i++)
- if (problem[i] != sug)
- enableproblem(solv, problem[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++;
+}
- if (sug < 0)
- disableupdaterules(solv, job, -(sug + 1));
- else if (sug >= solv->updaterules && sug < solv->updaterules_end)
+static void
+deduceq2addedmap(Solver *solv, Map *addedmap)
+{
+ int j;
+ Id p;
+ Rule *r;
+ for (j = solv->pkgrules_end - 1; j > 0; j--)
{
- /* enable feature rule */
- Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
- if (r->p)
- enablerule(solv, r);
+ 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);
}
-
- enableweakrules(solv);
-
- for (;;)
+ for (j = 0; j < solv->addedmap_deduceq.count; j++)
{
- int njob, nfeature, nupdate;
- queue_empty(&solv->problems);
- revert(solv, 1); /* XXX no longer needed? */
- reset_solver(solv);
+ p = solv->addedmap_deduceq.elements[j];
+ if (p > 0)
+ MAPSET(addedmap, p);
+ else
+ MAPCLR(addedmap, p);
+ }
+}
- if (!solv->problems.count)
- run_solver(solv, 0, 0);
+#ifdef ENABLE_COMPLEX_DEPS
+static int
+add_complex_jobrules(Solver *solv, Id dep, int flags, int jobidx, int weak)
+{
+ Pool *pool = solv->pool;
+ Queue bq;
+ int i, j;
- if (!solv->problems.count)
- {
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
- IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
- solver_printdecisions(solv);
- break; /* great, no more problems */
- }
- disabledcnt = disabled.count;
- /* start with 1 to skip over proof index */
- njob = nfeature = nupdate = 0;
- for (i = 1; i < solv->problems.count - 1; i++)
- {
- /* ignore solutions in refined */
- v = solv->problems.elements[i];
- if (v == 0)
- break; /* end of problem reached */
- for (j = 0; problem[j]; j++)
- if (problem[j] != sug && problem[j] == v)
- break;
- if (problem[j])
- continue;
- if (v >= solv->featurerules && v < solv->featurerules_end)
- nfeature++;
- else if (v > 0)
- nupdate++;
- else
- njob++;
- queue_push(&disabled, v);
- }
- if (disabled.count == disabledcnt)
- {
- /* no solution found, this was an invalid suggestion! */
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
- refined->count = 0;
- break;
- }
- if (!njob && nupdate && nfeature)
- {
- /* got only update rules, filter out feature rules */
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
- for (i = j = disabledcnt; i < disabled.count; i++)
- {
- v = disabled.elements[i];
- if (v < solv->featurerules || v >= solv->featurerules_end)
- disabled.elements[j++] = v;
- }
- disabled.count = j;
- nfeature = 0;
- }
- if (disabled.count == disabledcnt + 1)
- {
- /* just one suggestion, add it to refined list */
- v = disabled.elements[disabledcnt];
- if (!nfeature)
- queue_push(refined, v); /* do not record feature rules */
- disableproblem(solv, v);
- if (v >= solv->updaterules && v < solv->updaterules_end)
- {
- Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
- if (r->p)
- enablerule(solv, r); /* enable corresponding feature rule */
- }
- if (v < 0)
- disableupdaterules(solv, job, -(v + 1));
- }
+ queue_init(&bq);
+ i = pool_normalize_complex_dep(pool, dep, &bq, flags | CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
+ {
+ queue_free(&bq);
+ if (i == 0)
+ solver_addjobrule(solv, -SYSTEMSOLVABLE, 0, 0, jobidx, weak);
+ return 0;
+ }
+ for (i = 0; i < bq.count; i++)
+ {
+ if (!bq.elements[i])
+ continue;
+ for (j = 0; bq.elements[i + j + 1]; j++)
+ ;
+ if (j > 1)
+ solver_addjobrule(solv, bq.elements[i], 0, pool_ids2whatprovides(pool, bq.elements + i + 1, j), jobidx, weak);
else
- {
- /* more than one solution, disable all */
- /* do not push anything on refine list, as we do not know which solution to choose */
- /* thus, the user will get another problem if he selects this solution, where he
- * can choose the right one */
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
- {
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
- for (i = disabledcnt; i < disabled.count; i++)
- solver_printproblem(solv, disabled.elements[i]);
- }
- for (i = disabledcnt; i < disabled.count; i++)
- {
- v = disabled.elements[i];
- disableproblem(solv, v);
- if (v >= solv->updaterules && v < solv->updaterules_end)
- {
- Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
- if (r->p)
- enablerule(solv, r);
- }
- }
- }
+ solver_addjobrule(solv, bq.elements[i], bq.elements[i + 1], 0, jobidx, weak);
+ i += j + 1;
}
- /* all done, get us back into the same state as before */
- /* enable refined rules again */
- for (i = 0; i < disabled.count; i++)
- enableproblem(solv, disabled.elements[i]);
- /* disable problem rules again */
-
- /* FIXME! */
- for (i = 0; problem[i]; i++)
- enableproblem(solv, problem[i]);
- disableupdaterules(solv, job, -1);
-
- /* disable problem rules again */
- for (i = 0; problem[i]; i++)
- disableproblem(solv, problem[i]);
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
+ queue_free(&bq);
+ return 1;
}
+#endif
-
-/*-------------------------------------------------------------------
- * sorting helper for problems
+/*
+ *
+ * solve job queue
+ *
*/
-static int
-problems_sortcmp(const void *ap, const void *bp)
+int
+solver_solve(Solver *solv, Queue *job)
{
- Id a = *(Id *)ap, b = *(Id *)bp;
- if (a < 0 && b > 0)
- return 1;
- if (a > 0 && b < 0)
- return -1;
- return a - b;
-}
+ Pool *pool = solv->pool;
+ Repo *installed = solv->installed;
+ int i;
+ int oldnrules, initialnrules;
+ Map addedmap; /* '1' == have pkg-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);
-/*-------------------------------------------------------------------
- * sort problems
- */
+ /* 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, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
-static void
-problems_sort(Solver *solv)
-{
- int i, j;
- if (!solv->problems.count)
- return;
- for (i = j = 1; i < solv->problems.count; i++)
+ /* 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, pool->pooljobs.elements);
+ job = &solv->job;
+
+ /* free old stuff in jase we re-run a solver */
+ queuep_free(&solv->update_targets);
+ queuep_free(&solv->cleandeps_updatepkgs);
+ queue_empty(&solv->ruleassertions);
+ solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
+ solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
+ solv->choicerules_ref = solv_free(solv->choicerules_ref);
+ if (solv->noupdate.size)
+ map_empty(&solv->noupdate);
+ map_zerosize(&solv->multiversion);
+ solv->updatemap_all = 0;
+ map_zerosize(&solv->updatemap);
+ solv->bestupdatemap_all = 0;
+ map_zerosize(&solv->bestupdatemap);
+ solv->fixmap_all = 0;
+ map_zerosize(&solv->fixmap);
+ solv->dupmap_all = 0;
+ map_zerosize(&solv->dupmap);
+ map_zerosize(&solv->dupinvolvedmap);
+ solv->droporphanedmap_all = 0;
+ map_zerosize(&solv->droporphanedmap);
+ map_zerosize(&solv->cleandepsmap);
+ map_zerosize(&solv->weakrulemap);
+ 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_jobs = 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)
{
- if (!solv->problems.elements[i])
- {
- if (i > j + 1)
- qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
- if (++i == solv->problems.count)
- break;
- j = i + 1;
- }
+ map_empty(&solv->recommendsmap);
+ map_empty(&solv->suggestsmap);
+ queuep_free(&solv->recommendscplxq);
+ queuep_free(&solv->suggestscplxq);
+ solv->recommends_index = 0;
}
-}
+ queuep_free(&solv->brokenorphanrules);
+ solv->specialupdaters = solv_free(solv->specialupdaters);
-/*-------------------------------------------------------------------
- * convert problems to solutions
- */
+ /*
+ * create basic rule set of all involved packages
+ * use addedmap bitmap to make sure we don't create rules twice
+ */
-static void
-problems_to_solutions(Solver *solv, Queue *job)
-{
- Pool *pool = solv->pool;
- Queue problems;
- Queue solution;
- Queue solutions;
- Id *problem;
- Id why;
- int i, j, nsol;
-
- if (!solv->problems.count)
- return;
- problems_sort(solv);
- queue_clone(&problems, &solv->problems);
- queue_init(&solution);
- queue_init(&solutions);
- /* copy over proof index */
- queue_push(&solutions, problems.elements[0]);
- problem = problems.elements + 1;
- for (i = 1; i < problems.count; i++)
- {
- Id v = problems.elements[i];
- if (v == 0)
- {
- /* mark end of this problem */
- queue_push(&solutions, 0);
- queue_push(&solutions, 0);
- if (i + 1 == problems.count)
- break;
- /* copy over proof of next problem */
- queue_push(&solutions, problems.elements[i + 1]);
- i++;
- problem = problems.elements + i + 1;
- continue;
- }
- refine_suggestion(solv, job, problem, v, &solution);
- if (!solution.count)
- continue; /* this solution didn't work out */
+ /* create multiversion map if needed */
+ solver_calculate_multiversionmap(pool, job, &solv->multiversion);
+
+ map_init(&addedmap, pool->nsolvables);
+ MAPSET(&addedmap, SYSTEMSOLVABLE);
+
+ map_init(&installcandidatemap, pool->nsolvables);
+ queue_init(&q);
+
+ now = solv_timems(0);
+ /*
+ * create rules for all package that could be involved with the solving
+ * so called: pkg rules
+ *
+ */
+ initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
+ if (initialnrules > 1)
+ deduceq2addedmap(solv, &addedmap);
+ if (solv->nrules != initialnrules)
+ solver_shrinkrules(solv, initialnrules);
+ solv->nrules = initialnrules;
+ solv->pkgrules_end = 0;
- nsol = 0;
- for (j = 0; j < solution.count; j++)
+ if (installed)
+ {
+ /* check for update/verify jobs as they need to be known early */
+ /* also setup the droporphaned map, we need it when creating update rules */
+ for (i = 0; i < job->count; i += 2)
{
- why = solution.elements[j];
- /* must be either job descriptor or update rule */
- assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
-#if 0
- solver_printproblem(solv, why);
-#endif
- if (why < 0)
- {
- /* job descriptor */
- queue_push(&solutions, 0);
- queue_push(&solutions, -why);
- }
- else
+ how = job->elements[i];
+ what = job->elements[i + 1];
+ select = how & SOLVER_SELECTMASK;
+ switch (how & SOLVER_JOBMASK)
{
- /* update rule, find replacement package */
- Id p, d, *dp, rp = 0;
- Rule *rr;
- p = solv->installed->start + (why - solv->updaterules);
- if (solv->decisionmap[p] > 0)
- continue; /* false alarm, turned out we can keep the package */
- rr = solv->rules + solv->featurerules + (why - solv->updaterules);
- if (!rr->p)
- rr = solv->rules + why;
- if (rr->w2)
+ case SOLVER_VERIFY:
+ 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 (s->repo != installed)
+ continue;
+ if (!solv->fixmap.size)
+ map_grow(&solv->fixmap, installed->end - installed->start);
+ MAPSET(&solv->fixmap, p - installed->start);
+ }
+ break;
+ case SOLVER_UPDATE:
+ if (select == SOLVER_SOLVABLE_ALL)
{
- d = rr->d < 0 ? -rr->d - 1 : rr->d;
- if (!d)
+ solv->updatemap_all = 1;
+ if (how & SOLVER_FORCEBEST)
+ solv->bestupdatemap_all = 1;
+ if (how & SOLVER_CLEANDEPS)
{
- if (solv->decisionmap[rr->w2] > 0 && pool->solvables[rr->w2].repo != solv->installed)
- rp = rr->w2;
+ FOR_REPO_SOLVABLES(installed, p, s)
+ add_cleandeps_package(solv, p);
}
- else
+ }
+ 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))
{
- for (dp = pool->whatprovidesdata + d; *dp; dp++)
+ int targeted = 1;
+ FOR_JOB_SELECT(p, pp, select, what)
{
- if (solv->decisionmap[*dp] > 0 && pool->solvables[*dp].repo != solv->installed)
+ 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)
{
- rp = *dp;
- break;
+ 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;
+ case SOLVER_DROP_ORPHANED:
+ if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
+ solv->droporphanedmap_all = 1;
+ FOR_JOB_SELECT(p, pp, select, what)
+ {
+ s = pool->solvables + p;
+ if (s->repo != installed)
+ continue;
+ if (!solv->droporphanedmap.size)
+ map_grow(&solv->droporphanedmap, installed->end - installed->start);
+ MAPSET(&solv->droporphanedmap, p - installed->start);
}
- queue_push(&solutions, p);
- queue_push(&solutions, rp);
+ break;
+ default:
+ break;
}
- nsol++;
- }
- /* mark end of this solution */
- if (nsol)
- {
- queue_push(&solutions, 0);
- queue_push(&solutions, 0);
}
- else
- {
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
- }
- }
- queue_free(&solution);
- queue_free(&problems);
- /* copy queue over to solutions */
- queue_free(&solv->problems);
- queue_clone(&solv->problems, &solutions);
-
- /* bring solver back into problem state */
- revert(solv, 1); /* XXX move to reset_solver? */
- reset_solver(solv);
- assert(solv->problems.count == solutions.count);
- queue_free(&solutions);
-}
+ if (solv->update_targets)
+ transform_update_targets(solv);
+ oldnrules = solv->nrules;
+ FOR_REPO_SOLVABLES(installed, p, s)
+ solver_addpkgrulesforsolvable(solv, s, &addedmap);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for installed solvables\n", solv->nrules - oldnrules);
+ oldnrules = solv->nrules;
+ FOR_REPO_SOLVABLES(installed, p, s)
+ solver_addpkgrulesforupdaters(solv, s, &addedmap, 1);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for updaters of installed solvables\n", solv->nrules - oldnrules);
+ }
-/*-------------------------------------------------------------------
- *
- * problem iterator
- *
- * advance to next problem
- */
+ /*
+ * create rules for all packages involved in the job
+ * (to be installed or removed)
+ */
-Id
-solver_next_problem(Solver *solv, Id problem)
-{
- Id *pp;
- if (problem == 0)
- return solv->problems.count ? 1 : 0;
- pp = solv->problems.elements + problem;
- while (pp[0] || pp[1])
+ oldnrules = solv->nrules;
+ for (i = 0; i < job->count; i += 2)
{
- /* solution */
- pp += 2;
- while (pp[0] || pp[1])
- pp += 2;
- pp += 2;
+ how = job->elements[i];
+ what = job->elements[i + 1];
+ select = how & SOLVER_SELECTMASK;
+
+ switch (how & SOLVER_JOBMASK)
+ {
+ case SOLVER_INSTALL:
+ FOR_JOB_SELECT(p, pp, select, what)
+ {
+ MAPSET(&installcandidatemap, p);
+ solver_addpkgrulesforsolvable(solv, pool->solvables + p, &addedmap);
+ }
+ break;
+ case SOLVER_DISTUPGRADE:
+ if (select == SOLVER_SOLVABLE_ALL)
+ {
+ solv->dupmap_all = 1;
+ solv->updatemap_all = 1;
+ if (how & SOLVER_FORCEBEST)
+ solv->bestupdatemap_all = 1;
+ }
+ if (!solv->dupmap_all || solv->allowuninstall)
+ hasdupjob = 1;
+ break;
+ default:
+ break;
+ }
}
- pp += 2;
- problem = pp - solv->problems.elements;
- if (problem >= solv->problems.count)
- return 0;
- return problem + 1;
-}
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for packages involved in a job\n", solv->nrules - oldnrules);
-/*-------------------------------------------------------------------
- *
- * solution iterator
- */
+ /*
+ * add rules for suggests, enhances
+ */
+ oldnrules = solv->nrules;
+ solver_addpkgrulesforweak(solv, &addedmap);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
-Id
-solver_next_solution(Solver *solv, Id problem, Id solution)
-{
- Id *pp;
- if (solution == 0)
- {
- solution = problem;
- pp = solv->problems.elements + solution;
- return pp[0] || pp[1] ? solution : 0;
- }
- pp = solv->problems.elements + solution;
- while (pp[0] || pp[1])
- pp += 2;
- pp += 2;
- solution = pp - solv->problems.elements;
- return pp[0] || pp[1] ? solution : 0;
-}
+#ifdef ENABLE_LINKED_PKGS
+ oldnrules = solv->nrules;
+ solver_addpkgrulesforlinked(solv, &addedmap);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of linked packages\n", solv->nrules - oldnrules);
+#endif
+ /*
+ * first pass done, we now have all the pkg rules we need.
+ * unify existing rules before going over all job rules and
+ * policy rules.
+ * at this point the system is always solvable,
+ * as an empty system (remove all packages) is a valid solution
+ */
-/*-------------------------------------------------------------------
- *
- * solution element iterator
- */
+ IF_POOLDEBUG (SOLV_DEBUG_STATS)
+ {
+ int possible = 0, installable = 0;
+ for (i = 1; i < pool->nsolvables; i++)
+ {
+ if (pool_installable(pool, pool->solvables + i))
+ installable++;
+ if (MAPTST(&addedmap, i))
+ possible++;
+ }
+ POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
+ }
-Id
-solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
-{
- Id *pp;
- element = element ? element + 2 : solution;
- pp = solv->problems.elements + element;
- if (!(pp[0] || pp[1]))
- return 0;
- *p = pp[0];
- *rp = pp[1];
- return element;
-}
+ if (solv->nrules > initialnrules)
+ solver_unifyrules(solv); /* remove duplicate pkg rules */
+ solv->pkgrules_end = solv->nrules; /* mark end of pkg rules */
+ if (solv->nrules > initialnrules)
+ addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
-/*-------------------------------------------------------------------
- *
- * Retrieve information about a problematic rule
- *
- * this is basically the reverse of addrpmrulesforsolvable
- */
+ POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule creation took %d ms\n", solv_timems(now));
-SolverProbleminfo
-solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
-{
- Pool *pool = solv->pool;
- Repo *installed = solv->installed;
- Rule *r;
- Solvable *s;
- int dontfix = 0;
- Id p, d, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
+ /* create dup maps if needed. We need the maps early to create our
+ * update rules */
+ if (hasdupjob)
+ solver_createdupmaps(solv);
- assert(rid > 0);
- if (rid >= solv->jobrules && rid < solv->jobrules_end)
- {
+ /*
+ * create feature rules
+ *
+ * foreach installed:
+ * create assertion (keep installed, if no update available)
+ * or
+ * create update rule (A|update1(A)|update2(A)|...)
+ *
+ * those are used later on to keep a version of the installed packages in
+ * best effort mode
+ */
- r = solv->rules + rid;
- p = solv->ruletojob.elements[rid - solv->jobrules];
- *depp = job->elements[p + 1];
- *sourcep = p;
- *targetp = job->elements[p];
- d = r->d < 0 ? -r->d - 1 : r->d;
- if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
- return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
- return SOLVER_PROBLEM_JOB_RULE;
- }
- if (rid >= solv->updaterules && rid < solv->updaterules_end)
- {
- *depp = 0;
- *sourcep = solv->installed->start + (rid - solv->updaterules);
- *targetp = 0;
- return SOLVER_PROBLEM_UPDATE_RULE;
- }
- assert(rid < solv->rpmrules_end);
- r = solv->rules + rid;
- assert(r->p < 0);
- d = r->d < 0 ? -r->d - 1 : r->d;
- if (d == 0 && r->w2 == 0)
+ solv->featurerules = solv->nrules; /* mark start of feature rules */
+ if (installed)
{
- /* a rpm rule assertion */
- s = pool->solvables - r->p;
- if (installed && !solv->fixsystem && s->repo == installed)
- dontfix = 1;
- assert(!dontfix); /* dontfix packages never have a neg assertion */
- *sourcep = -r->p;
- *targetp = 0;
- /* see why the package is not installable */
- if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
- {
- *depp = 0;
- return SOLVER_PROBLEM_NOT_INSTALLABLE;
- }
- /* check requires */
- if (s->requires)
+ /* foreach possibly installed solvable */
+ for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
{
- reqp = s->repo->idarraydata + s->requires;
- while ((req = *reqp++) != 0)
- {
- if (req == SOLVABLE_PREREQMARKER)
- continue;
- dp = pool_whatprovides(pool, req);
- if (*dp == 0)
- break;
- }
- if (req)
+ if (s->repo != installed)
{
- *depp = req;
- return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
+ solver_addrule(solv, 0, 0, 0); /* create dummy rule */
+ continue;
}
+ solver_addupdaterule(solv, s, 1); /* allow s to be updated */
}
- if (!solv->allowselfconflicts && s->conflicts)
- {
- conp = s->repo->idarraydata + s->conflicts;
- while ((con = *conp++) != 0)
- FOR_PROVIDES(p, pp, con)
- if (p == -r->p)
- {
- *depp = con;
- return SOLVER_PROBLEM_SELF_CONFLICT;
- }
- }
- /* should never happen */
- *depp = 0;
- return SOLVER_PROBLEM_RPM_RULE;
+ /* make sure we accounted for all rules */
+ assert(solv->nrules - solv->featurerules == installed->end - installed->start);
}
- s = pool->solvables - r->p;
- if (installed && !solv->fixsystem && s->repo == installed)
- dontfix = 1;
- if (d == 0 && r->w2 < 0)
- {
- /* a package conflict */
- Solvable *s2 = pool->solvables - r->w2;
- int dontfix2 = 0;
+ solv->featurerules_end = solv->nrules;
+
+ /*
+ * Add update rules for installed solvables
+ *
+ * almost identical to feature rules
+ * except that downgrades/archchanges/vendorchanges are not allowed
+ */
- if (installed && !solv->fixsystem && s2->repo == installed)
- dontfix2 = 1;
+ solv->updaterules = solv->nrules;
- /* if both packages have the same name and at least one of them
- * is not installed, they conflict */
- if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
+ if (installed)
+ { /* foreach installed solvables */
+ /* we create all update rules, but disable some later on depending on the job */
+ for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
{
- /* also check noobsoletes map */
- if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
- || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
- || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -r->w2)))
+ Rule *sr;
+
+ if (s->repo != installed)
{
- *depp = 0;
- *sourcep = -r->p;
- *targetp = -r->w2;
- return SOLVER_PROBLEM_SAME_NAME;
+ solver_addrule(solv, 0, 0, 0); /* create dummy rule */
+ continue;
}
+ solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
+ /*
+ * check for and remove duplicate
+ */
+ r = solv->rules + solv->nrules - 1; /* r: update rule */
+ if (!r->p)
+ continue;
+ sr = r - (installed->end - installed->start); /* sr: feature rule */
+ /* it's also orphaned if the feature rule consists just of the installed package */
+ if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
+ queue_push(&solv->orphaned, i);
+ if (!solver_rulecmp(solv, r, sr))
+ memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
+ else
+ solver_disablerule(solv, sr); /* disable feature rule for now */
}
+ /* consistency check: we added a rule for _every_ installed solvable */
+ assert(solv->nrules - solv->updaterules == installed->end - installed->start);
+ }
+ solv->updaterules_end = solv->nrules;
+
+
+ /*
+ * now add all job rules
+ */
- /* check conflicts in both directions */
- if (s->conflicts)
+ 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;
+ select = how & SOLVER_SELECTMASK;
+ switch (how & SOLVER_JOBMASK)
{
- conp = s->repo->idarraydata + s->conflicts;
- while ((con = *conp++) != 0)
- {
- FOR_PROVIDES(p, pp, con)
- {
- if (dontfix && pool->solvables[p].repo == installed)
- continue;
- if (p != -r->w2)
- continue;
- *depp = con;
- *sourcep = -r->p;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_CONFLICT;
- }
+ case SOLVER_INSTALL:
+ 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;
+ d = 0;
}
- }
- if (s2->conflicts)
- {
- conp = s2->repo->idarraydata + s2->conflicts;
- while ((con = *conp++) != 0)
- {
- FOR_PROVIDES(p, pp, con)
+#ifdef ENABLE_COMPLEX_DEPS
+ else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
+ {
+ if (add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? CPLXDEPS_NAME : 0, i, weak))
+ if (how & SOLVER_FORCEBEST)
+ hasbestinstalljob = 1;
+ break;
+ }
+#endif
+ else
+ {
+ queue_empty(&q);
+ FOR_JOB_SELECT(p, pp, select, what)
+ queue_push(&q, p);
+ if (!q.count)
{
- if (dontfix2 && pool->solvables[p].repo == installed)
- continue;
- if (p != -r->p)
- continue;
- *depp = con;
- *sourcep = -r->w2;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_CONFLICT;
+ if (select == SOLVER_SOLVABLE_ONE_OF)
+ break; /* ignore empty installs */
+ /* no candidate found or unsupported, make this an impossible rule */
+ queue_push(&q, -SYSTEMSOLVABLE);
}
+ p = queue_shift(&q); /* get first candidate */
+ d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
}
- }
- /* check obsoletes in both directions */
- if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
- {
- obsp = s->repo->idarraydata + s->obsoletes;
- while ((obs = *obsp++) != 0)
+ /* force install of namespace supplements hack */
+ if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
{
- FOR_PROVIDES(p, pp, obs)
+ Reldep *rd = GETRELDEP(pool, what);
+ if (rd->flags == REL_NAMESPACE)
{
- if (p != -r->w2)
- continue;
- if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
- continue;
- *depp = obs;
- *sourcep = -r->p;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+ 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);
}
}
- }
- if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->w2)))
- {
- obsp = s2->repo->idarraydata + s2->obsoletes;
- while ((obs = *obsp++) != 0)
+ solver_addjobrule(solv, p, 0, d, i, weak);
+ if (how & SOLVER_FORCEBEST)
+ hasbestinstalljob = 1;
+ break;
+ case SOLVER_ERASE:
+ 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, 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, 0, i, weak);
+ }
+#ifdef ENABLE_COMPLEX_DEPS
+ else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
+ {
+ /* no special "erase a specific solvable" handling? */
+ add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? (CPLXDEPS_NAME | CPLXDEPS_TODNF | CPLXDEPS_INVERT) : (CPLXDEPS_TODNF | CPLXDEPS_INVERT), i, weak);
+ break;
+ }
+#endif
+ 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, 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)
{
- FOR_PROVIDES(p, pp, obs)
+ int j, k;
+ k = solv->nrules;
+ FOR_PROVIDES(p, pp, name)
{
- if (p != -r->p)
+ s = pool->solvables + p;
+ if (s->name != name)
continue;
- if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+ /* keep other versions installed */
+ if (s->repo == installed)
continue;
- *depp = obs;
- *sourcep = -r->w2;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+ /* keep installcandidates of other jobs */
+ if (MAPTST(&installcandidatemap, p))
+ continue;
+ /* 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, 0, i, weak); /* remove by id */
}
}
- }
- if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
- {
- FOR_PROVIDES(p, pp, s->name)
+ break;
+
+ case SOLVER_UPDATE:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ break;
+ case SOLVER_VERIFY:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ break;
+ case SOLVER_WEAKENDEPS:
+ 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_MULTIVERSION:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ break;
+ case SOLVER_LOCK:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
+ if (select == SOLVER_SOLVABLE_ALL)
{
- if (p != -r->w2)
- continue;
- *depp = s->name;
- *sourcep = -r->p;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+ FOR_POOL_SOLVABLES(p)
+ solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
}
- }
- if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->w2)))
- {
- FOR_PROVIDES(p, pp, s2->name)
+ else if (select == SOLVER_SOLVABLE_REPO)
{
- if (p != -r->p)
- continue;
- *depp = s2->name;
- *sourcep = -r->w2;
- *targetp = p;
- return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+ 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, 0, i, weak);
}
+ FOR_JOB_SELECT(p, pp, select, what)
+ solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
+ break;
+ case SOLVER_DISTUPGRADE:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
+ break;
+ case SOLVER_DROP_ORPHANED:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
+ break;
+ case SOLVER_USERINSTALLED:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
+ break;
+ default:
+ POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
+ break;
}
- /* all cases checked, can't happen */
- *depp = 0;
- *sourcep = -r->p;
- *targetp = 0;
- return SOLVER_PROBLEM_RPM_RULE;
- }
- /* simple requires */
- if (s->requires)
- {
- reqp = s->repo->idarraydata + s->requires;
- while ((req = *reqp++) != 0)
+
+ IF_POOLDEBUG (SOLV_DEBUG_JOB)
{
- if (req == SOLVABLE_PREREQMARKER)
- continue;
- dp = pool_whatprovides(pool, req);
- if (d == 0)
+ int j;
+ if (solv->nrules == oldnrules)
+ POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
+ for (j = oldnrules; j < solv->nrules; j++)
{
- if (*dp == r->w2 && dp[1] == 0)
- break;
+ POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
+ solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
}
- else if (dp - pool->whatprovidesdata == d)
- break;
}
- if (req)
+ }
+ assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
+ solv->jobrules_end = solv->nrules;
+
+ /* now create infarch and dup rules */
+ if (!solv->noinfarchcheck)
+ {
+ solver_addinfarchrules(solv, &addedmap);
+#if 0
+ if (pool->implicitobsoleteusescolors)
{
- *depp = req;
- *sourcep = -r->p;
- *targetp = 0;
- return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
+ /* currently doesn't work well with infarch rules, so make
+ * them weak */
+ for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
+ queue_push(&solv->weakruleq, i);
}
+#endif
}
- /* all cases checked, can't happen */
- *depp = 0;
- *sourcep = -r->p;
- *targetp = 0;
- return SOLVER_PROBLEM_RPM_RULE;
-}
+ else
+ solv->infarchrules = solv->infarchrules_end = solv->nrules;
+ if (hasdupjob)
+ solver_addduprules(solv, &addedmap);
+ else
+ solv->duprules = solv->duprules_end = solv->nrules;
-/*-------------------------------------------------------------------
- *
- * find problem rule
- */
+ if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
+ solver_addbestrules(solv, hasbestinstalljob);
+ else
+ solv->bestrules = solv->bestrules_end = solv->nrules;
-static void
-findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
-{
- Id rid, d;
- Id lreqr, lconr, lsysr, ljobr;
- Rule *r;
- int reqassert = 0;
+ if (hasdupjob)
+ solver_freedupmaps(solv); /* no longer needed */
+
+ if (solv->do_yum_obsoletes)
+ solver_addyumobsrules(solv);
+ else
+ solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
+
+ if (1)
+ solver_addchoicerules(solv);
+ else
+ solv->choicerules = solv->choicerules_end = solv->nrules;
- lreqr = lconr = lsysr = ljobr = 0;
- while ((rid = solv->learnt_pool.elements[idx++]) != 0)
+ if (0)
{
- assert(rid > 0);
- if (rid >= solv->learntrules)
- findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
- else if (rid >= solv->jobrules && rid < solv->jobrules_end)
- {
- if (!*jobrp)
- *jobrp = rid;
- }
- else if (rid >= solv->updaterules && rid < solv->updaterules_end)
- {
- if (!*sysrp)
- *sysrp = rid;
- }
- else
+ for (i = solv->featurerules; i < solv->nrules; i++)
+ solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
+ }
+ /* all rules created
+ * --------------------------------------------------------------
+ * prepare for solving
+ */
+
+ /* free unneeded memory */
+ map_free(&addedmap);
+ map_free(&installcandidatemap);
+ queue_free(&q);
+
+ POOL_DEBUG(SOLV_DEBUG_STATS, "%d pkg rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->pkgrules_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 */
+ if (solv->weakruleq.count)
+ {
+ map_grow(&solv->weakrulemap, solv->nrules);
+ for (i = 0; i < solv->weakruleq.count; i++)
{
- assert(rid < solv->rpmrules_end);
- r = solv->rules + rid;
- d = r->d < 0 ? -r->d - 1 : r->d;
- if (!d && r->w2 < 0)
- {
- if (!*conrp)
- *conrp = rid;
- }
- else
- {
- if (!d && r->w2 == 0 && !reqassert)
- {
- /* prefer assertions (XXX: bad idea?) */
- *reqrp = rid;
- reqassert = 1;
- }
- if (!*reqrp)
- *reqrp = rid;
- else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed)
- {
- /* prefer rules of installed packages */
- Id op = *reqrp >= 0 ? solv->rules[*reqrp].p : -*reqrp;
- if (op <= 0 || solv->pool->solvables[op].repo != solv->installed)
- *reqrp = rid;
- }
- }
+ p = solv->weakruleq.elements[i];
+ MAPSET(&solv->weakrulemap, p);
}
}
- if (!*reqrp && lreqr)
- *reqrp = lreqr;
- if (!*conrp && lconr)
- *conrp = lconr;
- if (!*jobrp && ljobr)
- *jobrp = ljobr;
- if (!*sysrp && lsysr)
- *sysrp = lsysr;
-}
+ /* 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);
+ }
-/*-------------------------------------------------------------------
- *
- * find problem rule
- *
- * search for a rule that describes the problem to the
- * user. A pretty hopeless task, actually. We currently
- * prefer simple requires.
- */
+ /* all new rules are learnt after this point */
+ solv->learntrules = solv->nrules;
-Id
-solver_findproblemrule(Solver *solv, Id problem)
-{
- Id reqr, conr, sysr, jobr;
- Id idx = solv->problems.elements[problem - 1];
- reqr = conr = sysr = jobr = 0;
- findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
- if (reqr)
- return reqr;
- if (conr)
- return conr;
- if (sysr)
- return sysr;
- if (jobr)
- return jobr;
- assert(0);
+ /* create watches chains */
+ makewatches(solv);
+
+ /* create assertion index. it is only used to speed up
+ * makeruledecsions() a bit */
+ for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
+ if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
+ queue_push(&solv->ruleassertions, i);
+
+ /* disable update rules that conflict with our job */
+ solver_disablepolicyrules(solv);
+
+ /* break orphans if requested */
+ if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
+ solver_breakorphans(solv);
+
+ /*
+ * ********************************************
+ * solve!
+ * ********************************************
+ */
+
+ now = solv_timems(0);
+ solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
+ POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
+
+ /*
+ * prepare solution queue if there were problems
+ */
+ 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->multiversion);
+}
-/*-------------------------------------------------------------------
- *
- * create reverse obsoletes map for installed solvables
- *
- * for each installed solvable find which packages with *different* names
- * obsolete the solvable.
- * this index is used in policy_findupdatepackages if noupdateprovide is set.
- */
+void solver_get_orphaned(Solver *solv, Queue *orphanedq)
+{
+ queue_free(orphanedq);
+ queue_init_clone(orphanedq, &solv->orphaned);
+}
-static void
-create_obsolete_index(Solver *solv)
+void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
{
Pool *pool = solv->pool;
+ Queue redoq, disabledq;
+ int goterase, i;
Solvable *s;
- Repo *installed = solv->installed;
- Id p, *pp, obs, *obsp, *obsoletes, *obsoletes_data;
- int i, n;
+ Rule *r;
+ Map obsmap;
- if (!installed || !installed->nsolvables)
+ if (!recommendationsq && !suggestionsq)
return;
- solv->obsoletes = obsoletes = sat_calloc(installed->end - installed->start, sizeof(Id));
- for (i = 1; i < pool->nsolvables; i++)
+
+ map_init(&obsmap, pool->nsolvables);
+ if (solv->installed)
{
- s = pool->solvables + i;
- if (!s->obsoletes)
+ 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->multiversion.size && MAPTST(&solv->multiversion, 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 (!pool_installable(pool, s))
+ if (r->p >= 0) /* install job? */
continue;
- obsp = s->repo->idarraydata + s->obsoletes;
- while ((obs = *obsp++) != 0)
+ queue_push(&disabledq, i);
+ solver_disablerule(solv, r);
+ goterase++;
+ }
+
+ if (goterase)
+ {
+ enabledisablelearntrules(solv);
+ removedisabledconflicts(solv, &redoq);
+ }
+
+ /*
+ * find recommended packages
+ */
+ 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_PROVIDES(p, pp, obs)
+ for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
{
- if (pool->solvables[p].repo != installed)
- continue;
- if (pool->solvables[p].name == s->name)
- continue;
- if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+ Id why;
+ why = solv->decisionq_why.elements[i];
+ if (why)
+ continue; /* forced by unit rule or dep resolving */
+ p = solv->decisionq.elements[i];
+ if (p < 0)
continue;
- obsoletes[p - installed->start]++;
+ 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)
+ {
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, rec))
+ {
+ do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
+ continue;
+ }
+#endif
+ 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);
+ }
}
}
- }
- n = 0;
- for (i = 0; i < installed->nsolvables; i++)
- if (obsoletes[i])
- {
- n += obsoletes[i] + 1;
- obsoletes[i] = n;
- }
- solv->obsoletes_data = obsoletes_data = sat_calloc(n + 1, sizeof(Id));
- POOL_DEBUG(SAT_DEBUG_STATS, "obsoletes data: %d entries\n", n + 1);
- for (i = pool->nsolvables - 1; i > 0; i--)
- {
- s = pool->solvables + i;
- if (!s->obsoletes)
- continue;
- if (!pool_installable(pool, s))
- continue;
- obsp = s->repo->idarraydata + s->obsoletes;
- while ((obs = *obsp++) != 0)
+ for (i = 1; i < pool->nsolvables; i++)
{
- FOR_PROVIDES(p, pp, obs)
+ 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 (pool->solvables[p].repo != installed)
+ if (!s->supplements)
continue;
- if (pool->solvables[p].name == s->name)
+ if (!pool_installable(pool, s))
continue;
- if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+ if (!solver_is_supplementing(solv, s))
continue;
- p -= installed->start;
- if (obsoletes_data[obsoletes[p]] != i)
- obsoletes_data[--obsoletes[p]] = i;
}
+ queue_push(recommendationsq, i);
}
+ /* we use MODE_SUGGEST here so that repo prio is ignored */
+ policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
}
-}
-
-
-/*-------------------------------------------------------------------
- *
- * remove disabled conflicts
- */
-static void
-removedisabledconflicts(Solver *solv, Queue *removed)
-{
- Pool *pool = solv->pool;
- int i, n;
- Id p, why, *dp;
- Id new;
- Rule *r;
- Id *decisionmap = solv->decisionmap;
+ /*
+ * find suggested packages
+ */
- POOL_DEBUG(SAT_DEBUG_STATS, "removedisabledconflicts\n");
- queue_empty(removed);
- for (i = 0; i < solv->decisionq.count; i++)
- {
- p = solv->decisionq.elements[i];
- if (p > 0)
- continue;
- /* a conflict. we never do conflicts on free decisions, so there
- * must have been an unit rule */
- why = solv->decisionq_why.elements[i];
- assert(why > 0);
- r = solv->rules + why;
- if (r->d < 0 && decisionmap[-p])
- {
- /* rule is now disabled, remove from decisionmap */
- POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
- queue_push(removed, -p);
- queue_push(removed, decisionmap[-p]);
- decisionmap[-p] = 0;
- }
- }
- if (!removed->count)
- return;
- /* we removed some confliced packages. some of them might still
- * be in conflict, so search for unit rules and re-conflict */
- new = 0;
- for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
+ if (suggestionsq)
{
- if (i == solv->nrules)
- {
- i = 1;
- r = solv->rules + i;
- }
- if (r->d < 0)
- continue;
- if (!r->w2)
- {
- if (r->p < 0 && !decisionmap[-r->p])
- new = r->p;
- }
- else if (!r->d)
- {
- /* binary rule */
- if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
- new = r->p;
- else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
- new = r->w2;
- }
- else
+ Id sug, *sugp, p, pp;
+
+ 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++)
{
- if (r->p < 0 && decisionmap[-r->p] == 0)
- new = r->p;
- if (new || DECISIONMAP_FALSE(r->p))
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ continue;
+ s = pool->solvables + p;
+ if (s->suggests)
{
- dp = pool->whatprovidesdata + r->d;
- while ((p = *dp++) != 0)
+ sugp = s->repo->idarraydata + s->suggests;
+ while ((sug = *sugp++) != 0)
{
- if (new && p == new)
- continue;
- if (p < 0 && decisionmap[-p] == 0)
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, sug))
{
- if (new)
- {
- new = 0;
- break;
- }
- new = p;
+ do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
+ continue;
}
- else if (!DECISIONMAP_FALSE(p))
- {
- new = 0;
+#endif
+ 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);
}
}
}
- if (new)
+ for (i = 1; i < pool->nsolvables; i++)
{
- POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
- decisionmap[-new] = -1;
- new = 0;
- n = 0; /* redo all rules */
+ 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 */
+
/*-------------------------------------------------------------------
*
- * weaken solvable dependencies
+ * calculate DU changes
*/
-static void
-weaken_solvable_deps(Solver *solv, Id p)
+void
+solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
{
- int i;
- Rule *r;
+ Map installedmap;
- for (i = 1, r = solv->rules + i; i < solv->featurerules; i++, r++)
- {
- if (r->p != -p)
- continue;
- if ((r->d == 0 || r->d == -1) && r->w2 < 0)
- continue; /* conflict */
- queue_push(&solv->weakruleq, i);
- }
+ solver_create_state_maps(solv, &installedmap, 0);
+ pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
+ map_free(&installedmap);
}
-/********************************************************************/
-/* main() */
-/*
- *
- * solve job queue
+/*-------------------------------------------------------------------
*
+ * calculate changes in install size
*/
+int
+solver_calc_installsizechange(Solver *solv)
+{
+ Map installedmap;
+ int change;
+
+ solver_create_state_maps(solv, &installedmap, 0);
+ change = pool_calc_installsizechange(solv->pool, &installedmap);
+ map_free(&installedmap);
+ return change;
+}
+
void
-solver_solve(Solver *solv, Queue *job)
+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;
- Repo *installed = solv->installed;
+ Map installedmap;
int i;
- int oldnrules;
- Map addedmap; /* '1' == have rpm-rules for solvable */
- Id how, what, weak, p, *pp, d;
- Queue q, redoq;
- Solvable *s;
- int goterase;
- Rule *r;
-
- /* create whatprovides if not already there */
- if (!pool->whatprovides)
- pool_createwhatprovides(pool);
+ pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
+ pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 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);
+}
- /* create obsolete index if needed */
- if (solv->noupdateprovide)
- create_obsolete_index(solv);
+/*-------------------------------------------------------------------
+ *
+ * decision introspection
+ */
- /*
- * create basic rule set of all involved packages
- * use addedmap bitmap to make sure we don't create rules twice
- *
- */
+int
+solver_get_decisionlevel(Solver *solv, Id p)
+{
+ return solv->decisionmap[p];
+}
- /* create noobsolete map if needed */
- for (i = 0; i < job->count; i += 2)
- {
- how = job->elements[i] & ~SOLVER_WEAK;
- what = job->elements[i + 1];
- switch(how)
- {
- case SOLVER_NOOBSOLETES_SOLVABLE:
- case SOLVER_NOOBSOLETES_SOLVABLE_NAME:
- case SOLVER_NOOBSOLETES_SOLVABLE_PROVIDES:
- if (!solv->noobsoletes.size)
- map_init(&solv->noobsoletes, pool->nsolvables);
- if (how == SOLVER_NOOBSOLETES_SOLVABLE)
- {
- MAPSET(&solv->noobsoletes, what);
- break;
- }
- FOR_PROVIDES(p, pp, what)
- {
- if (how == SOLVER_NOOBSOLETES_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- MAPSET(&solv->noobsoletes, p);
- }
- break;
- default:
- break;
- }
- }
+void
+solver_get_decisionqueue(Solver *solv, Queue *decisionq)
+{
+ queue_free(decisionq);
+ queue_init_clone(decisionq, &solv->decisionq);
+}
- map_init(&addedmap, pool->nsolvables);
- queue_init(&q);
+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];
+}
- /*
- * always install our system solvable
- */
- MAPSET(&addedmap, SYSTEMSOLVABLE);
- queue_push(&solv->decisionq, SYSTEMSOLVABLE);
- queue_push(&solv->decisionq_why, 0);
- solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
+void
+solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
+{
+ Id p;
+ int i;
- /*
- * create rules for all package that could be involved with the solving
- * so called: rpm rules
- *
- */
- if (installed)
+ queue_empty(decisionq);
+ for (i = 0; i < solv->decisionq.count; i++)
{
- oldnrules = solv->nrules;
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for installed solvables ***\n");
- FOR_REPO_SOLVABLES(installed, p, s)
- 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");
- oldnrules = solv->nrules;
- FOR_REPO_SOLVABLES(installed, p, s)
- addrpmrulesforupdaters(solv, s, &addedmap, 1);
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
+ p = solv->decisionq.elements[i];
+ if (p < 0)
+ p = -p;
+ if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
+ break;
}
-
- /*
- * create rules for all packages involved in the job
- * (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)
+ if (i == solv->decisionq.count)
+ return;
+ for (i = 0; i < solv->decisionq.count; i++)
{
- how = job->elements[i] & ~SOLVER_WEAK;
- what = job->elements[i + 1];
-
- switch(how)
- {
- case SOLVER_INSTALL_SOLVABLE:
- addrpmrulesforsolvable(solv, pool->solvables + what, &addedmap);
- break;
- case SOLVER_INSTALL_SOLVABLE_NAME:
- case SOLVER_INSTALL_SOLVABLE_PROVIDES:
- FOR_PROVIDES(p, pp, what)
- {
- /* if by name, ensure that the name matches */
- if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
- }
- break;
- case SOLVER_INSTALL_SOLVABLE_UPDATE:
- /* dont allow downgrade */
- addrpmrulesforupdaters(solv, pool->solvables + what, &addedmap, 0);
- break;
- case SOLVER_INSTALL_SOLVABLE_ONE_OF:
- pp = pool->whatprovidesdata + what;
- while ((p = *pp++) != 0)
- addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
- break;
- }
+ 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;
}
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
+}
- oldnrules = solv->nrules;
-
- /*
- * add rules for suggests, [freshens,] enhances
- */
- addrpmrulesforweak(solv, &addedmap);
- POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
+int
+solver_describe_decision(Solver *solv, Id p, Id *infop)
+{
+ int i;
+ Id pp, why;
- IF_POOLDEBUG (SAT_DEBUG_STATS)
+ 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 (infop)
+ *infop = why > 0 ? why : -why;
+ if (why > 0)
+ return SOLVER_REASON_UNIT_RULE;
+ why = -why;
+ if (i == 0)
+ return SOLVER_REASON_KEEP_INSTALLED; /* the systemsolvable */
+ if (i < solv->decisioncnt_update)
+ return SOLVER_REASON_RESOLVE_JOB;
+ if (i < solv->decisioncnt_keep)
{
- int possible = 0, installable = 0;
- for (i = 1; i < pool->nsolvables; i++)
- {
- if (pool_installable(pool, pool->solvables + i))
- installable++;
- if (MAPTST(&addedmap, i))
- possible++;
- }
- POOL_DEBUG(SAT_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
+ if (why == 0 && pp < 0)
+ return SOLVER_REASON_CLEANDEPS_ERASE;
+ return SOLVER_REASON_UPDATE_INSTALLED;
}
-
- /*
- * first pass done, we now have all the rpm rules we need.
- * unify existing rules before going over all job rules and
- * policy rules.
- * at this point the system is always solvable,
- * as an empty system (remove all packages) is a valid solution
- */
-
- unifyrules(solv); /* remove duplicate rpm rules */
-
- solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
-
- solv->directdecisions = solv->decisionq.count;
- POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
-
- /*
- * create feature rules
- *
- * foreach installed:
- * create assertion (keep installed, if no update available)
- * or
- * create update rule (A|update1(A)|update2(A)|...)
- *
- * those are used later on to keep a version of the installed packages in
- * best effort mode
- */
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
- solv->featurerules = solv->nrules; /* mark start of feature rules */
- if (installed)
+ if (i < solv->decisioncnt_resolve)
{
- /* foreach possibly installed solvable */
- for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
- {
- if (s->repo != installed)
- {
- addrule(solv, 0, 0); /* create dummy rule */
- continue;
- }
-#if CODE10
- if (s->freshens && !s->supplements)
- {
- const char *name = id2str(pool, s->name);
- if (name[0] == 'a' && !strncmp(name, "atom:", 5))
- {
- addrule(solv, 0, 0);
- continue;
- }
- }
-#endif
- addupdaterule(solv, s, 1); /* allow s to be updated */
- }
- /*
- * assert one rule per installed solvable,
- * either an assertion (A)
- * or a possible update (A|update1(A)|update2(A)|...)
- */
- assert(solv->nrules - solv->featurerules == installed->end - installed->start);
+ if (solv->focus_installed && i >= solv->decisioncnt_jobs)
+ return SOLVER_REASON_RESOLVE_JOB;
+ if (why == 0 && pp < 0)
+ return SOLVER_REASON_CLEANDEPS_ERASE;
+ return SOLVER_REASON_KEEP_INSTALLED;
}
- solv->featurerules_end = solv->nrules;
-
- /*
- * Add update rules for installed solvables
- *
- * almost identical to feature rules
- * except that downgrades are allowed
- */
-
- POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
- solv->updaterules = solv->nrules;
+ if (why > 0)
+ return SOLVER_REASON_RESOLVE;
+ /* weak or orphaned */
+ if (i < solv->decisioncnt_orphan)
+ return SOLVER_REASON_WEAKDEP;
+ return SOLVER_REASON_RESOLVE_ORPHAN;
+}
- if (installed)
- { /* foreach installed solvables */
- /* we create all update rules, but disable some later on depending on the job */
- for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
- {
- Rule *sr;
- if (s->repo != installed)
- {
- addrule(solv, 0, 0); /* create dummy rule */
- continue;
- }
+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;
-#if CODE10
- /* no update rules for patch atoms */
- if (s->freshens && !s->supplements)
- {
- const char *name = id2str(pool, s->name);
- if (name[0] == 'a' && !strncmp(name, "atom:", 5))
- {
- addrule(solv, 0, 0);
- continue;
- }
- }
-#endif
- addupdaterule(solv, s, 0); /* allowall = 0: downgrades allowed */
+ 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? */
- /*
- * check for and remove duplicate
- */
-
- r = solv->rules + solv->nrules - 1; /* r: update rule */
- sr = r - (installed->end - installed->start); /* sr: feature rule */
- unifyrules_sortcmp_data = pool;
- if (!unifyrules_sortcmp(r, sr))
+ /* 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)
{
- /* identical rule, kill unneeded rule */
- if (solv->allowuninstall)
- {
- /* keep feature rule */
- memset(r, 0, sizeof(*r));
- queue_push(&solv->weakruleq, sr - solv->rules);
- }
+ if (p2 == p)
+ found = 1;
else
{
- /* keep update rule */
- memset(sr, 0, sizeof(*sr));
+ /* if p2 is already installed, this recommends is ignored */
+ if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
+ break;
}
}
- else if (solv->allowuninstall)
+ if (!p2 && found)
{
- /* make both feature and update rule weak */
- queue_push(&solv->weakruleq, r - solv->rules);
- queue_push(&solv->weakruleq, sr - solv->rules);
+ queue_push(whyq, SOLVER_REASON_RECOMMENDED);
+ queue_push2(whyq, i, rec);
}
- else
- disablerule(solv, sr);
}
- /* consistency check: we added a rule for _every_ installed solvable */
- assert(solv->nrules - solv->updaterules == installed->end - installed->start);
}
- solv->updaterules_end = solv->nrules;
-
-
- /*
- * 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)
+ /* 2) list all supplements */
+ s = pool->solvables + p;
+ if (s->supplements && level > 0)
{
- oldnrules = solv->nrules;
-
- how = job->elements[i] & ~SOLVER_WEAK;
- weak = job->elements[i] & SOLVER_WEAK;
- what = job->elements[i + 1];
- switch(how)
+ 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++ )
{
- case SOLVER_INSTALL_SOLVABLE: /* install specific solvable */
- s = pool->solvables + what;
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
- addrule(solv, what, 0); /* install by Id */
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- break;
- case SOLVER_ERASE_SOLVABLE:
- s = pool->solvables + what;
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase solvable %s\n", weak ? "weak " : "", solvable2str(pool, s));
- addrule(solv, -what, 0); /* remove by Id */
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- break;
- case SOLVER_INSTALL_SOLVABLE_NAME: /* install by capability */
- case SOLVER_INSTALL_SOLVABLE_PROVIDES:
- if (how == SOLVER_INSTALL_SOLVABLE_NAME)
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall name %s\n", weak ? "weak " : "", dep2str(pool, what));
- if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
- queue_empty(&q);
- FOR_PROVIDES(p, pp, what)
- {
- /* if by name, ensure that the name matches */
- if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- queue_push(&q, p);
- }
- if (!q.count)
- {
- /* no provider, make this an impossible rule */
- queue_push(&q, -SYSTEMSOLVABLE);
- }
-
- p = queue_shift(&q); /* get first provider */
- if (!q.count)
- d = 0; /* single provider ? -> make assertion */
- else
- d = pool_queuetowhatprovides(pool, &q); /* get all providers */
- addrule(solv, p, d); /* add 'requires' rule */
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- break;
- case SOLVER_ERASE_SOLVABLE_NAME: /* remove by capability */
- case SOLVER_ERASE_SOLVABLE_PROVIDES:
- if (how == SOLVER_ERASE_SOLVABLE_NAME)
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
- if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
- FOR_PROVIDES(p, pp, what)
- {
- /* if by name, ensure that the name matches */
- if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
- continue;
- addrule(solv, -p, 0); /* add 'remove' rule */
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- }
- break;
- case SOLVER_INSTALL_SOLVABLE_UPDATE: /* find update for solvable */
- s = pool->solvables + what;
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solvable2str(pool, s));
- addupdaterule(solv, s, 0);
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- break;
- case SOLVER_INSTALL_SOLVABLE_ONE_OF:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: %sone of\n", weak ? "weak " : "");
- for (pp = pool->whatprovidesdata + what; *pp; pp++)
- POOL_DEBUG(SAT_DEBUG_JOB, " %s\n", solvable2str(pool, pool->solvables + *pp));
- addrule(solv, -SYSTEMSOLVABLE, what);
- queue_push(&solv->ruletojob, i);
- if (weak)
- queue_push(&solv->weakruleq, solv->nrules - 1);
- break;
- case SOLVER_WEAKEN_SOLVABLE_DEPS:
- s = pool->solvables + what;
- POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
- weaken_solvable_deps(solv, what);
- break;
- case SOLVER_NOOBSOLETES_SOLVABLE:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete %s\n", solvable2str(pool, pool->solvables + what));
- break;
- case SOLVER_NOOBSOLETES_SOLVABLE_NAME:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete name %s\n", dep2str(pool, what));
- break;
- case SOLVER_NOOBSOLETES_SOLVABLE_PROVIDES:
- POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete provides %s\n", dep2str(pool, what));
- break;
+ p2 = solv->decisionq.elements[i];
+ if (p2 > 0)
+ solv->decisionmap[p2] = -solv->decisionmap[p2];
}
-
- /*
- * debug
- */
-
- IF_POOLDEBUG (SAT_DEBUG_JOB)
+ 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++)
{
- int j;
- if (solv->nrules == oldnrules)
- POOL_DEBUG(SAT_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);
- }
+ p2 = solv->decisionq.elements[i];
+ if (p2 > 0)
+ solv->decisionmap[p2] = -solv->decisionmap[p2];
}
}
- assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
- solv->jobrules_end = solv->nrules;
-
- /* all rules created
- * --------------------------------------------------------------
- * prepare for solving
- */
-
- /* free unneeded memory */
- map_free(&addedmap);
- queue_free(&q);
+}
- /* create weak map */
- map_init(&solv->weakrulemap, solv->nrules);
- for (i = 0; i < solv->weakruleq.count; i++)
+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)
{
- p = solv->weakruleq.elements[i];
- MAPSET(&solv->weakrulemap, p);
+ 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);
+ }
+}
- /* all new rules are learnt after this point */
- solv->learntrules = solv->nrules;
-
- /* create assertion index. it is only used to speed up
- * makeruledecsions() a bit */
- for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
- if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
- queue_push(&solv->ruleassertions, i);
-
- /* disable update rules that conflict with our job */
- disableupdaterules(solv, job, -1);
-
- /* make decisions based on job/update assertions */
- makeruledecisions(solv);
+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;
+}
- /* create watches chains */
- makewatches(solv);
+static int
+get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
+{
+ return *(Id *)ap - *(Id *)bp;
+}
- POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
+static int
+get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
+{
+ Pool *pool = dp;
+ return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
+}
- /*
- * ********************************************
- * solve!
- * ********************************************
- */
-
- run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
+static int
+get_userinstalled_cmp_namearch(const void *ap, const void *bp, void *dp)
+{
+ Pool *pool = dp;
+ int r;
+ r = strcmp(pool_id2str(pool, ((Id *)ap)[0]), pool_id2str(pool, ((Id *)bp)[0]));
+ if (r)
+ return r;
+ return strcmp(pool_id2str(pool, ((Id *)ap)[1]), pool_id2str(pool, ((Id *)bp)[1]));
+}
- queue_init(&redoq);
- goterase = 0;
- /* disable all erase jobs (including weak "keep uninstalled" rules) */
- for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
+static void
+get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
+{
+ Id lastp = -1, lasta = -1;
+ int i, j;
+ if (q->count < ((flags & GET_USERINSTALLED_NAMEARCH) ? 4 : 2))
+ return;
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), get_userinstalled_cmp_namearch, pool);
+ else if ((flags & GET_USERINSTALLED_NAMES) != 0)
+ solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
+ else
+ solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
{
- if (r->d < 0) /* disabled ? */
- continue;
- if (r->p > 0) /* install job? */
- continue;
- disablerule(solv, r);
- goterase++;
+ for (i = j = 0; i < q->count; i += 2)
+ if (q->elements[i] != lastp || q->elements[i + 1] != lasta)
+ {
+ q->elements[j++] = lastp = q->elements[i];
+ q->elements[j++] = lasta = q->elements[i + 1];
+ }
}
-
- if (goterase)
+ else
{
- enabledisablelearntrules(solv);
- removedisabledconflicts(solv, &redoq);
+ for (i = j = 0; i < q->count; i++)
+ if (q->elements[i] != lastp)
+ q->elements[j++] = lastp = q->elements[i];
}
+ queue_truncate(q, j);
+}
- /*
- * 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)
+static void
+namearch2solvables(Pool *pool, Queue *q, Queue *qout, int job)
+{
+ int i;
+ if (!pool->installed)
+ return;
+ for (i = 0; i < q->count; i += 2)
{
- Id rec, *recp, p, *pp;
+ Id p, pp, name = q->elements[i], arch = q->elements[i + 1];
+ FOR_PROVIDES(p, pp, name)
+ {
+ Solvable *s = pool->solvables + p;
+ if (s->repo != pool->installed || s->name != name || (arch && s->arch != arch))
+ continue;
+ if (job)
+ queue_push(qout, job);
+ queue_push(qout, p);
+ }
+ }
+}
- /* create map of all recommened packages */
- solv->recommends_index = -1;
- MAPZERO(&solv->recommendsmap);
- for (i = 0; i < solv->decisionq.count; i++)
+void
+solver_get_userinstalled(Solver *solv, Queue *q, int flags)
+{
+ Pool *pool = solv->pool;
+ Id p, p2, pp;
+ Solvable *s;
+ Repo *installed = solv->installed;
+ int i, j;
+ Map userinstalled;
+
+ map_init(&userinstalled, 0);
+ queue_empty(q);
+ /* first process jobs */
+ for (i = 0; i < solv->job.count; i += 2)
+ {
+ Id how = solv->job.elements[i];
+ Id what, select;
+ if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
+ {
+ if (!userinstalled.size)
+ map_grow(&userinstalled, installed->end - installed->start);
+ what = solv->job.elements[i + 1];
+ select = how & SOLVER_SELECTMASK;
+ if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
+ FOR_REPO_SOLVABLES(installed, p, s)
+ MAPSET(&userinstalled, p - installed->start);
+ FOR_JOB_SELECT(p, pp, select, what)
+ if (pool->solvables[p].repo == installed)
+ MAPSET(&userinstalled, p - installed->start);
+ continue;
+ }
+ if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
+ continue;
+ if ((how & SOLVER_NOTBYUSER) != 0)
+ continue;
+ what = solv->job.elements[i + 1];
+ select = how & SOLVER_SELECTMASK;
+ FOR_JOB_SELECT(p, pp, select, what)
+ if (solv->decisionmap[p] > 0)
+ {
+ queue_push(q, p);
+#ifdef ENABLE_LINKED_PKGS
+ if (has_package_link(pool, pool->solvables + p))
+ {
+ int j;
+ Queue lq;
+ queue_init(&lq);
+ find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
+ for (j = 0; j < lq.count; j++)
+ if (solv->decisionmap[lq.elements[j]] > 0)
+ queue_push(q, lq.elements[j]);
+ }
+#endif
+ }
+ }
+ /* now process updates of userinstalled packages */
+ if (installed && userinstalled.size)
+ {
+ for (i = 1; i < solv->decisionq.count; i++)
{
p = solv->decisionq.elements[i];
- if (p < 0)
+ if (p <= 0)
continue;
s = pool->solvables + p;
- if (s->recommends)
+ if (!s->repo)
+ continue;
+ if (s->repo == installed)
{
- 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);
- }
+ if (MAPTST(&userinstalled, p - installed->start))
+ queue_push(q, p);
+ continue;
}
- }
- for (i = 1; i < pool->nsolvables; i++)
- {
- if (solv->decisionmap[i] < 0)
- continue;
- if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
- continue;
- s = pool->solvables + i;
- if (!MAPTST(&solv->recommendsmap, i))
+ /* new package, check if we replace a userinstalled one */
+ FOR_PROVIDES(p2, pp, s->name)
{
- if (!s->supplements)
+ Solvable *ps = pool->solvables + p2;
+ if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
continue;
- if (!pool_installable(pool, s))
+ if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
continue;
- if (!solver_is_supplementing(solv, s))
+ if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
continue;
+ queue_push(q, p);
+ break;
+ }
+ if (!p2 && s->repo != installed && s->obsoletes)
+ {
+ Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
+ while ((obs = *obsp++) != 0)
+ {
+ FOR_PROVIDES(p2, pp, obs)
+ {
+ Solvable *ps = pool->solvables + p2;
+ if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
+ continue;
+ if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
+ continue;
+ if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
+ continue;
+ queue_push(q, p);
+ break;
+ }
+ if (p2)
+ break;
+ }
}
- 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, 0, POLICY_MODE_SUGGEST);
}
+ map_free(&userinstalled);
- /*
- * find suggested packages
- */
-
- if (1)
+ /* convert to desired output format */
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ {
+ int qcount = q->count;
+ queue_insertn(q, 0, qcount, 0);
+ for (i = j = 0; i < qcount; i++)
+ {
+ s = pool->solvables + q->elements[i + qcount];
+ q->elements[j++] = s->name;
+ q->elements[j++] = s->arch;
+ }
+ }
+ else if ((flags & GET_USERINSTALLED_NAMES) != 0)
{
- Id sug, *sugp, p, *pp;
+ for (i = 0; i < q->count; i++)
+ {
+ s = pool->solvables + q->elements[i];
+ q->elements[i] = s->name;
+ }
+ }
+ /* sort and unify */
+ get_userinstalled_sort_uniq(pool, q, flags);
- /* create map of all suggests that are still open */
- solv->recommends_index = -1;
- MAPZERO(&solv->suggestsmap);
- for (i = 0; i < solv->decisionq.count; i++)
+ /* invert if asked for */
+ if ((flags & GET_USERINSTALLED_INVERTED) != 0)
+ {
+ /* first generate queue with all installed packages */
+ Queue invq;
+ queue_init(&invq);
+ for (i = 1; i < solv->decisionq.count; i++)
{
p = solv->decisionq.elements[i];
- if (p < 0)
+ if (p <= 0)
continue;
s = pool->solvables + p;
- if (s->suggests)
+ if (!s->repo)
+ continue;
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ queue_push2(&invq, s->name, s->arch);
+ else if ((flags & GET_USERINSTALLED_NAMES) != 0)
+ queue_push(&invq, s->name);
+ else
+ queue_push(&invq, p);
+ }
+ /* push q on invq, just in case... */
+ queue_insertn(&invq, invq.count, q->count, q->elements);
+ get_userinstalled_sort_uniq(pool, &invq, flags);
+ /* subtract queues (easy as they are sorted and invq is a superset of q) */
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ {
+ if (q->count)
{
- sugp = s->repo->idarraydata + s->suggests;
- while ((sug = *sugp++) != 0)
- {
- FOR_PROVIDES(p, pp, sug)
- if (solv->decisionmap[p] > 0)
+ for (i = j = 0; i < invq.count; i += 2)
+ if (invq.elements[i] == q->elements[j] && invq.elements[i + 1] == q->elements[j + 1])
+ {
+ invq.elements[i] = invq.elements[i + 1] = 0;
+ j += 2;
+ if (j >= q->count)
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);
- }
+ }
+ queue_empty(q);
}
+ for (i = 0; i < invq.count; i += 2)
+ if (invq.elements[i])
+ queue_push2(q, invq.elements[i], invq.elements[i + 1]);
}
- for (i = 1; i < pool->nsolvables; i++)
+ else
{
- if (solv->decisionmap[i] < 0)
- continue;
- if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
- continue;
- s = pool->solvables + i;
- if (!MAPTST(&solv->suggestsmap, i))
+ if (q->count)
{
- if (!s->enhances)
- continue;
- if (!pool_installable(pool, s))
- continue;
- if (!solver_is_enhancing(solv, s))
- continue;
+ for (i = j = 0; i < invq.count; i++)
+ if (invq.elements[i] == q->elements[j])
+ {
+ invq.elements[i] = 0;
+ if (++j >= q->count)
+ break;
+ }
+ queue_empty(q);
}
- queue_push(&solv->suggestions, i);
+ for (i = 0; i < invq.count; i++)
+ if (invq.elements[i])
+ queue_push(q, invq.elements[i]);
}
- policy_filter_unwanted(solv, &solv->suggestions, 0, POLICY_MODE_SUGGEST);
- }
-
- if (redoq.count)
- {
- /* restore decisionmap */
- for (i = 0; i < redoq.count; i += 2)
- solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
+ queue_free(&invq);
}
+}
- /*
- * if unsolvable, prepare solutions
- */
+void
+pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
+{
+ int i;
- if (solv->problems.count)
+ if ((flags & GET_USERINSTALLED_INVERTED) != 0)
{
- int recocount = solv->recommendations.count;
- solv->recommendations.count = 0; /* so that revert() doesn't mess with it */
- queue_empty(&redoq);
- for (i = 0; i < solv->decisionq.count; i++)
+ Queue invq;
+ Id p, lastid;
+ Solvable *s;
+ int bad;
+ if (!pool->installed)
+ return;
+ queue_init(&invq);
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ flags &= ~GET_USERINSTALLED_NAMES; /* just in case */
+ FOR_REPO_SOLVABLES(pool->installed, p, s)
+ queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
+ if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+ {
+ /* for namearch we convert to packages */
+ namearch2solvables(pool, q, &invq, 0);
+ get_userinstalled_sort_uniq(pool, &invq, flags);
+ namearch2solvables(pool, q, &invq, 0);
+ flags = 0;
+ }
+ else
+ {
+ queue_insertn(&invq, invq.count, q->count, q->elements);
+ get_userinstalled_sort_uniq(pool, &invq, flags);
+ /* now the fun part, add q again, sort, and remove all dups */
+ queue_insertn(&invq, invq.count, q->count, q->elements);
+ }
+ if (invq.count > 1)
+ {
+ if ((flags & GET_USERINSTALLED_NAMES) != 0)
+ solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
+ else
+ solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
+ }
+ lastid = -1;
+ bad = 1;
+ for (i = 0; i < invq.count; i++)
{
- Id p = solv->decisionq.elements[i];
- queue_push(&redoq, p);
- queue_push(&redoq, solv->decisionq_why.elements[i]);
- queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
+ if (invq.elements[i] == lastid)
+ {
+ bad = 1;
+ continue;
+ }
+ if (!bad)
+ queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
+ bad = 0;
+ lastid = invq.elements[i];
}
- problems_to_solutions(solv, job);
- memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
- queue_empty(&solv->decisionq);
- queue_empty(&solv->decisionq_why);
- for (i = 0; i < redoq.count; i += 3)
+ if (!bad)
+ queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
+ queue_free(&invq);
+ }
+ else
+ {
+ if (flags & GET_USERINSTALLED_NAMEARCH)
+ namearch2solvables(pool, q, job, SOLVER_USERINSTALLED | SOLVER_SOLVABLE);
+ else
{
- Id p = redoq.elements[i];
- queue_push(&solv->decisionq, p);
- queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
- solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
+ for (i = 0; i < q->count; i++)
+ queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
}
- solv->recommendations.count = recocount;
}
-
- POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
- queue_free(&redoq);
}
-/***********************************************************************/
-/* disk usage computations */
-
-/*-------------------------------------------------------------------
- *
- * calculate DU changes
- */
+int
+solver_alternatives_count(Solver *solv)
+{
+ Id *elements = solv->branches.elements;
+ int res, count;
+ for (res = 0, count = solv->branches.count; count; res++)
+ count -= elements[count - 2];
+ return res;
+}
-void
-solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
+int
+solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
{
- Map installedmap;
+ int cnt = solver_alternatives_count(solv);
+ int count = solv->branches.count;
+ Id *elements = solv->branches.elements;
+ if (choices)
+ queue_empty(choices);
+ if (alternative <= 0 || alternative > cnt)
+ return 0;
+ elements += count;
+ for (; cnt > alternative; cnt--)
+ elements -= elements[-2];
+ if (levelp)
+ *levelp = elements[-1];
+ if (fromp)
+ *fromp = elements[-4];
+ if (idp)
+ *idp = elements[-3];
+ if (chosenp)
+ {
+ int i;
+ *chosenp = 0;
+ for (i = elements[-2]; i > 4; i--)
+ {
+ Id p = -elements[-i];
+ if (p > 0 && solv->decisionmap[p] == elements[-1] + 1)
+ {
+ *chosenp = p;
+ break;
+ }
+ }
+ }
+ if (choices)
+ queue_insertn(choices, 0, elements[-2] - 4, elements - elements[-2]);
+ return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE;
+}
- solver_create_state_maps(solv, &installedmap, 0);
- pool_calc_duchanges(solv->pool, solv->installed, &installedmap, mps, nmps);
- map_free(&installedmap);
+const char *
+solver_select2str(Pool *pool, Id select, Id what)
+{
+ const char *s;
+ char *b;
+ select &= SOLVER_SELECTMASK;
+ if (select == SOLVER_SOLVABLE)
+ return pool_solvid2str(pool, what);
+ if (select == SOLVER_SOLVABLE_NAME)
+ return pool_dep2str(pool, what);
+ if (select == SOLVER_SOLVABLE_PROVIDES)
+ {
+ s = pool_dep2str(pool, what);
+ b = pool_alloctmpspace(pool, 11 + strlen(s));
+ sprintf(b, "providing %s", s);
+ return b;
+ }
+ if (select == SOLVER_SOLVABLE_ONE_OF)
+ {
+ Id p;
+ b = 0;
+ while ((p = pool->whatprovidesdata[what++]) != 0)
+ {
+ s = pool_solvid2str(pool, p);
+ if (b)
+ b = pool_tmpappend(pool, b, ", ", s);
+ else
+ b = pool_tmpjoin(pool, s, 0, 0);
+ pool_freetmpspace(pool, s);
+ }
+ return b ? b : "nothing";
+ }
+ if (select == SOLVER_SOLVABLE_REPO)
+ {
+ b = pool_alloctmpspace(pool, 20);
+ sprintf(b, "repo #%d", what);
+ return b;
+ }
+ if (select == SOLVER_SOLVABLE_ALL)
+ return "all packages";
+ return "unknown job select";
}
+const char *
+pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
+{
+ Id select = how & SOLVER_SELECTMASK;
+ const char *strstart = 0, *strend = 0;
+ char *s;
+ int o;
-/*-------------------------------------------------------------------
- *
- * calculate changes in install size
- */
+ switch (how & SOLVER_JOBMASK)
+ {
+ case SOLVER_NOOP:
+ return "do nothing";
+ case SOLVER_INSTALL:
+ if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
+ strstart = "keep ", strend = " installed";
+ else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
+ strstart = "install ";
+ else if (select == SOLVER_SOLVABLE_PROVIDES)
+ strstart = "install a package ";
+ else
+ strstart = "install one of ";
+ break;
+ case SOLVER_ERASE:
+ if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
+ strstart = "keep ", strend = " uninstalled";
+ else if (select == SOLVER_SOLVABLE_PROVIDES)
+ strstart = "deinstall all packages ";
+ else
+ strstart = "deinstall ";
+ break;
+ case SOLVER_UPDATE:
+ strstart = "update ";
+ break;
+ case SOLVER_WEAKENDEPS:
+ strstart = "weaken deps of ";
+ break;
+ case SOLVER_MULTIVERSION:
+ strstart = "multi version ";
+ break;
+ case SOLVER_LOCK:
+ strstart = "lock ";
+ break;
+ case SOLVER_DISTUPGRADE:
+ strstart = "dist upgrade ";
+ break;
+ case SOLVER_VERIFY:
+ strstart = "verify ";
+ break;
+ case SOLVER_DROP_ORPHANED:
+ strstart = "deinstall ", strend = " if orphaned";
+ break;
+ case SOLVER_USERINSTALLED:
+ strstart = "regard ", strend = " as userinstalled";
+ break;
+ default:
+ strstart = "unknown job ";
+ break;
+ }
+ s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
+ how &= flagmask;
+ if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
+ return s;
+ o = strlen(s);
+ s = pool_tmpappend(pool, s, " ", 0);
+ if (how & SOLVER_WEAK)
+ s = pool_tmpappend(pool, s, ",weak", 0);
+ if (how & SOLVER_ESSENTIAL)
+ s = pool_tmpappend(pool, s, ",essential", 0);
+ if (how & SOLVER_CLEANDEPS)
+ s = pool_tmpappend(pool, s, ",cleandeps", 0);
+ if (how & SOLVER_ORUPDATE)
+ s = pool_tmpappend(pool, s, ",orupdate", 0);
+ if (how & SOLVER_FORCEBEST)
+ s = pool_tmpappend(pool, s, ",forcebest", 0);
+ if (how & SOLVER_TARGETED)
+ s = pool_tmpappend(pool, s, ",targeted", 0);
+ if (how & SOLVER_SETEV)
+ s = pool_tmpappend(pool, s, ",setev", 0);
+ if (how & SOLVER_SETEVR)
+ s = pool_tmpappend(pool, s, ",setevr", 0);
+ if (how & SOLVER_SETARCH)
+ s = pool_tmpappend(pool, s, ",setarch", 0);
+ if (how & SOLVER_SETVENDOR)
+ s = pool_tmpappend(pool, s, ",setvendor", 0);
+ if (how & SOLVER_SETREPO)
+ s = pool_tmpappend(pool, s, ",setrepo", 0);
+ if (how & SOLVER_SETNAME)
+ s = pool_tmpappend(pool, s, ",setname", 0);
+ if (how & SOLVER_NOAUTOSET)
+ s = pool_tmpappend(pool, s, ",noautoset", 0);
+ if (s[o + 1] != ',')
+ s = pool_tmpappend(pool, s, ",?", 0);
+ s[o + 1] = '[';
+ return pool_tmpappend(pool, s, "]", 0);
+}
-int
-solver_calc_installsizechange(Solver *solv)
+const char *
+solver_alternative2str(Solver *solv, int type, Id id, Id from)
{
- Map installedmap;
- int change;
-
- solver_create_state_maps(solv, &installedmap, 0);
- change = pool_calc_installsizechange(solv->pool, solv->installed, &installedmap);
- map_free(&installedmap);
- return change;
+ Pool *pool = solv->pool;
+ if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
+ {
+ const char *s = pool_dep2str(pool, id);
+ return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from));
+ }
+ if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
+ {
+ int rtype;
+ Id depfrom, depto, dep;
+ char buf[64];
+ if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
+ id = solver_rule2pkgrule(solv, id);
+ rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
+ if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
+ {
+ if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES)
+ return pool_dep2str(pool, dep);
+ return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep);
+ }
+ if (rtype == SOLVER_RULE_PKG_REQUIRES)
+ {
+ const char *s = pool_dep2str(pool, dep);
+ return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom));
+ }
+ sprintf(buf, "Rule #%d", id);
+ return pool_tmpjoin(pool, buf, 0, 0);
+ }
+ return "unknown alternative type";
}
-/* EOF */