1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
16 static bool have_dep(struct manifest *m, const char *dep)
20 list_for_each(&m->deps, i, list)
21 if (streq(i->modname, dep + strlen("ccan/")))
27 static bool add_dep(struct manifest *m,
28 struct list_head *deplist,
29 const char *dep, struct score *score)
32 struct manifest *subm;
33 char *dir = tal_fmt(m, "%s/%s", ccan_dir, dep);
35 /* FIXME: get_manifest has a tendency to exit. */
36 if (stat(dir, &st) != 0) {
37 score->error = tal_fmt(m, "Could not stat dependency %s: %s",
38 dir, strerror(errno));
41 subm = get_manifest(m, dir);
42 list_add_tail(deplist, &subm->list);
46 /* FIXME: check this is still true once we reduce features. */
47 static void check_depends_exist(struct manifest *m,
48 unsigned int *timeleft, struct score *score)
54 deps = get_safe_ccan_deps(m, m->dir, "depends", true);
56 deps = get_deps(m, m->dir, "depends", true,
59 for (i = 0; deps[i]; i++) {
60 if (!strstarts(deps[i], "ccan/"))
63 if (!add_dep(m, &m->deps, deps[i], score))
68 score->score = score->total;
71 static void check_test_depends_exist(struct manifest *m,
72 unsigned int *timeleft,
79 /* We may need libtap for testing, unless we're "tap" */
80 if (streq(m->modname, "tap")) {
82 } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
89 deps = get_safe_ccan_deps(m, m->dir, "testdepends", true);
91 deps = get_deps(m, m->dir, "testdepends", true,
94 for (i = 0; deps[i]; i++) {
95 if (!strstarts(deps[i], "ccan/"))
98 /* Don't add dependency twice: we can only be on one list! */
99 if (!have_dep(m, deps[i])
100 && !add_dep(m, &m->test_deps, deps[i], score))
103 if (streq(deps[i], "ccan/tap")) {
108 if (needs_tap && !have_dep(m, "ccan/tap")
109 && !add_dep(m, &m->test_deps, "ccan/tap", score)) {
114 score->score = score->total;
117 struct ccanlint depends_exist = {
118 .key = "depends_exist",
119 .name = "Module's CCAN dependencies can be found",
121 .check = check_depends_exist,
122 .needs = "info_exists"
125 REGISTER_TEST(depends_exist);
127 struct ccanlint test_depends_exist = {
128 .key = "test_depends_exist",
129 .name = "Module's CCAN test dependencies can be found",
131 .check = check_test_depends_exist,
132 .needs = "depends_exist"
135 REGISTER_TEST(test_depends_exist);