pkg: implement maximum depth for pkg_traverse()

feature/tap-sh
William Pitcock 2011-07-25 01:22:04 -05:00
parent 8e46a165c2
commit 05d596b9bc
3 changed files with 21 additions and 7 deletions

16
main.c
View File

@ -32,6 +32,7 @@ static int want_version = 0;
static int want_cflags = 0; static int want_cflags = 0;
static int want_libs = 0; static int want_libs = 0;
static int want_modversion = 0; static int want_modversion = 0;
static int maximum_traverse_depth = -1;
static char *required_pkgconfig_version = NULL; static char *required_pkgconfig_version = NULL;
@ -83,6 +84,14 @@ pkg_queue_walk(pkg_queue_t *head)
.realname = "virtual" .realname = "virtual"
}; };
/* if maximum_traverse_depth is one, then we will not traverse deeper
* than our virtual package.
*/
if (!maximum_traverse_depth)
maximum_traverse_depth = -1;
else if (maximum_traverse_depth)
maximum_traverse_depth++;
foreach_list_entry(head, pkgq) foreach_list_entry(head, pkgq)
{ {
world.requires = parse_deplist(&world, pkgq->package); world.requires = parse_deplist(&world, pkgq->package);
@ -94,19 +103,19 @@ pkg_queue_walk(pkg_queue_t *head)
want_cflags = 0; want_cflags = 0;
want_libs = 0; want_libs = 0;
pkg_traverse(&world, print_modversion, NULL); pkg_traverse(&world, print_modversion, NULL, 1);
} }
if (want_cflags) if (want_cflags)
{ {
wanted_something++; wanted_something++;
pkg_traverse(&world, print_cflags, NULL); pkg_traverse(&world, print_cflags, NULL, maximum_traverse_depth);
} }
if (want_libs) if (want_libs)
{ {
wanted_something++; wanted_something++;
pkg_traverse(&world, print_libs, NULL); pkg_traverse(&world, print_libs, NULL, maximum_traverse_depth);
} }
if (wanted_something) if (wanted_something)
@ -138,6 +147,7 @@ main(int argc, const char *argv[])
{ "exists", 0, POPT_ARG_NONE, NULL, 0, "return 0 if all packages present" }, { "exists", 0, POPT_ARG_NONE, NULL, 0, "return 0 if all packages present" },
{ "print-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" }, { "print-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" },
{ "short-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" }, { "short-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" },
{ "maximum-traverse-depth", 0, POPT_ARG_INT, &maximum_traverse_depth, 0, "limits maximum traversal depth of the computed dependency graph" },
POPT_AUTOHELP POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 } { NULL, 0, 0, NULL, 0 }
}; };

8
pkg.c
View File

@ -36,10 +36,14 @@ pkg_find(const char *name)
void void
pkg_traverse(pkg_t *root, pkg_traverse(pkg_t *root,
void (*pkg_traverse_func)(pkg_t *package, void *data), void (*pkg_traverse_func)(pkg_t *package, void *data),
void *data) void *data,
int maxdepth)
{ {
pkg_dependency_t *node; pkg_dependency_t *node;
if (maxdepth == 0)
return;
foreach_list_entry(root->requires, node) foreach_list_entry(root->requires, node)
{ {
pkg_t *pkgdep; pkg_t *pkgdep;
@ -54,7 +58,7 @@ pkg_traverse(pkg_t *root,
continue; continue;
} }
pkg_traverse(pkgdep, pkg_traverse_func, data); pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1);
} }
pkg_traverse_func(root, data); pkg_traverse_func(root, data);

2
pkg.h
View File

@ -85,7 +85,7 @@ struct pkg_ {
}; };
pkg_t *pkg_find(const char *name); pkg_t *pkg_find(const char *name);
void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data); void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth);
/* parse.c */ /* parse.c */
pkg_t *parse_file(const char *path); pkg_t *parse_file(const char *path);