diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 45dc11c..c58dd6f 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -416,6 +416,7 @@ PKGCONF_API void pkgconf_tuple_define_global(pkgconf_client_t *client, const cha /* queue.c */ PKGCONF_API void pkgconf_queue_push(pkgconf_list_t *list, const char *package); +PKGCONF_API void pkgconf_queue_push_dependency(pkgconf_list_t *list, const pkgconf_dependency_t *dep); PKGCONF_API bool pkgconf_queue_compile(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list); PKGCONF_API bool pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth); PKGCONF_API void pkgconf_queue_free(pkgconf_list_t *list); diff --git a/libpkgconf/queue.c b/libpkgconf/queue.c index 09c02e3..2615761 100644 --- a/libpkgconf/queue.c +++ b/libpkgconf/queue.c @@ -29,6 +29,32 @@ * Using the `queue` module functions is the recommended way of working with dependency graphs. */ +/* + * !doc + * + * .. c:function:: void pkgconf_queue_push_dependency(pkgconf_list_t *list, const pkgconf_dependency_t *dep) + * + * Pushes a requested dependency onto the dependency resolver's queue which is described by + * a pkgconf_dependency_t node. + * + * :param pkgconf_list_t* list: the dependency resolution queue to add the package request to. + * :param pkgconf_dependency_t* dep: the dependency requested + * :return: nothing + */ +void +pkgconf_queue_push_dependency(pkgconf_list_t *list, const pkgconf_dependency_t *dep) +{ + pkgconf_buffer_t depbuf = PKGCONF_BUFFER_INITIALIZER; + pkgconf_queue_t *pkgq = calloc(1, sizeof(pkgconf_queue_t)); + + pkgconf_buffer_append(&depbuf, dep->package); + if (dep->version != NULL) + pkgconf_buffer_append_fmt(&depbuf, " %s %s", pkgconf_pkg_get_comparator(dep), dep->version); + + pkgq->package = pkgconf_buffer_freeze(&depbuf); + pkgconf_node_insert_tail(&pkgq->iter, pkgq, list); +} + /* * !doc *