X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_depends_exist.c;h=12eaf021410153c5567ea1abd22a98afa5ba0b51;hp=2ac60a2a556c8db27b309216399e496d986ea718;hb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;hpb=5f44c8ca0eb66503db51e0df1b65ff173eb42f57 diff --git a/tools/ccanlint/compulsory_tests/check_depends_exist.c b/tools/ccanlint/compulsory_tests/check_depends_exist.c index 2ac60a2a..12eaf021 100644 --- a/tools/ccanlint/compulsory_tests/check_depends_exist.c +++ b/tools/ccanlint/compulsory_tests/check_depends_exist.c @@ -14,60 +14,65 @@ #include #include -static char *add_dep(char *sofar, struct manifest *m, const char *dep) +static bool add_dep(struct manifest *m, const char *dep, struct score *score) { - char *dir; struct stat st; - struct ccan_file *f; + struct manifest *subm; + char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep); - dir = talloc_asprintf(m, "../%s", dep); + /* FIXME: get_manifest has a tendency to exit. */ if (stat(dir, &st) != 0) { - return talloc_asprintf_append(sofar, - "ccan/%s: expected it in" - " directory %s\n", - dep, dir); + score->error + = talloc_asprintf(m, + "Could not stat dependency %s: %s", + dir, strerror(errno)); + return false; } - - f = new_ccan_file(m, dir); - list_add_tail(&m->dep_dirs, &f->list); - return sofar; + subm = get_manifest(m, dir); + list_add_tail(&m->deps, &subm->list); + return true; } -static void *check_depends_exist(struct manifest *m) +static void check_depends_exist(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { unsigned int i; - char *report = NULL; char **deps; + char *updir = talloc_strdup(m, m->dir); + + *strrchr(updir, '/') = '\0'; if (safe_mode) - deps = get_safe_ccan_deps(m, "..", m->basename, true, + deps = get_safe_ccan_deps(m, m->dir, true, &m->info_file->compiled); else - deps = get_deps(m, "..", m->basename, true, - &m->info_file->compiled); + deps = get_deps(m, m->dir, true, &m->info_file->compiled); for (i = 0; deps[i]; i++) { if (!strstarts(deps[i], "ccan/")) continue; - report = add_dep(report, m, deps[i] + strlen("ccan/")); + if (!add_dep(m, deps[i], score)) + return; } - return report; -} -static const char *describe_depends_exist(struct manifest *m, - void *check_result) -{ - return talloc_asprintf(check_result, - "The following dependencies are are expected:\n" - "%s", (char *)check_result); + /* We may need libtap for testing, unless we're "tap" */ + if (!streq(m->basename, "tap") + && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) { + if (!add_dep(m, "ccan/tap", score)) + return; + } + + score->pass = true; + score->score = score->total; } struct ccanlint depends_exist = { - .name = "CCAN dependencies are present", - .total_score = 1, + .key = "depends_exist", + .name = "Module's CCAN dependencies can be found", .check = check_depends_exist, - .describe = describe_depends_exist, + .needs = "info_exists" }; -REGISTER_TEST(depends_exist, NULL); +REGISTER_TEST(depends_exist);