From 5b10a85a82c7b9724eccc015e53f527afbdb1e52 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 8 Aug 2022 09:08:27 +0000 Subject: [PATCH] queue: add pkgconf_queue_solve API --- libpkgconf/libpkgconf.h | 1 + libpkgconf/queue.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 15cf88f..d198828 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -377,6 +377,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 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); PKGCONF_API bool pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data); PKGCONF_API bool pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth); diff --git a/libpkgconf/queue.c b/libpkgconf/queue.c index fe556c5..b97b9dc 100644 --- a/libpkgconf/queue.c +++ b/libpkgconf/queue.c @@ -252,6 +252,30 @@ pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_lis return PKGCONF_PKG_ERRF_OK; } +/* + * !doc + * + * .. c:function:: bool pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth) + * + * Solves and flattens the dependency graph for the supplied dependency list. + * + * :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_pkg_t* world: The root for the generated dependency graph, provided by the caller. Should have PKGCONF_PKG_PKGF_VIRTUAL flag. + * :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 + */ +bool +pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth) +{ + /* if maxdepth is one, then we will not traverse deeper than our virtual package. */ + if (!maxdepth) + maxdepth = -1; + + return pkgconf_queue_verify(client, world, list, maxdepth) == PKGCONF_PKG_ERRF_OK; +} + /* * !doc * @@ -260,6 +284,8 @@ pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_lis * 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. * + * This function should not be used in new code. Use pkgconf_queue_solve instead. + * * :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. @@ -282,7 +308,7 @@ pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queu if (!maxdepth) maxdepth = -1; - if (pkgconf_queue_verify(client, &world, list, maxdepth) != PKGCONF_PKG_ERRF_OK) + if (!pkgconf_queue_solve(client, list, &world, maxdepth)) goto cleanup; /* the world dependency set is flattened after it is returned from pkgconf_queue_verify */