summaryrefslogtreecommitdiff
path: root/src/solver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/solver.c')
-rw-r--r--src/solver.c356
1 files changed, 224 insertions, 132 deletions
diff --git a/src/solver.c b/src/solver.c
index 14fe78d..46d0ca3 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -44,16 +44,34 @@
* 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;
Reldep *rd;
Solvable *s;
- if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
+ if (!solv->dosplitprovides || !solv->installed)
return 0;
if (!ISRELDEP(dep))
return 0;
@@ -76,8 +94,10 @@ solver_splitprovides(Solver *solv, Id dep)
/* here we have packages that provide the correct name and contain the path,
* now do extra filtering */
s = pool->solvables + p;
- if (s->repo == solv->installed && s->name == rd->name &&
- (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
+ 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;
@@ -147,7 +167,7 @@ solver_check_installsuppdepq_dep(Solver *solv, Id dep)
return r1 == 2 || r2 == 2 ? 2 : 1;
}
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
- return solver_splitprovides(solv, rd->evr);
+ return solver_splitprovides(solv, rd->evr, 0);
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
return solver_dep_installed(solv, rd->evr);
if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
@@ -1243,13 +1263,7 @@ revert(Solver *solv, int level)
solv->propagate_index = solv->decisionq.count;
}
while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
- {
- solv->branches.count--;
- while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
- solv->branches.count--;
- while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] < 0)
- solv->branches.count--;
- }
+ 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)
@@ -1379,6 +1393,7 @@ 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;
@@ -1390,25 +1405,34 @@ reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
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++)
- if (!solver_is_enhancing(solv, pool->solvables + dq->elements[i]))
- {
- queue_push(dq, dq->elements[i]);
- dq->elements[i] = 0;
- }
+ {
+ 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++)
- if (dq->elements[i] && !solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
- {
- queue_push(dq, dq->elements[i]);
- dq->elements[i] = 0;
- }
+ {
+ 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];
@@ -1416,6 +1440,62 @@ reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
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);
+}
+
+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);
}
/*-------------------------------------------------------------------
@@ -1434,40 +1514,18 @@ selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid
{
Pool *pool = solv->pool;
Id p;
- int i;
if (dq->count > 1)
policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
- if (dq->count > 1)
- {
- /* XXX: didn't we already do that? */
- /* XXX: shouldn't we prefer installed packages? */
- /* XXX: move to policy.c? */
- /* choose the supplemented one */
- for (i = 0; i < dq->count; i++)
- if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
- {
- dq->elements[0] = dq->elements[i];
- dq->count = 1;
- break;
- }
- }
/* 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)
- {
- /* multiple candidates, open a branch */
- queue_push(&solv->branches, -dq->elements[0]);
- for (i = 1; i < dq->count; i++)
- queue_push(&solv->branches, dq->elements[i]);
- queue_push(&solv->branches, level);
- }
+ 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);
}
@@ -2528,7 +2586,6 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
/* filter out all already supplemented packages if requested */
if (!solv->addalreadyrecommended && dqs.count)
{
- int dosplitprovides_old = solv->dosplitprovides;
/* turn off all new packages */
for (i = 0; i < solv->decisionq.count; i++)
{
@@ -2539,7 +2596,6 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
if (s->repo && s->repo != solv->installed)
solv->decisionmap[p] = -solv->decisionmap[p];
}
- solv->dosplitprovides = 0;
/* filter out old supplements */
for (i = j = 0; i < dqs.count; i++)
{
@@ -2563,7 +2619,6 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
if (s->repo && s->repo != solv->installed)
solv->decisionmap[p] = -solv->decisionmap[p];
}
- solv->dosplitprovides = dosplitprovides_old;
}
/* multiversion doesn't mix well with supplements.
@@ -2679,13 +2734,10 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
if (!dq.count)
continue;
if (dq.count > 1)
- {
- /* multiple candidates, open a branch */
- queue_push(&solv->branches, -dq.elements[0]);
- for (i = 1; i < dq.count; i++)
- queue_push(&solv->branches, dq.elements[i]);
- queue_push(&solv->branches, level);
- }
+ 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;
@@ -2812,7 +2864,6 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
if (solv->branches.count)
{
int l, endi = 0;
- Id why;
p = l = 0;
for (i = solv->branches.count - 1; i >= 0; i--)
{
@@ -2821,6 +2872,7 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
{
endi = i + 1;
l = p;
+ i -= 3; /* skip: p data count */
}
else if (p > 0)
break;
@@ -2831,21 +2883,7 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
{
while (i > 0 && solv->branches.elements[i - 1] > 0)
i--;
- p = solv->branches.elements[i];
- solv->branches.elements[i] = -p;
- while (i > 0 && solv->branches.elements[i - 1] < 0)
- i--;
- POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
- queue_empty(&dq);
- queue_insertn(&dq, 0, endi - i, solv->branches.elements + i);
- level = l;
- revert(solv, level);
- queue_insertn(&solv->branches, solv->branches.count, dq.count, dq.elements);
- /* 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);
- olevel = level;
- level = setpropagatelearn(solv, level, p, disablerules, why);
+ level = takebranch(solv, i, endi, "branching", disablerules);
if (level == 0)
break;
continue;
@@ -2858,82 +2896,51 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
/* auto-minimization step */
if (solv->branches.count)
{
- int l = 0, lasti = -1, lastsi = -1, endi = 0;
- Id why;
- p = l = 0;
+ int endi, lasti = -1, lastiend = -1;
if (solv->recommends_index < solv->decisionq.count)
policy_update_recommendsmap(solv);
- for (i = solv->branches.count - 1; i >= 0; i--)
+ for (endi = solv->branches.count; endi > 0;)
{
- p = solv->branches.elements[i];
- if (p > 0 && !l)
- {
- l = p;
- endi = i + 1;
- lastsi = -1;
- }
- else if (p > 0)
+ int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
+ l = solv->branches.elements[endi - 1];
+ for (i = starti; i < endi - 4; i++)
{
- if (solv->decisionmap[p] > l + 1)
- lasti = i;
- else
+ p = solv->branches.elements[i];
+ if (p <= 0)
+ continue;
+ if (solv->decisionmap[p] > l)
{
- if (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p))
- {
- lastsi = p;
- }
+ lasti = i;
+ lastiend = endi;
+ lastsi = -1;
+ break;
}
+ if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
+ lastsi = i;
}
- else if (p < 0)
+ if (lastsi >= 0)
{
- l = 0;
- if (lastsi >= 0)
+ /* 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 = -p;
- if (solv->decisionmap[p] == l)
+ 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)))
{
- if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
- lasti = lastsi;
+ lasti = lastsi;
+ lastiend = endi;
+ break;
}
}
}
+ endi = starti;
}
if (lasti >= 0)
{
- int starti;
- /* find start of branch */
- for (i = lasti; i && solv->branches.elements[i] >= 0; )
- i--;
- while (i > 0 && solv->branches.elements[i] < 0)
- i--;
- starti = i ? i + 1 : 0;
-#if 0
- printf("minimization group level %d [%d-%d]:\n", solv->branches.elements[endi - 1], starti, endi);
- for (i = starti; i < endi - 1; i++)
- printf("%c %c%s\n", i == lasti ? 'x' : ' ', solv->branches.elements[i] >= 0 ? ' ' : '-', pool_solvid2str(pool, solv->branches.elements[i] >= 0 ? solv->branches.elements[i] : -solv->branches.elements[i]));
-#endif
- l = solv->branches.elements[endi - 1];
- p = solv->branches.elements[lasti];
- solv->branches.elements[lasti] = -p;
- POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], l, pool_solvid2str(pool, p));
minimizationsteps++;
- queue_empty(&dq);
- for (i = starti; i < endi - 1; i++)
- if (solv->branches.elements[i] < 0)
- queue_push(&dq, solv->branches.elements[i]);
- for (i = starti; i < endi; i++)
- if (solv->branches.elements[i] > 0)
- queue_push(&dq, solv->branches.elements[i]);
- if (dq.elements[dq.count - 2] <= 0)
- queue_empty(&dq);
- level = l;
- revert(solv, level);
- queue_insertn(&solv->branches, solv->branches.count, dq.count, dq.elements);
- /* 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);
- olevel = level;
- level = setpropagatelearn(solv, level, p, disablerules, why);
+ level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
if (level == 0)
break;
continue; /* back to main loop */
@@ -3644,7 +3651,10 @@ solver_solve(Solver *solv, Queue *job)
* add rules for suggests, enhances
*/
oldnrules = solv->nrules;
- solver_addpkgrulesforweak(solv, &addedmap);
+ if (hasdupjob && !solv->updatemap_all && solv->dosplitprovides && solv->installed)
+ solver_addpkgrulesforweak(solv, &addedmap);
+ else
+ solver_addpkgrulesforweak(solv, &addedmap);
POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
#ifdef ENABLE_LINKED_PKGS
@@ -4886,6 +4896,54 @@ pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
}
}
+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;
+}
+
+int
+solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
+{
+ 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;
+}
+
const char *
solver_select2str(Pool *pool, Id select, Id what)
{
@@ -5025,3 +5083,37 @@ pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
return pool_tmpappend(pool, s, "]", 0);
}
+const char *
+solver_alternative2str(Solver *solv, int type, Id id, Id from)
+{
+ 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";
+}
+