X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fdepends_accurate.c;h=5549fc13360de3f96735a75622b9cd871ef6fa1f;hb=c3a4f74f5ddedd7fed3f351498a6743d2a1d9ed1;hp=05ada48a40dc8b829c361beca5ba9d17350abc6c;hpb=932d65dd6537250e617516749f03a00fea3b34f6;p=ccan diff --git a/tools/ccanlint/tests/depends_accurate.c b/tools/ccanlint/tests/depends_accurate.c index 05ada48a..5549fc13 100644 --- a/tools/ccanlint/tests/depends_accurate.c +++ b/tools/ccanlint/tests/depends_accurate.c @@ -1,8 +1,7 @@ #include #include -#include #include -#include +#include #include #include #include @@ -22,8 +21,13 @@ static bool has_dep(struct manifest *m, char **deps, bool *used, unsigned int i; /* We can include ourselves, of course. */ - if (streq(depname + strlen("ccan/"), m->modname)) - return true; + if (strstarts(depname + strlen("ccan/"), m->modname)) { + const char *p = depname + strlen("ccan/") + strlen(m->modname); + /* And our own tests! */ + if (streq(p, "/test") || streq(p, "")) + return true; + /* But not any submodules; they need an explicit dep */ + } for (i = 0; deps[i]; i++) { if (streq(deps[i], depname)) { @@ -46,18 +50,17 @@ static bool check_dep_includes(struct manifest *m, for (i = 0; lines[i]; i++) { char *mod; - if (!strreg(f, lines[i], - "^[ \t]*#[ \t]*include[ \t]*[<\"]" - "(ccan/+.+)/+[^/]+\\.h", &mod)) + if (!tal_strreg(f, lines[i], + "^[ \t]*#[ \t]*include[ \t]*[<\"]" + "(ccan/+.+)/+[^/]+\\.[ch][\">]", &mod)) continue; if (has_dep(m, deps, used, mod)) continue; - /* FIXME: we can't be sure about - * conditional includes, so don't - * complain. */ - if (!li[i].cond) { + /* FIXME: we can't be sure about conditional includes, + * so don't complain (handle common case of idempotent wrap) */ + if (!li[i].cond || li[i].cond == f->idempotent_cond) { score_file_error(score, f, i+1, "%s not listed in _info", mod); ok = false; @@ -86,10 +89,10 @@ static void check_depends_accurate(struct manifest *m, get_or_compile_info); } - core_deps = talloc_array_length(deps) - 1; - test_deps = talloc_array_length(tdeps) - 1; + core_deps = tal_count(deps) - 1; + test_deps = tal_count(tdeps) - 1; - used = talloc_zero_array(m, bool, core_deps + test_deps + 1); + used = tal_arrz(m, bool, core_deps + test_deps + 1); foreach_ptr(list, &m->c_files, &m->h_files) { struct ccan_file *f; @@ -99,16 +102,15 @@ static void check_depends_accurate(struct manifest *m, } for (i = 0; i < core_deps; i++) { - if (!used[i]) + if (!used[i] && strstarts(deps[i], "ccan/")) score_file_error(score, m->info_file, 0, "%s is an unused dependency", deps[i]); } - /* Now append test dependencies to deps. */ - deps = talloc_realloc(NULL, deps, char *, - (core_deps + test_deps + 1) * sizeof(char *)); - memcpy(&deps[core_deps], tdeps, test_deps * sizeof(char *)); + /* Now remove NUL and append test dependencies to deps. */ + deps = tal_dup_arr(m, char *, take(deps), core_deps, test_deps + 2); + memcpy(deps + core_deps, tdeps, sizeof(tdeps[0]) * test_deps); /* ccan/tap is given a free pass. */ deps[core_deps + test_deps] = (char *)"ccan/tap"; deps[core_deps + test_deps + 1] = NULL; @@ -140,7 +142,7 @@ struct ccanlint depends_accurate = { .key = "depends_accurate", .name = "Module's CCAN dependencies are the only CCAN files #included", .check = check_depends_accurate, - .needs = "depends_exist test_depends_exist" + .needs = "depends_exist info_compiles test_depends_exist headers_idempotent" }; REGISTER_TEST(depends_accurate);