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,
61 score->error = tal_fmt(m, "Could not extract dependencies");
65 for (i = 0; deps[i]; i++) {
66 if (!strstarts(deps[i], "ccan/")) {
71 if (!add_dep(m, &m->deps, deps[i], score))
76 score->score = score->total;
79 static void check_test_depends_exist(struct manifest *m,
80 unsigned int *timeleft,
87 /* We may need libtap for testing, unless we're "tap" */
88 if (streq(m->modname, "tap")) {
90 } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
97 deps = get_safe_ccan_deps(m, m->dir, "testdepends", true);
99 deps = get_deps(m, m->dir, "testdepends", true,
100 get_or_compile_info);
102 for (i = 0; deps[i]; i++) {
103 if (!strstarts(deps[i], "ccan/"))
106 /* Don't add dependency twice: we can only be on one list!
107 * Also, it's possible to have circular test depends, so drop
109 if (!have_dep(m, deps[i])
110 && !streq(deps[i] + strlen("ccan/"), m->modname)
111 && !add_dep(m, &m->test_deps, deps[i], score))
114 if (streq(deps[i], "ccan/tap")) {
119 if (needs_tap && !have_dep(m, "ccan/tap")
120 && !add_dep(m, &m->test_deps, "ccan/tap", score)) {
125 score->score = score->total;
128 struct ccanlint depends_exist = {
129 .key = "depends_exist",
130 .name = "Module's CCAN dependencies can be found",
132 .check = check_depends_exist,
133 .needs = "info_compiles"
136 REGISTER_TEST(depends_exist);
138 struct ccanlint test_depends_exist = {
139 .key = "test_depends_exist",
140 .name = "Module's CCAN test dependencies can be found",
142 .check = check_test_depends_exist,
143 .needs = "depends_exist"
146 REGISTER_TEST(test_depends_exist);