From 199023653cd6020218fbc4d0712591fc7ee0c5e1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 12 Nov 2012 17:03:24 +1030 Subject: [PATCH] tools: enhance get_libs to get libraries for tests, too. Signed-off-by: Rusty Russell --- tools/ccanlint/tests/examples_compile.c | 2 +- tools/ccanlint/tests/module_links.c | 2 +- tools/ccanlint/tests/tests_compile.c | 2 +- tools/depends.c | 28 ++++++++++++++++++++++--- tools/tools.h | 8 +++++-- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tools/ccanlint/tests/examples_compile.c b/tools/ccanlint/tests/examples_compile.c index 79817c78..ac9476fd 100644 --- a/tools/ccanlint/tests/examples_compile.c +++ b/tools/ccanlint/tests/examples_compile.c @@ -120,7 +120,7 @@ static char *example_lib_list(const void *ctx, struct manifest **deps) /* FIXME: This doesn't uniquify. */ for (i = 0; i < talloc_array_length(deps); i++) { - libs = get_libs(ctx, deps[i]->dir, false, get_or_compile_info); + libs = get_libs(ctx, deps[i]->dir, NULL, get_or_compile_info); for (j = 0; libs[j]; j++) list = talloc_asprintf_append(list, "-l%s ", libs[j]); } diff --git a/tools/ccanlint/tests/module_links.c b/tools/ccanlint/tests/module_links.c index 79aa7d1a..d665ba7d 100644 --- a/tools/ccanlint/tests/module_links.c +++ b/tools/ccanlint/tests/module_links.c @@ -47,7 +47,7 @@ static char *lib_list(const struct manifest *m) char **libs; char *ret = talloc_strdup(m, ""); - libs = get_libs(m, m->dir, true, get_or_compile_info); + libs = get_libs(m, m->dir, "depends", get_or_compile_info); for (i = 0; libs[i]; i++) ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); return ret; diff --git a/tools/ccanlint/tests/tests_compile.c b/tools/ccanlint/tests/tests_compile.c index 733aebdb..3114f2f1 100644 --- a/tools/ccanlint/tests/tests_compile.c +++ b/tools/ccanlint/tests/tests_compile.c @@ -58,7 +58,7 @@ char *lib_list(const struct manifest *m, enum compile_type ctype) char **libs; char *ret = talloc_strdup(m, ""); - libs = get_libs(m, m->dir, true, get_or_compile_info); + libs = get_libs(m, m->dir, "depends", get_or_compile_info); for (i = 0; libs[i]; i++) ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); return ret; diff --git a/tools/depends.c b/tools/depends.c index c6c77544..441c2c47 100644 --- a/tools/depends.c +++ b/tools/depends.c @@ -244,7 +244,24 @@ static char **get_one_libs(const void *ctx, const char *dir, return lines; } -char **get_libs(const void *ctx, const char *dir, bool recurse, +/* O(n^2) but n is small. */ +static char **add_deps(char **deps1, char **deps2) +{ + unsigned int i, len; + + len = talloc_array_length(deps1); + + for (i = 0; deps2[i]; i++) { + if (have_dep(deps1, deps2[i])) + continue; + deps1 = talloc_realloc(NULL, deps1, char *, len + 1); + deps1[len-1] = talloc_steal(deps1, deps2[i]); + deps1[len++] = NULL; + } + return deps1; +} + +char **get_libs(const void *ctx, const char *dir, const char *style, char *(*get_info)(const void *ctx, const char *dir)) { char **deps, **libs; @@ -253,8 +270,13 @@ char **get_libs(const void *ctx, const char *dir, bool recurse, libs = get_one_libs(ctx, dir, get_info); len = talloc_array_length(libs); - if (recurse) { - deps = get_deps(ctx, dir, "depends", true, get_info); + if (style) { + deps = get_deps(ctx, dir, style, true, get_info); + if (streq(style, "testdepends")) + deps = add_deps(deps, + get_deps(ctx, dir, "depends", true, + get_info)); + for (i = 0; deps[i]; i++) { char **newlibs, *subdir; size_t newlen; diff --git a/tools/tools.h b/tools/tools.h index 7368e932..1e9e2242 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -31,8 +31,12 @@ char **get_deps(const void *ctx, const char *dir, const char *style, char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style, bool recurse); -/* This also needs to compile the info file. */ -char **get_libs(const void *ctx, const char *dir, bool recurse, +/* This also needs to compile the info file: + * style == NULL: don't recurse. + * style == depends: recurse dependencies. + * style == testdepends: recurse testdepends and depends. + */ +char **get_libs(const void *ctx, const char *dir, const char *style, char *(*get_info)(const void *ctx, const char *dir)); /* From tools.c */ -- 2.39.2