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)
35 /* We can include ourselves, of course. */
36 if (streq(depname, m->basename))
39 list_for_each(&m->deps, i, list) {
40 if (streq(i->basename, depname))
46 static void check_depends_accurate(struct manifest *m,
48 unsigned int *timeleft, struct score *score)
50 struct list_head *list;
52 foreach_ptr(list, &m->c_files, &m->h_files,
53 &m->run_tests, &m->api_tests,
54 &m->compile_ok_tests, &m->compile_fail_tests,
55 &m->other_test_c_files) {
58 list_for_each(list, f, list) {
60 char **lines = get_ccan_file_lines(f);
62 for (i = 0; lines[i]; i++) {
64 if (lines[i][strspn(lines[i], " \t")] != '#')
66 p = strip_spaces(f, lines[i]);
67 if (!strstarts(p, "#include<ccan/")
68 && !strstarts(p, "#include\"ccan/"))
70 p += strlen("#include\"ccan/");
71 if (!strchr(strchr(p, '/') + 1, '/'))
73 *strchr(strchr(p, '/') + 1, '/') = '\0';
76 score->error = "Includes a ccan module"
77 " not listed in _info";
78 score_file_error(score, f, i+1, lines[i]);
85 score->score = score->total;
89 struct ccanlint depends_accurate = {
90 .key = "depends-accurate",
91 .name = "Module's CCAN dependencies are the only ccan files #included",
92 .check = check_depends_accurate,
95 REGISTER_TEST(depends_accurate, &depends_exist, NULL);