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, struct score *score)
55 deps = get_safe_ccan_deps(m, m->dir, "depends", true);
57 deps = get_deps(m, m->dir, "depends", true,
60 for (i = 0; deps[i]; i++) {
61 if (!strstarts(deps[i], "ccan/"))
64 if (!add_dep(m, &m->deps, deps[i], score))
69 score->score = score->total;
72 static void check_test_depends_exist(struct manifest *m,
73 unsigned int *timeleft,
80 /* We may need libtap for testing, unless we're "tap" */
81 if (streq(m->modname, "tap")) {
83 } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
90 deps = get_safe_ccan_deps(m, m->dir, "testdepends", true);
92 deps = get_deps(m, m->dir, "testdepends", true,
95 for (i = 0; deps[i]; i++) {
96 if (!strstarts(deps[i], "ccan/"))
99 /* Don't add dependency twice: we can only be on one list! */
100 if (!have_dep(m, deps[i])
101 && !add_dep(m, &m->test_deps, deps[i], score))
104 if (streq(deps[i], "ccan/tap")) {
109 if (needs_tap && !have_dep(m, "ccan/tap")
110 && !add_dep(m, &m->test_deps, "ccan/tap", score)) {
115 score->score = score->total;
118 struct ccanlint depends_exist = {
119 .key = "depends_exist",
120 .name = "Module's CCAN dependencies can be found",
122 .check = check_depends_exist,
123 .needs = "info_exists"
126 REGISTER_TEST(depends_exist);
128 struct ccanlint test_depends_exist = {
129 .key = "test_depends_exist",
130 .name = "Module's CCAN test dependencies can be found",
132 .check = check_test_depends_exist,
133 .needs = "depends_exist"
136 REGISTER_TEST(test_depends_exist);