]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: recurse to get -l options.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 10 Sep 2012 06:14:00 +0000 (15:44 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 10 Sep 2012 06:14:00 +0000 (15:44 +0930)
If a dependent module needs -l options, we don't notice.  Fix that, now
we have one.

tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/module_links.c
tools/ccanlint/tests/tests_compile.c
tools/depends.c
tools/tools.h

index 7fb60845c6604af2e1b5ecbe7cb90b1bd2c1a286..760711f1c5354f8fc39fa228c213f20ed728db8b 100644 (file)
@@ -107,13 +107,12 @@ static char *example_obj_list(struct manifest *m, struct ccan_file *f)
 /* FIXME: Test with reduced features! */
 static char *lib_list(const struct manifest *m)
 {
-       unsigned int i, num;
+       unsigned int i;
        char **libs;
        char *ret = talloc_strdup(m, "");
 
-       libs = get_libs(m, m->dir, &num,
-                       &m->info_file->compiled[COMPILE_NORMAL]);
-       for (i = 0; i < num; i++)
+       libs = get_libs(m, m->dir, true, get_or_compile_info);
+       for (i = 0; libs[i]; i++)
                ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
        return ret;
 }
index 2dda642978f75b8512e3c97b7c3564f12ea49e17..79aa7d1a872a6421c6fb8706142fe2df0c2b9e76 100644 (file)
@@ -43,12 +43,12 @@ static char *obj_list(const struct manifest *m)
 
 static char *lib_list(const struct manifest *m)
 {
-       unsigned int i, num;
-       char **libs = get_libs(m, ".",
-                              &num, &m->info_file->compiled[COMPILE_NORMAL]);
+       unsigned int i;
+       char **libs;
        char *ret = talloc_strdup(m, "");
 
-       for (i = 0; i < num; i++)
+       libs = get_libs(m, m->dir, true, get_or_compile_info);
+       for (i = 0; libs[i]; i++)
                ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
        return ret;
 }
index 911f310caf5e1d9800f37996600c427483c758b8..733aebdb88d1b7d0a977f1285523ecb878fb32ea 100644 (file)
@@ -54,12 +54,12 @@ char *test_obj_list(const struct manifest *m, bool link_with_module,
 
 char *lib_list(const struct manifest *m, enum compile_type ctype)
 {
-       unsigned int i, num;
-       char **libs = get_libs(m, m->dir, &num,
-                              &m->info_file->compiled[ctype]);
+       unsigned int i;
+       char **libs;
        char *ret = talloc_strdup(m, "");
 
-       for (i = 0; i < num; i++)
+       libs = get_libs(m, m->dir, true, get_or_compile_info);
+       for (i = 0; libs[i]; i++)
                ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
        return ret;
 }
index 6958c37bd2608c2125b1987aeb17b5d50d193a77..19229661f2e581f2b4cc6fc86b6d95e4cf9862e7 100644 (file)
@@ -214,23 +214,55 @@ get_all_deps(const void *ctx, const char *dir,
        return deps;
 }
 
-char **get_libs(const void *ctx, const char *dir,
-               unsigned int *num, char **infofile)
+/* Can return NULL: _info may not support 'libs'. */
+static char **get_one_libs(const void *ctx, const char *dir,
+                          char *(*get_info)(const void *ctx, const char *dir))
+{
+       char *cmd, **lines;
+
+       cmd = talloc_asprintf(ctx, "%s libs", get_info(ctx, dir));
+       lines = lines_from_cmd(cmd, "%s", cmd);
+       /* Strip final NULL. */
+       if (lines)
+               lines = talloc_realloc(NULL, lines, char *,
+                                      talloc_array_length(lines)-1);
+       return lines;
+}
+
+char **get_libs(const void *ctx, const char *dir, bool recurse,
+               char *(*get_info)(const void *ctx, const char *dir))
 {
-       char **libs, *cmd;
+       char **deps, **libs;
+       unsigned int i, len;
+
+       libs = get_one_libs(ctx, dir, get_info);
+       len = talloc_array_length(libs);
 
-       if (!*infofile) {
-               *infofile = compile_info(ctx, dir);
-               if (!*infofile)
-                       errx(1, "Could not compile _info for '%s'", dir);
+       if (recurse) {
+               deps = get_deps(ctx, dir, true, get_info);
+               for (i = 0; deps[i]; i++) {
+                       char **newlibs, *subdir;
+                       size_t newlen;
+
+                       if (!strstarts(deps[i], "ccan/"))
+                               continue;
+
+                       subdir = talloc_asprintf(ctx, "%s/%s",
+                                                talloc_dirname(ctx, dir),
+                                                deps[i] + strlen("ccan/"));
+
+                       newlibs = get_one_libs(ctx, subdir, get_info);
+                       newlen = talloc_array_length(newlibs);
+                       libs = talloc_realloc(ctx, libs, char *, len + newlen);
+                       memcpy(&libs[len], newlibs,
+                              sizeof(newlibs[0])*newlen);
+                       len += newlen;
+               }
        }
 
-       cmd = talloc_asprintf(ctx, "%s libs", *infofile);
-       libs = lines_from_cmd(cmd, "%s", cmd);
-       if (!libs)
-               err(1, "Could not run '%s'", cmd);
-       /* FIXME: Do we need num arg? */
-       *num = talloc_array_length(libs) - 1;
+       /* Append NULL entry. */
+       libs = talloc_realloc(ctx, libs, char *, len + 1);
+       libs[len] = NULL;
        return libs;
 }
 
index e78d13904c82b1c36c263ddb57a5fdb267779139..56e9de610620a0c944da84fc7f58337c3ae66393 100644 (file)
@@ -30,8 +30,8 @@ char **get_deps(const void *ctx, const char *dir, bool recurse,
 char **get_safe_ccan_deps(const void *ctx, const char *dir, bool recurse);
 
 /* This also needs to compile the info file. */
-char **get_libs(const void *ctx, const char *dir,
-               unsigned int *num, char **infofile);
+char **get_libs(const void *ctx, const char *dir, bool recurse,
+               char *(*get_info)(const void *ctx, const char *dir));
 
 /* From tools.c */
 /* If set, print all commands run, all output they give and exit status. */