--- /dev/null
+#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);
+}
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 \
const char *config_header;
+const char *ccan_dir;
+
#if 0
static void indent_print(const char *string)
{
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);
/* 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 */
#include <stdarg.h>
#include <assert.h>
-const char *ccan_dir;
-
static size_t dir_hash(const char *name)
{
return hash(name, strlen(name), 0);
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;
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. */
/* 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 */
/* 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 */