Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Human readable description of SAT rules.
Vsevolod Stakhov committed 11 years ago
commit 9dbaabdf6c11c0b31c36907253491ece9615ab7a
parent 11ceca1
1 file changed +95 -14
modified libpkg/pkg_solve.c
@@ -46,6 +46,26 @@

struct pkg_solve_item;

+
enum pkg_solve_rule_type {
+
	PKG_RULE_DEPEND = 0,
+
	PKG_RULE_UPGRADE_CONFLICT,
+
	PKG_RULE_EXPLICIT_CONFLICT,
+
	PKG_RULE_REQUEST_CONFLICT,
+
	PKG_RULE_REQUEST,
+
	PKG_RULE_REQUIRE,
+
	PKG_RULE_MAX
+
};
+

+
static const char *rule_reasons[] = {
+
	[PKG_RULE_DEPEND] = "dependency",
+
	[PKG_RULE_UPGRADE_CONFLICT] = "upgrade",
+
	[PKG_RULE_REQUEST_CONFLICT] = "candidates",
+
	[PKG_RULE_EXPLICIT_CONFLICT] = "conflict",
+
	[PKG_RULE_REQUEST] = "request",
+
	[PKG_RULE_REQUIRE] = "require",
+
	[PKG_RULE_MAX] = NULL
+
};
+

struct pkg_solve_variable {
	struct pkg_job_universe_item *unit;
	bool to_install;
@@ -67,7 +87,7 @@ struct pkg_solve_item {
};

struct pkg_solve_rule {
-
	const char *reason;
+
	enum pkg_solve_rule_type reason;
	struct pkg_solve_item *items;
	struct pkg_solve_rule *next;
};
@@ -120,7 +140,7 @@ pkg_solve_item_new(struct pkg_solve_variable *var)
}

