]> git.ozlabs.org Git - ccan/blobdiff - tools/manifest.c
tools: don't assume modules are immediately below ccan/ dir.
[ccan] / tools / manifest.c
index e41c7abc371b8d1b80dcf41ab67b126b09fbcf93..cf4c987e956a261ea42772d16e3f1a5faab8d682 100644 (file)
 #include <ccan/foreach/foreach.h>
 #include <ccan/asort/asort.h>
 #include <ccan/array_size/array_size.h>
+#include <ccan/err/err.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <err.h>
 #include <errno.h>
 #include <dirent.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <assert.h>
 
-const char *ccan_dir;
-
 static size_t dir_hash(const char *name)
 {
        return hash(name, strlen(name), 0);
@@ -239,7 +237,9 @@ struct manifest *get_manifest(const void *ctx, const char *dir)
        list_head_init(&m->examples);
        list_head_init(&m->mangled_examples);
        list_head_init(&m->deps);
+       list_head_init(&m->test_deps);
 
+       /* Trim trailing /. */
        len = strlen(m->dir);
        while (len && m->dir[len-1] == '/')
                m->dir[--len] = '\0';
@@ -249,20 +249,8 @@ struct manifest *get_manifest(const void *ctx, const char *dir)
                errx(1, "I don't expect to be run from the root directory");
        m->basename++;
 
-       /* We expect the ccan dir to be two levels above module dir. */
-       if (!ccan_dir) {
-               char *p, *dir;
-               dir = talloc_strdup(NULL, m->dir);
-               p = strrchr(dir, '/');
-               if (!p)
-                       errx(1, "I expect the ccan root directory in ../..");
-               *p = '\0';
-               p = strrchr(dir, '/');
-               if (!p)
-                       errx(1, "I expect the ccan root directory in ../..");
-               *p = '\0';
-               ccan_dir = dir;
-       }
+       assert(strstarts(m->dir, find_ccan_dir(m->dir)));
+       m->modname = m->dir + strlen(find_ccan_dir(m->dir)) + strlen("ccan/");
 
        add_files(m, "");