1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <ccan/str_talloc/str_talloc.h>
6 #include <ccan/foreach/foreach.h>
19 static bool has_dep(struct manifest *m, bool test_depend, const char *depname)
23 /* We can include ourselves, of course. */
24 if (streq(depname, m->basename))
27 list_for_each(&m->deps, i, list) {
28 if (streq(i->basename, depname))
33 list_for_each(&m->test_deps, i, list) {
34 if (streq(i->basename, depname))
42 static void check_dep_includes(struct manifest *m, struct score *score,
43 struct ccan_file *f, bool test_depend)
46 char **lines = get_ccan_file_lines(f);
47 struct line_info *li = get_ccan_line_info(f);
49 for (i = 0; lines[i]; i++) {
51 if (!strreg(f, lines[i],
52 "^[ \t]*#[ \t]*include[ \t]*[<\"]"
53 "ccan/+([^/]+)/", &mod))
56 if (has_dep(m, test_depend, mod))
59 /* FIXME: we can't be sure about
60 * conditional includes, so don't
63 score_file_error(score, f, i+1,
64 "%s not listed in _info", mod);
69 static void check_depends_accurate(struct manifest *m,
70 unsigned int *timeleft, struct score *score)
72 struct list_head *list;
74 foreach_ptr(list, &m->c_files, &m->h_files) {
77 list_for_each(list, f, list)
78 check_dep_includes(m, score, f, false);
81 foreach_ptr(list, &m->run_tests, &m->api_tests,
82 &m->compile_ok_tests, &m->compile_fail_tests,
83 &m->other_test_c_files) {
86 list_for_each(list, f, list)
87 check_dep_includes(m, score, f, true);
91 score->score = score->total;
96 struct ccanlint depends_accurate = {
97 .key = "depends_accurate",
98 .name = "Module's CCAN dependencies are the only CCAN files #included",
99 .check = check_depends_accurate,
100 .needs = "depends_exist test_depends_exist"
103 REGISTER_TEST(depends_accurate);