Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add DOT_FILE variable to save dot graph.
Vsevolod Stakhov committed 10 years ago
commit 011f0c7ff5a03652cfc669391144275554c235fb
parent d71e383
4 files changed +34 -4
modified libpkg/pkg.h.in
@@ -1070,6 +1070,11 @@ int pkg_jobs_cudf_parse_output(struct pkg_jobs *j, FILE *f);
int pkg_solve_sat_problem(struct pkg_solve_problem *problem);

/**
+
 * Export SAT problem to a dot graph description
+
 */
+
void pkg_solve_dot_export(struct pkg_solve_problem *problem, FILE *file);
+

+
/**
 * Convert package jobs to a SAT problem
 * @return SAT problem or NULL if failed
 */
modified libpkg/pkg_config.c
@@ -373,6 +373,12 @@ static struct config_entry c[] = {
		"NO",
		"Always cleanup the cache directory after install/upgrade",
	},
+
	{
+
		PKG_STRING,
+
		"DOT_FILE",
+
		NULL,
+
		"Save SAT problem to the specified dot file"
+
	},
};

static bool parsed = false;
modified libpkg/pkg_jobs.c
@@ -1668,8 +1668,8 @@ pkg_jobs_solve(struct pkg_jobs *j)
	int ret, pstatus;
	struct pkg_solve_problem *problem;
	struct pkg_solved *job;
-
	const char *solver;
-
	FILE *spipe[2];
+
	const char *solver, *dotfile;
+
	FILE *spipe[2], *dot = NULL;
	pid_t pchild;

	pkgdb_begin_solver(j->db);
@@ -1729,10 +1729,25 @@ again:
					waitpid(pchild, &pstatus, WNOHANG);
				}
				else {
+
					if ((dotfile = pkg_object_string(pkg_config_get("DOT_FILE")))
+
							!= NULL) {
+
						dot = fopen(dotfile, "w");
+

+
						if (dot == NULL) {
+
							pkg_emit_errno("fopen", dotfile);
+
						}
+
					}
+

					ret = pkg_solve_sat_problem(problem);
					if (ret == EPKG_FATAL) {
						pkg_emit_error("cannot solve job using SAT solver");
						ret = EPKG_FATAL;
+

+
						if (dot) {
+
							pkg_solve_dot_export(problem, dot);
+
							fclose(dot);
+
						}
+

						pkg_solve_problem_free(problem);
						j->solved = 0;
					}
@@ -1742,6 +1757,12 @@ again:
					}
					else {
						ret = pkg_solve_sat_to_jobs(problem);
+

+
						if (dot) {
+
							pkg_solve_dot_export(problem, dot);
+
							fclose(dot);
+
						}
+

						pkg_solve_problem_free(problem);
					}
				}
modified libpkg/pkg_solve.c
@@ -1206,8 +1206,6 @@ void
pkg_solve_dot_export(struct pkg_solve_problem *problem, FILE *file)
{
	struct pkg_solve_rule *rule;
-
	struct pkg_solve_item *it, *key_elt = NULL;
-
	int res, iter = 0;
	size_t i;

	fprintf(file, "digraph {\n");