2012-07-29 08:49:56 +00:00
|
|
|
/*
|
|
|
|
* queue.c
|
|
|
|
* compilation of a list of packages into a world dependency set
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 pkgconf authors (see AUTHORS).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2012-07-29 08:49:56 +00:00
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* libpkgconf `queue` module
|
|
|
|
* =========================
|
|
|
|
*
|
|
|
|
* The `queue` module provides an interface that allows easily building a dependency graph from an
|
|
|
|
* arbitrary set of dependencies. It also provides support for doing "preflight" checks on the entire
|
|
|
|
* dependency graph prior to working with it.
|
|
|
|
*
|
|
|
|
* Using the `queue` module functions is the recommended way of working with dependency graphs.
|
|
|
|
*/
|
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
typedef struct {
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t iter;
|
2013-03-01 16:24:57 +00:00
|
|
|
char *package;
|
2015-09-06 15:51:34 +00:00
|
|
|
} pkgconf_queue_t;
|
2013-03-01 16:24:57 +00:00
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_queue_push(pkgconf_list_t *list, const char *package)
|
|
|
|
*
|
|
|
|
* Pushes a requested dependency onto the dependency resolver's queue.
|
|
|
|
*
|
|
|
|
* :param pkgconf_list_t* list: the dependency resolution queue to add the package request to.
|
|
|
|
* :param char* package: the dependency atom requested
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2013-03-01 16:24:57 +00:00
|
|
|
void
|
2015-09-06 15:51:34 +00:00
|
|
|
pkgconf_queue_push(pkgconf_list_t *list, const char *package)
|
2012-07-29 08:49:56 +00:00
|
|
|
{
|
2015-09-06 15:51:34 +00:00
|
|
|
pkgconf_queue_t *pkgq = calloc(sizeof(pkgconf_queue_t), 1);
|
2012-07-29 08:49:56 +00:00
|
|
|
|
|
|
|
pkgq->package = strdup(package);
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert_tail(&pkgq->iter, pkgq, list);
|
2012-07-29 08:49:56 +00:00
|
|
|
}
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: bool pkgconf_queue_compile(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list)
|
|
|
|
*
|
|
|
|
* Compile a dependency resolution queue into a dependency resolution problem if possible, otherwise report an error.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_pkg_t* world: The designated root of the dependency graph.
|
|
|
|
* :param pkgconf_list_t* list: The list of dependency requests to consider.
|
|
|
|
* :return: true if the built dependency resolution problem is consistent, else false
|
|
|
|
* :rtype: bool
|
|
|
|
*/
|
2012-07-29 08:56:20 +00:00
|
|
|
bool
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_queue_compile(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *iter;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(list->head, iter)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2015-09-06 15:51:34 +00:00
|
|
|
pkgconf_queue_t *pkgq;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
pkgq = iter->data;
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_dependency_parse(client, world, &world->requires, pkgq->package);
|
2012-07-29 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
return (world->requires.head != NULL);
|
2012-07-29 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_queue_free(pkgconf_list_t *list)
|
|
|
|
*
|
|
|
|
* Release any memory related to a dependency resolution queue.
|
|
|
|
*
|
|
|
|
* :param pkgconf_list_t* list: The dependency resolution queue to release.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-07-29 08:56:20 +00:00
|
|
|
void
|
2015-09-06 15:51:34 +00:00
|
|
|
pkgconf_queue_free(pkgconf_list_t *list)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node, *tnode;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, tnode, node)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2015-09-06 15:51:34 +00:00
|
|
|
pkgconf_queue_t *pkgq = node->data;
|
2013-03-01 16:24:57 +00:00
|
|
|
|
2012-07-29 08:56:20 +00:00
|
|
|
free(pkgq->package);
|
|
|
|
free(pkgq);
|
|
|
|
}
|
|
|
|
}
|
2012-07-29 09:45:21 +00:00
|
|
|
|
2012-07-29 10:36:21 +00:00
|
|
|
static inline unsigned int
|
2017-01-19 23:32:38 +00:00
|
|
|
pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list, int maxdepth)
|
2012-07-29 10:36:21 +00:00
|
|
|
{
|
2016-12-01 21:05:03 +00:00
|
|
|
if (!pkgconf_queue_compile(client, world, list))
|
2015-09-06 16:45:00 +00:00
|
|
|
return PKGCONF_PKG_ERRF_DEPGRAPH_BREAK;
|
2012-07-29 10:36:21 +00:00
|
|
|
|
2017-01-19 23:32:38 +00:00
|
|
|
return pkgconf_pkg_verify_graph(client, world, maxdepth, client->flags);
|
2012-07-29 10:36:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2017-01-19 23:32:38 +00:00
|
|
|
* .. c:function:: void pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data)
|
2016-12-11 05:27:21 +00:00
|
|
|
*
|
|
|
|
* Attempt to compile a dependency resolution queue into a dependency resolution problem, then attempt to solve the problem and
|
|
|
|
* feed the solution to a callback function if a complete dependency graph is found.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_list_t* list: The list of dependency requests to consider.
|
|
|
|
* :param pkgconf_queue_apply_func_t func: The callback function to call if a solution is found by the dependency resolver.
|
|
|
|
* :param int maxdepth: The maximum allowed depth for the dependency resolver. A depth of -1 means unlimited.
|
|
|
|
* :param void* data: An opaque pointer which is passed to the callback function.
|
|
|
|
* :returns: true if the dependency resolver found a solution, otherwise false.
|
|
|
|
* :rtype: bool
|
|
|
|
*/
|
2012-07-29 09:45:21 +00:00
|
|
|
bool
|
2017-01-19 23:32:38 +00:00
|
|
|
pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data)
|
2012-07-29 09:45:21 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t world = {
|
2016-05-20 07:06:46 +00:00
|
|
|
.id = "virtual:world",
|
2012-07-29 09:45:21 +00:00
|
|
|
.realname = "virtual world package",
|
2015-09-06 16:37:20 +00:00
|
|
|
.flags = PKGCONF_PKG_PROPF_VIRTUAL,
|
2012-07-29 09:45:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
|
|
|
|
if (!maxdepth)
|
|
|
|
maxdepth = -1;
|
|
|
|
|
2017-01-19 23:32:38 +00:00
|
|
|
if (pkgconf_queue_verify(client, &world, list, maxdepth) != PKGCONF_PKG_ERRF_OK)
|
2012-07-29 09:45:21 +00:00
|
|
|
return false;
|
|
|
|
|
2017-01-19 23:32:38 +00:00
|
|
|
if (!func(client, &world, data, maxdepth))
|
2012-08-12 10:32:31 +00:00
|
|
|
{
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_free(client, &world);
|
2012-08-12 10:32:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-29 09:45:21 +00:00
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_free(client, &world);
|
2012-07-29 09:45:21 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-29 10:36:21 +00:00
|
|
|
|
2016-12-11 05:27:21 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2017-01-19 23:32:38 +00:00
|
|
|
* .. c:function:: void pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data)
|
2016-12-11 05:27:21 +00:00
|
|
|
*
|
|
|
|
* Attempt to compile a dependency resolution queue into a dependency resolution problem, then attempt to solve the problem.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_list_t* list: The list of dependency requests to consider.
|
|
|
|
* :param int maxdepth: The maximum allowed depth for the dependency resolver. A depth of -1 means unlimited.
|
|
|
|
* :returns: true if the dependency resolver found a solution, otherwise false.
|
|
|
|
* :rtype: bool
|
|
|
|
*/
|
2012-07-29 10:36:21 +00:00
|
|
|
bool
|
2017-01-19 23:32:38 +00:00
|
|
|
pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth)
|
2012-07-29 10:36:21 +00:00
|
|
|
{
|
|
|
|
bool retval = true;
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t world = {
|
2016-05-20 07:06:46 +00:00
|
|
|
.id = "virtual:world",
|
2012-07-29 10:36:21 +00:00
|
|
|
.realname = "virtual world package",
|
2015-09-06 16:37:20 +00:00
|
|
|
.flags = PKGCONF_PKG_PROPF_VIRTUAL,
|
2012-07-29 10:36:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
|
|
|
|
if (!maxdepth)
|
|
|
|
maxdepth = -1;
|
|
|
|
|
2017-01-19 23:32:38 +00:00
|
|
|
if (pkgconf_queue_verify(client, &world, list, maxdepth) != PKGCONF_PKG_ERRF_OK)
|
2012-07-29 10:36:21 +00:00
|
|
|
retval = false;
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_free(client, &world);
|
2012-07-29 10:36:21 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|