]> git.ozlabs.org Git - ccan/blobdiff - tools/manifest.c
tools: use rbuf instead of grab_file.
[ccan] / tools / manifest.c
index e41c7abc371b8d1b80dcf41ab67b126b09fbcf93..b4db234f67501bf72525dec54aa549c8218c66d2 100644 (file)
@@ -7,24 +7,21 @@
 #include <ccan/talloc_link/talloc_link.h>
 #include <ccan/hash/hash.h>
 #include <ccan/htable/htable_type.h>
-#include <ccan/grab_file/grab_file.h>
 #include <ccan/noerr/noerr.h>
 #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);
@@ -47,7 +44,8 @@ static struct htable_manifest *manifests;
 const char *get_ccan_file_contents(struct ccan_file *f)
 {
        if (!f->contents) {
-               f->contents = grab_file(f, f->fullname, &f->contents_size);
+               f->contents = talloc_grab_file(f, f->fullname,
+                                              &f->contents_size);
                if (!f->contents)
                        err(1, "Reading file %s", f->fullname);
        }
@@ -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, "");