]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/ccanlint.c
tools: explicit find_ccan_dir()
[ccan] / tools / ccanlint / ccanlint.c
index d31ef94058f6d63b0030f5e85c6e971edbc60189..931ed41a44429c91affa837c789cd7294e8287cb 100644 (file)
@@ -52,6 +52,8 @@ const char *cflags = NULL;
 
 const char *config_header;
 
+const char *ccan_dir;
+
 #if 0
 static void indent_print(const char *string)
 {
@@ -279,19 +281,18 @@ static bool check_names(const char *member, struct ccanlint *c,
        return true;
 }
 
-#undef REGISTER_TEST
-#define REGISTER_TEST(name, ...) extern struct ccanlint name
-#include "generated-testlist"
-
 static void init_tests(void)
 {
        struct ccanlint_map names;
+       struct ccanlint **table;
+       size_t i, num;
 
        strmap_init(&tests);
 
-#undef REGISTER_TEST
-#define REGISTER_TEST(name) register_test(&name)
-#include "generated-testlist"
+       table = autodata_get(ccanlint_tests, &num);
+       for (i = 0; i < num; i++)
+               register_test(table[i]);
+       autodata_free(table);
 
        strmap_iterate(&tests, init_deps, NULL);
 
@@ -690,7 +691,9 @@ static bool run_tests(struct dgraph_node *all,
 static bool add_to_all(const char *member, struct ccanlint *c,
                       struct dgraph_node *all)
 {
-       dgraph_add_edge(&c->node, all);
+       /* If we're excluded on cmdline, don't add. */
+       if (!c->skip)
+               dgraph_add_edge(&c->node, all);
        return true;
 }
 
@@ -776,16 +779,21 @@ int main(int argc, char *argv[])
                        dir[strlen(dir)-1] = '\0';
 
        got_dir:
+               /* We assume there's a ccan/ in there somewhere... */
+               if (i == 1) {
+                       ccan_dir = find_ccan_dir(dir);
+                       if (!ccan_dir)
+                               errx(1, "Cannot find ccan/ base directory in %s",
+                                    dir);
+                       read_config_header();
+               }
+
                if (dir != base_dir)
                        prefix = talloc_append_string(talloc_basename(NULL,dir),
                                                      ": ");
 
                m = get_manifest(talloc_autofree_context(), dir);
 
-               /* FIXME: This has to come after we've got manifest. */
-               if (i == 1)
-                       read_config_header();
-
                /* Create a symlink from temp dir back to src dir's
                 * test directory. */
                unlink(testlink);