ccanlint: handle nested modules when mentioned in examples.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 08:59:23 +0000 (19:29 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 08:59:23 +0000 (19:29 +1030)
If we see an ccan include line in an example, we add that to the
dependencies to try to build the example, but we didn't handle nested
modules.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/ccanlint/tests/depends_accurate.c
tools/ccanlint/tests/examples_compile.c

index 83a19e2cea57ad041f5c71584a9eb5beb23b008d..05ada48a40dc8b829c361beca5ba9d17350abc6c 100644 (file)
@@ -48,7 +48,7 @@ static bool check_dep_includes(struct manifest *m,
                char *mod;
                if (!strreg(f, lines[i],
                            "^[ \t]*#[ \t]*include[ \t]*[<\"]"
-                           "(ccan/+.+)/+[^/]+.h", &mod))
+                           "(ccan/+.+)/+[^/]+\\.h", &mod))
                        continue;
 
                if (has_dep(m, deps, used, mod))
index ce1d9769691d7ee6fa07736e33718f8deb2c55e5..7d8803c6973db2cc4213915a30caa1e3aa67d5f3 100644 (file)
@@ -1,6 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <ccan/talloc/talloc.h>
+#include <ccan/str_talloc/str_talloc.h>
 #include <ccan/cast/cast.h>
 #include <ccan/str/str.h>
 #include <sys/types.h>
@@ -83,13 +84,10 @@ static struct manifest **get_example_deps(struct manifest *m,
 
        /* Other modules implied by includes. */
        for (lines = get_ccan_file_lines(f); *lines; lines++) {
-               unsigned preflen = strspn(*lines, " \t");
-               if (strstarts(*lines + preflen, "#include <ccan/")) {
-                       char *modname;
-
-                       modname = talloc_strdup(f, *lines + preflen
-                                               + strlen("#include <ccan/"));
-                       modname[strcspn(modname, "/")] = '\0';
+               char *modname;
+               if (strreg(f, *lines,
+                           "^[ \t]*#[ \t]*include[ \t]*[<\"]"
+                          "ccan/+(.+)/+[^/]+\\.h", &modname)) {
                        if (!have_mod(deps, modname))
                                add_dep(&deps, modname);
                }