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/foreach/foreach.h>
18 static char *strip_spaces(const void *ctx, char *line)
20 char *p = talloc_strdup(ctx, line);
23 for (i = 0, j = 0; p[i]; i++) {
31 static bool has_dep(struct manifest *m, const char *depname, bool tap_ok)
35 if (tap_ok && streq(depname, "ccan/tap"))
38 /* We can include ourselves, of course. */
39 if (streq(depname + strlen("ccan/"), m->basename))
42 list_for_each(&m->dep_dirs, f, list) {
43 if (streq(f->name, depname))
49 static void check_depends_accurate(struct manifest *m,
51 unsigned int *timeleft, struct score *score)
53 struct list_head *list;
55 foreach_ptr(list, &m->c_files, &m->h_files,
56 &m->run_tests, &m->api_tests,
57 &m->compile_ok_tests, &m->compile_fail_tests,
58 &m->other_test_c_files) {
62 /* Including ccan/tap is fine for tests. */
63 tap_ok = (list != &m->c_files && list != &m->h_files);
65 list_for_each(list, f, list) {
67 char **lines = get_ccan_file_lines(f);
69 for (i = 0; lines[i]; i++) {
71 if (lines[i][strspn(lines[i], " \t")] != '#')
73 p = strip_spaces(f, lines[i]);
74 if (!strstarts(p, "#include<ccan/")
75 && !strstarts(p, "#include\"ccan/"))
77 p += strlen("#include\"");
78 if (!strchr(strchr(p, '/') + 1, '/'))
80 *strchr(strchr(p, '/') + 1, '/') = '\0';
81 if (has_dep(m, p, tap_ok))
83 score->error = "Includes a ccan module"
84 " not listed in _info";
85 score_file_error(score, f, i+1, lines[i]);
92 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,
102 REGISTER_TEST(depends_accurate, &depends_exist, NULL);