]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/depends_exist.c
Merge Makefile rewrite into master
[ccan] / tools / ccanlint / tests / depends_exist.c
index 76750fb1236f7bab79e7ff2a73412aa74185d919..50f154221f3bb46e931da8d845b768a9c4f025b7 100644 (file)
@@ -1,7 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
+#include <ccan/tal/path/path.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -19,7 +19,7 @@ static bool have_dep(struct manifest *m, const char *dep)
        struct manifest *i;
 
        list_for_each(&m->deps, i, list)
-               if (streq(i->basename, dep + strlen("ccan/")))
+               if (streq(i->modname, dep + strlen("ccan/")))
                        return true;
 
        return false;
@@ -31,14 +31,12 @@ static bool add_dep(struct manifest *m,
 {
        struct stat st;
        struct manifest *subm;
-       char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep);
+       char *dir = path_join(m, ccan_dir, dep);
 
        /* FIXME: get_manifest has a tendency to exit. */
        if (stat(dir, &st) != 0) {
-               score->error
-                       = talloc_asprintf(m,
-                                         "Could not stat dependency %s: %s",
-                                         dir, strerror(errno));
+               score->error = tal_fmt(m, "Could not stat dependency %s: %s",
+                                      dir, strerror(errno));
                return false;
        }
        subm = get_manifest(m, dir);
@@ -48,7 +46,8 @@ static bool add_dep(struct manifest *m,
 
 /* FIXME: check this is still true once we reduce features. */
 static void check_depends_exist(struct manifest *m,
-                               unsigned int *timeleft, struct score *score)
+                               unsigned int *timeleft UNNEEDED,
+                               struct score *score)
 {
        unsigned int i;
        char **deps;
@@ -59,9 +58,16 @@ static void check_depends_exist(struct manifest *m,
                deps = get_deps(m, m->dir, "depends", true,
                                get_or_compile_info);
 
+       if (!deps) {
+               score->error = tal_fmt(m, "Could not extract dependencies");
+               return;
+       }
+
        for (i = 0; deps[i]; i++) {
-               if (!strstarts(deps[i], "ccan/"))
+               if (!strstarts(deps[i], "ccan/")) {
+                       non_ccan_deps = true;
                        continue;
+               }
 
                if (!add_dep(m, &m->deps, deps[i], score))
                        return;
@@ -72,7 +78,7 @@ static void check_depends_exist(struct manifest *m,
 }
 
 static void check_test_depends_exist(struct manifest *m,
-                                    unsigned int *timeleft,
+                                    unsigned int *timeleft UNNEEDED,
                                     struct score *score)
 {
        unsigned int i;
@@ -80,7 +86,7 @@ static void check_test_depends_exist(struct manifest *m,
        bool needs_tap;
 
        /* We may need libtap for testing, unless we're "tap" */
-       if (streq(m->basename, "tap")) {
+       if (streq(m->modname, "tap")) {
                needs_tap = false;
        } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
                needs_tap = false;
@@ -98,8 +104,11 @@ static void check_test_depends_exist(struct manifest *m,
                if (!strstarts(deps[i], "ccan/"))
                        continue;
 
-               /* Don't add dependency twice: we can only be on one list! */
+               /* Don't add dependency twice: we can only be on one list!
+                * Also, it's possible to have circular test depends, so drop
+                * self-refs. */
                if (!have_dep(m, deps[i])
+                   && !streq(deps[i] + strlen("ccan/"), m->modname)
                    && !add_dep(m, &m->test_deps, deps[i], score))
                        return;
 
@@ -122,7 +131,7 @@ struct ccanlint depends_exist = {
        .name = "Module's CCAN dependencies can be found",
        .compulsory = true,
        .check = check_depends_exist,
-       .needs = "info_exists"
+       .needs = "info_compiles"
 };
 
 REGISTER_TEST(depends_exist);