pkg: pkg_verify_dependency(): add return error flags pointer.

presently, three error flags are defined:

PKG_ERRF_OK: everything went fine (no error)

PKG_ERRF_PACKAGE_NOT_FOUND: a graph node couldn't be verified because there was no
                            database entry for it

PKG_ERRF_PACKAGE_VER_MISMATCH: a graph node couldn't be verified because the entry
                               in the database did not match versioning constraints
pull/15/head
William Pitcock 2012-05-03 17:42:04 +00:00
parent 4dbca6ae18
commit 91ec341a92
3 changed files with 28 additions and 9 deletions

4
main.c
View File

@ -244,7 +244,7 @@ pkg_queue_walk(pkg_queue_t *head)
{ {
pkg_t *pkg; pkg_t *pkg;
pkg = pkg_verify_dependency(iter, global_traverse_flags); pkg = pkg_verify_dependency(iter, global_traverse_flags, NULL);
print_requires(pkg, NULL); print_requires(pkg, NULL);
} }
} }
@ -261,7 +261,7 @@ pkg_queue_walk(pkg_queue_t *head)
{ {
pkg_t *pkg; pkg_t *pkg;
pkg = pkg_verify_dependency(iter, global_traverse_flags | PKGF_SEARCH_PRIVATE); pkg = pkg_verify_dependency(iter, global_traverse_flags | PKGF_SEARCH_PRIVATE, NULL);
print_requires_private(pkg, NULL); print_requires_private(pkg, NULL);
} }
} }

19
pkg.c
View File

@ -244,13 +244,21 @@ pkg_get_comparator(pkg_dependency_t *pkgdep)
* return the appropriate pkg_t object, else NULL. * return the appropriate pkg_t object, else NULL.
*/ */
pkg_t * pkg_t *
pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags) pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags)
{ {
pkg_t *pkg; pkg_t *pkg;
if (eflags != NULL)
*eflags = PKG_ERRF_OK;
pkg = pkg_find(pkgdep->package, flags); pkg = pkg_find(pkgdep->package, flags);
if (pkg == NULL) if (pkg == NULL)
{
if (eflags != NULL)
*eflags |= PKG_ERRF_PACKAGE_NOT_FOUND;
return NULL; return NULL;
}
pkg->id = strdup(pkgdep->package); pkg->id = strdup(pkgdep->package);
@ -285,6 +293,9 @@ pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags)
return pkg; return pkg;
} }
if (eflags != NULL)
*eflags |= PKG_ERRF_PACKAGE_VER_MISMATCH;
return NULL; return NULL;
} }
@ -307,6 +318,7 @@ pkg_walk_list(pkg_dependency_t *deplist,
int maxdepth, int maxdepth,
unsigned int flags) unsigned int flags)
{ {
unsigned int eflags;
pkg_dependency_t *node; pkg_dependency_t *node;
foreach_list_entry(deplist, node) foreach_list_entry(deplist, node)
@ -316,13 +328,16 @@ pkg_walk_list(pkg_dependency_t *deplist,
if (*node->package == '\0') if (*node->package == '\0')
continue; continue;
pkgdep = pkg_verify_dependency(node, flags); pkgdep = pkg_verify_dependency(node, flags, &eflags);
if (pkgdep == NULL) if (pkgdep == NULL)
{
if (eflags & PKG_ERRF_PACKAGE_NOT_FOUND)
{ {
fprintf(stderr, "Package %s was not found in the pkg-config search path.\n", node->package); fprintf(stderr, "Package %s was not found in the pkg-config search path.\n", node->package);
fprintf(stderr, "Perhaps you should add the directory containing `%s.pc'\n", node->package); fprintf(stderr, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
fprintf(stderr, "to the PKG_CONFIG_PATH environment variable\n"); fprintf(stderr, "to the PKG_CONFIG_PATH environment variable\n");
fprintf(stderr, "No package '%s' found\n", node->package); fprintf(stderr, "No package '%s' found\n", node->package);
}
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

6
pkg.h
View File

@ -104,11 +104,15 @@ struct pkg_ {
#define PKGF_SEARCH_PRIVATE 0x1 #define PKGF_SEARCH_PRIVATE 0x1
#define PKGF_ENV_ONLY 0x2 #define PKGF_ENV_ONLY 0x2
#define PKG_ERRF_OK 0x0
#define PKG_ERRF_PACKAGE_NOT_FOUND 0x1
#define PKG_ERRF_PACKAGE_VER_MISMATCH 0x2
pkg_t *pkg_find(const char *name, unsigned int flags); pkg_t *pkg_find(const char *name, unsigned int flags);
void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags); void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags);
void pkg_verify_graph(pkg_t *root, int depth, unsigned int flags); void pkg_verify_graph(pkg_t *root, int depth, unsigned int flags);
int pkg_compare_version(const char *a, const char *b); int pkg_compare_version(const char *a, const char *b);
pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags); pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags);
const char *pkg_get_comparator(pkg_dependency_t *pkgdep); const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
/* parse.c */ /* parse.c */