summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-03-19 15:45:45 +1030
committerRusty Russell <rusty@rustcorp.com.au>2012-03-19 15:45:45 +1030
commit20ea8a370823bd73a3c96da40a4779fa6ea66462 (patch)
tree6779dcc4d94c8212526d5fc55f801b04f1538242
parent4ded146c1b385977b02de6c66d6c1b1c514ebfbe (diff)
tools: explicit find_ccan_dir()
Move ccan_dir determination out to its own function, rather than implying it by the first time we get the manifest of a module.
-rw-r--r--tools/ccan_dir.c31
-rw-r--r--tools/ccanlint/Makefile1
-rw-r--r--tools/ccanlint/ccanlint.c15
-rw-r--r--tools/ccanlint/ccanlint.h3
-rw-r--r--tools/manifest.c24
-rw-r--r--tools/manifest.h3
-rw-r--r--tools/tools.h2
7 files changed, 48 insertions, 31 deletions
diff --git a/tools/ccan_dir.c b/tools/ccan_dir.c
new file mode 100644
index 00000000..0bb9b144
--- /dev/null
+++ b/tools/ccan_dir.c
@@ -0,0 +1,31 @@
+#include <ccan/talloc/talloc.h>
+#include "tools.h"
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* Walk up to find /ccan/ => ccan directory. */
+static unsigned int ccan_dir_prefix(const char *fulldir)
+{
+ unsigned int i;
+
+ assert(fulldir[0] == '/');
+ for (i = strlen(fulldir) - 1; i > 0; i--) {
+ if (strncmp(fulldir+i, "/ccan", 5) != 0)
+ continue;
+ if (fulldir[i+5] != '\0' && fulldir[i+5] != '/')
+ continue;
+ return i + 1;
+ }
+ return 0;
+}
+
+const char *find_ccan_dir(const char *base)
+{
+ unsigned int prefix = ccan_dir_prefix(base);
+
+ if (!prefix)
+ return NULL;
+
+ return talloc_strndup(NULL, base, prefix);
+}
diff --git a/tools/ccanlint/Makefile b/tools/ccanlint/Makefile
index 463ef89e..cf450f27 100644
--- a/tools/ccanlint/Makefile
+++ b/tools/ccanlint/Makefile
@@ -27,6 +27,7 @@ CORE_OBJS := \
tools/ccanlint/ccanlint.o \
tools/ccanlint/file_analysis.o \
tools/ccanlint/licenses.o \
+ tools/ccan_dir.o \
tools/compile.o \
tools/depends.o \
tools/doc_extract-core.o \
diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c
index 516c5bb6..931ed41a 100644
--- a/tools/ccanlint/ccanlint.c
+++ b/tools/ccanlint/ccanlint.c
@@ -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)
{
@@ -777,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);
diff --git a/tools/ccanlint/ccanlint.h b/tools/ccanlint/ccanlint.h
index 6fcca5fa..8ebf68d2 100644
--- a/tools/ccanlint/ccanlint.h
+++ b/tools/ccanlint/ccanlint.h
@@ -191,4 +191,7 @@ extern const char *compiler, *cflags;
/* Contents of config.h (or NULL if not found) */
extern const char *config_header;
+/* Where is the ccan dir? */
+extern const char *ccan_dir;
+
#endif /* CCAN_LINT_H */
diff --git a/tools/manifest.c b/tools/manifest.c
index 9de9030b..024eaa42 100644
--- a/tools/manifest.c
+++ b/tools/manifest.c
@@ -23,8 +23,6 @@
#include <stdarg.h>
#include <assert.h>
-const char *ccan_dir;
-
static size_t dir_hash(const char *name)
{
return hash(name, strlen(name), 0);
@@ -196,22 +194,6 @@ static void sort_files(struct list_head *list)
talloc_free(files);
}
-/* Walk up tp find /ccan/ => ccan directory. */
-static unsigned int ccan_dir_prefix(const char *fulldir)
-{
- unsigned int i;
-
- assert(fulldir[0] == '/');
- for (i = strlen(fulldir) - 1; i > 0; i--) {
- if (strncmp(fulldir+i, "/ccan", 5) != 0)
- continue;
- if (fulldir[i+5] != '\0' && fulldir[i+5] != '/')
- continue;
- return i + 1;
- }
- errx(1, "Could not find /ccan/ dir in %s", fulldir);
-}
-
struct manifest *get_manifest(const void *ctx, const char *dir)
{
struct manifest *m;
@@ -265,12 +247,6 @@ 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++;
- if (!ccan_dir) {
- unsigned int prefix = ccan_dir_prefix(m->dir);
-
- ccan_dir = talloc_strndup(NULL, m->dir, prefix);
- }
-
add_files(m, "");
/* Nicer to run tests in a predictable order. */
diff --git a/tools/manifest.h b/tools/manifest.h
index 588efe5f..ee5ae9df 100644
--- a/tools/manifest.h
+++ b/tools/manifest.h
@@ -89,7 +89,4 @@ const char *get_ccan_file_contents(struct ccan_file *f);
/* Use this rather than accessing f->lines directly: loads on demand. */
char **get_ccan_file_lines(struct ccan_file *f);
-/* Where is the ccan dir? Available after first manifest. */
-extern const char *ccan_dir;
-
#endif /* CCAN_TOOLS_MANIFEST_H */
diff --git a/tools/tools.h b/tools/tools.h
index 4ac98183..8d1ae048 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -75,4 +75,6 @@ extern const unsigned int default_timeout_ms;
/* Talloc destructor which unlinks file. */
int unlink_file_destructor(char *filename);
+/* Get ccan/ top dir, given a directory within it. */
+const char *find_ccan_dir(const char *base);
#endif /* CCAN_TOOLS_H */