1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 static bool expect_obj_file(const char *dir)
20 struct manifest *dep_man;
23 olddir = talloc_getcwd(dir);
25 err(1, "Getting current directory");
27 /* We will fail below if this doesn't exist. */
31 dep_man = get_manifest(dir);
32 if (chdir(olddir) != 0)
33 err(1, "Returning to original directory '%s'", olddir);
36 /* If it has C files, we expect an object file built from them. */
37 has_c_files = !list_empty(&dep_man->c_files);
42 /* FIXME: recursive ccanlint if they ask for it. */
43 static char *add_dep(char *sofar, struct manifest *m, const char *dep)
49 dir = talloc_asprintf(m, "../%s", dep);
50 need_obj = expect_obj_file(dir);
53 file = talloc_asprintf(m, "../%s.o", dep);
54 if (stat(file, &st) == 0) {
55 struct ccan_file *f = new_ccan_file(m, file);
56 list_add_tail(&m->dep_obj_files, &f->list);
61 if (stat(dir, &st) == 0) {
65 return talloc_asprintf_append(sofar,
66 "ccan/%s: isn't built (no %s)\n",
70 return talloc_asprintf_append(sofar,
71 "ccan/%s: could not find directory %s\n",
75 static void *check_depends(struct manifest *m)
82 deps = get_safe_ccan_deps(m, "..", m->basename, true);
84 deps = get_deps(m, "..", m->basename, true);
86 for (i = 0; deps[i]; i++) {
87 if (!strstarts(deps[i], "ccan/"))
90 report = add_dep(report, m, deps[i] + strlen("ccan/"));
95 static const char *describe_depends(struct manifest *m, void *check_result)
97 return talloc_asprintf(check_result,
98 "The following dependencies are needed:\n"
99 "%s\n", (char *)check_result);
102 struct ccanlint depends = {
103 .name = "CCAN dependencies are built",
105 .check = check_depends,
106 .describe = describe_depends,
109 REGISTER_TEST(depends, NULL);