X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_depends_built.c;h=41b9a8cae3ff19d28b106501a7fb46d0213aa7da;hp=854f4bc8fe40443cc86bed5b30f3519281218ab9;hb=f9423c171395571f9880286190d9cf63da147668;hpb=f952b88b36e3803370825fb43385f1a42aa24b64 diff --git a/tools/ccanlint/compulsory_tests/check_depends_built.c b/tools/ccanlint/compulsory_tests/check_depends_built.c index 854f4bc8..41b9a8ca 100644 --- a/tools/ccanlint/compulsory_tests/check_depends_built.c +++ b/tools/ccanlint/compulsory_tests/check_depends_built.c @@ -13,6 +13,7 @@ #include #include #include +#include "build.h" static const char *can_build(struct manifest *m) { @@ -21,73 +22,88 @@ static const char *can_build(struct manifest *m) return NULL; } -/* FIXME: recursive ccanlint if they ask for it. */ -static bool expect_obj_file(const char *dir) +static bool expect_obj_file(struct manifest *m) { - struct manifest *dep_man; - bool has_c_files; - - dep_man = get_manifest(dir, dir); - /* If it has C files, we expect an object file built from them. */ - has_c_files = !list_empty(&dep_man->c_files); - talloc_free(dep_man); - return has_c_files; + return !list_empty(&m->c_files); } -static void *check_depends_built(struct manifest *m) +static char *build_subdir_objs(struct manifest *m) { struct ccan_file *i; - struct stat st; - char *report = NULL; - - list_for_each(&m->dep_dirs, i, list) { - char *objfile; - - if (!expect_obj_file(i->fullname)) - continue; - - objfile = talloc_asprintf(m, "%s.o", i->fullname); - if (stat(objfile, &st) != 0) { - report = talloc_asprintf_append(report, - "object file %s\n", - objfile); - } else { - struct ccan_file *f = new_ccan_file(m, "", objfile); - list_add_tail(&m->dep_objs, &f->list); - } - - } - /* 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))) { - char *tapobj = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir); - if (stat(tapobj, &st) != 0) { - report = talloc_asprintf_append(report, - "object file %s" - " (for tests)\n", - tapobj); + list_for_each(&m->c_files, i, list) { + char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name); + char *output; + + i->compiled = maybe_temp_file(m, "", false, fullfile); + if (!compile_object(m, fullfile, ccan_dir, "", i->compiled, + &output)) { + talloc_free(i->compiled); + i->compiled = NULL; + return talloc_asprintf(m, + "Dependency %s" + " did not build:\n%s", + m->basename, output); } } + return NULL; +} + +char *build_submodule(struct manifest *m) +{ + char *errstr; + struct stat st; - return talloc_steal(m, report); + if (m->compiled) + return NULL; + + if (!expect_obj_file(m)) + return NULL; + + m->compiled = talloc_asprintf(m, "%s.o", m->dir); + if (stat(m->compiled, &st) == 0) + return NULL; + + if (verbose >= 2) + printf(" Building dependency %s\n", m->dir); + + errstr = build_subdir_objs(m); + if (errstr) + return errstr; + + m->compiled = build_module(m, false, &errstr); + if (!m->compiled) + return errstr; + return NULL; } -static const char *describe_depends_built(struct manifest *m, - void *check_result) +static void check_depends_built(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { - return talloc_asprintf(check_result, - "The following dependencies are not built:\n" - "%s", (char *)check_result); + struct manifest *i; + + list_for_each(&m->deps, i, list) { + char *errstr = build_submodule(i); + + if (errstr) { + score->error = talloc_asprintf(score, + "Dependency %s" + " did not build:\n%s", + i->basename, errstr); + return; + } + } + + score->pass = true; + score->score = score->total; } struct ccanlint depends_built = { - .key = "depends-built", - .name = "CCAN dependencies are built", - .total_score = 1, + .key = "depends_build", + .name = "Module's CCAN dependencies can be found or built", .check = check_depends_built, - .describe = describe_depends_built, .can_run = can_build, };