1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/tal/path/path.h>
17 static bool have_dep(struct manifest *m, const char *dep)
21 list_for_each(&m->deps, i, list)
22 if (streq(i->modname, dep + strlen("ccan/")))
28 static bool add_dep(struct manifest *m,
29 struct list_head *deplist,
30 const char *dep, struct score *score)
33 struct manifest *subm;
34 char *dir = path_join(m, ccan_dir, dep);
36 /* FIXME: get_manifest has a tendency to exit. */
37 if (stat(dir, &st) != 0) {
38 score->error = tal_fmt(m, "Could not stat dependency %s: %s",
39 dir, strerror(errno));
42 subm = get_manifest(m, dir);
43 list_add_tail(deplist, &subm->list);
47 /* FIXME: check this is still true once we reduce features. */
48 static void check_depends_exist(struct manifest *m,
49 unsigned int *timeleft UNNEEDED,
56 deps = get_safe_ccan_deps(m, m->dir, "depends", true);
58 deps = get_deps(m, m->dir, "depends", true,
62 score->error = tal_fmt(m, "Could not extract dependencies");
66 for (i = 0; deps[i]; i++) {
67 if (!strstarts(deps[i], "ccan/")) {
72 if (!add_dep(m, &m->deps, deps[i], score))
77 score->score = score->total;
80 static void check_test_depends_exist(struct manifest *m,
81 unsigned int *timeleft UNNEEDED,
88 /* We may need libtap for testing, unless we're "tap" */
89 if (streq(m->modname, "tap")) {
91 } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
98 deps = get_safe_ccan_deps(m, m->dir, "testdepends", true);
100 deps = get_deps(m, m->dir, "testdepends", true,
101 get_or_compile_info);
103 for (i = 0; deps[i]; i++) {
104 if (!strstarts(deps[i], "ccan/"))
107 /* Don't add dependency twice: we can only be on one list!
108 * Also, it's possible to have circular test depends, so drop
110 if (!have_dep(m, deps[i])
111 && !streq(deps[i] + strlen("ccan/"), m->modname)
112 && !add_dep(m, &m->test_deps, deps[i], score))
115 if (streq(deps[i], "ccan/tap")) {
120 if (needs_tap && !have_dep(m, "ccan/tap")
121 && !add_dep(m, &m->test_deps, "ccan/tap", score)) {
126 score->score = score->total;
129 struct ccanlint depends_exist = {
130 .key = "depends_exist",
131 .name = "Module's CCAN dependencies can be found",
133 .check = check_depends_exist,
134 .needs = "info_compiles"
137 REGISTER_TEST(depends_exist);
139 struct ccanlint test_depends_exist = {
140 .key = "test_depends_exist",
141 .name = "Module's CCAN test dependencies can be found",
143 .check = check_test_depends_exist,
144 .needs = "depends_exist"
147 REGISTER_TEST(test_depends_exist);