static struct pkg_solve_rule *
-
pkg_solve_rule_new(const char *reason)
+
pkg_solve_rule_new(enum pkg_solve_rule_type reason)
{
	struct pkg_solve_rule *result;

@@ -190,14 +210,75 @@ pkg_solve_problem_free(struct pkg_solve_problem *problem)
static void
pkg_print_rule_sbuf(struct pkg_solve_rule *rule, struct sbuf *sb)
{
-
	struct pkg_solve_item *it;
+
	struct pkg_solve_item *it = rule->items, *key_elt = NULL;
+
	const char *v1, *v2;

-
	sbuf_printf(sb, "%s rule: (", rule->reason);
-
	LL_FOREACH(rule->items, it) {
-
		sbuf_printf(sb, "%s%s%s%s", it->inverse < 0 ? "not " : "", it->var->uid,
-
						(it->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)",
-
										it->next ? " or " : ")");
+
	sbuf_printf(sb, "%s rule: ", rule_reasons[rule->reason]);
+
	switch(rule->reason) {
+
	case PKG_RULE_DEPEND:
+
		LL_FOREACH(rule->items, it) {
+
			if (it->inverse) {
+
				key_elt = it;
+
				break;
+
			}
+
		}
+
		if (key_elt) {
+
			sbuf_printf(sb, "package %s%s depends on: ", key_elt->var->uid,
+
				(key_elt->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)");
+
		}
+
		LL_FOREACH(rule->items, it) {
+
			if (it != key_elt) {
+
				sbuf_printf(sb, "%s%s", it->var->uid,
+
					(it->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)");
+
			}
+
		}
+
		break;
+
	case PKG_RULE_UPGRADE_CONFLICT:
+
		pkg_get(it->next->var->unit->pkg, PKG_VERSION, &v1);
+
		pkg_get(it->var->unit->pkg, PKG_VERSION, &v2);
+
		sbuf_printf(sb, "upgrade local %s-%s to remote %s-%s",
+
			it->next->var->uid, v1, it->var->uid, v2);
+
		break;
+
	case PKG_RULE_EXPLICIT_CONFLICT:
+
		sbuf_printf(sb, "The following packages conflict with each other: ");
+
		LL_FOREACH(rule->items, it) {
+
			pkg_get(it->var->unit->pkg, PKG_VERSION, &v1);
+
			sbuf_printf(sb, "%s-%s%s%s", it->var->uid, v1,
+
				(it->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)",
+
				it->next ? ", " : "");
+
		}
+
		break;
+
	case PKG_RULE_REQUIRE:
+
		LL_FOREACH(rule->items, it) {
+
			if (it->inverse) {
+
				key_elt = it;
+
				break;
+
			}
+
		}
+
		if (key_elt) {
+
			sbuf_printf(sb, "package %s%s depends on shared library provided by: ",
+
				key_elt->var->uid,
+
				(key_elt->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)");
+
		}
+
		LL_FOREACH(rule->items, it) {
+
			if (it != key_elt) {
+
				sbuf_printf(sb, "%s%s", it->var->uid,
+
					(it->var->unit->pkg->type == PKG_INSTALLED) ? "(l)" : "(r)");
+
			}
+
		}
+
		break;
+
	case PKG_RULE_REQUEST_CONFLICT:
+
		sbuf_printf(sb, "The following packages in request are candidates for installation: ");
+
		LL_FOREACH(rule->items, it) {
+
			pkg_get(it->var->unit->pkg, PKG_VERSION, &v1);
+
			sbuf_printf(sb, "%s-%s%s", it->var->uid, v1,
+
					it->next ? ", " : "");
+
		}
+
		break;
+
	default:
+
		break;
	}
+

	sbuf_finish(sb);
}

@@ -272,7 +353,7 @@ pkg_solve_add_depend_rule(struct pkg_solve_problem *problem,
		return (EPKG_END);
	}
	/* Dependency rule: (!A | B) */
-
	rule = pkg_solve_rule_new("dependency");
+
	rule = pkg_solve_rule_new(PKG_RULE_DEPEND);
	if (rule == NULL)
		return (EPKG_FATAL);
	/* !A */
@@ -340,7 +421,7 @@ pkg_solve_add_conflict_rule(struct pkg_solve_problem *problem,
		}

		/* Conflict rule: (!A | !Bx) */
-
		rule = pkg_solve_rule_new("explicit conflict");
+
		rule = pkg_solve_rule_new(PKG_RULE_EXPLICIT_CONFLICT);
		if (rule == NULL)
			return (EPKG_FATAL);
		/* !A */
@@ -378,7 +459,7 @@ pkg_solve_add_require_rule(struct pkg_solve_problem *problem,
	HASH_FIND_STR(problem->j->universe->provides, pkg_shlib_name(shlib), prhead);
	if (prhead != NULL) {
		/* Require rule !A | P1 | P2 | P3 ... */
-
		rule = pkg_solve_rule_new("require");
+
		rule = pkg_solve_rule_new(PKG_RULE_REQUIRE);
		if (rule == NULL)
			return (EPKG_FATAL);
		/* !A */
@@ -462,7 +543,7 @@ pkg_solve_add_request_rule(struct pkg_solve_problem *problem,
	 * Add clause for any of candidates:
	 * A1 | A2 | ... | An
	 */
-
	rule = pkg_solve_rule_new("request");
+
	rule = pkg_solve_rule_new(PKG_RULE_REQUEST);
	if (rule == NULL)
		return (EPKG_FATAL);
	cnt = 0;
@@ -493,7 +574,7 @@ pkg_solve_add_request_rule(struct pkg_solve_problem *problem,
					confvar = pkg_solve_find_var_in_chain(var, confitem->unit);
					assert(confvar != NULL && confvar != curvar && confvar != var);
					/* Conflict rule: (!A | !Bx) */
-
					rule = pkg_solve_rule_new("request conflict");
+
					rule = pkg_solve_rule_new(PKG_RULE_REQUEST_CONFLICT);
					if (rule == NULL)
						return (EPKG_FATAL);
					/* !A */
@@ -539,7 +620,7 @@ pkg_solve_add_chain_rule(struct pkg_solve_problem *problem,

	LL_FOREACH(var->next, curvar) {
		/* Conflict rule: (!Ax | !Ay) */
-
		rule = pkg_solve_rule_new("upgrade chain");
+
		rule = pkg_solve_rule_new(PKG_RULE_UPGRADE_CONFLICT);
		if (rule == NULL)
			return (EPKG_FATAL);
		/* !Ax */