X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_depends_built.c;h=3bd82f830971ff4ec7eefcde5b4bb342d31b1390;hb=0a97f2dc1df96702dd88d4be169f43dd186c2bfa;hp=1392be910a3400c04d83744843c109023f1f3e96;hpb=5f44c8ca0eb66503db51e0df1b65ff173eb42f57;p=ccan diff --git a/tools/ccanlint/compulsory_tests/check_depends_built.c b/tools/ccanlint/compulsory_tests/check_depends_built.c index 1392be91..3bd82f83 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,82 +22,75 @@ 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) { - char *olddir; - struct manifest *dep_man; - bool has_c_files; - - olddir = talloc_getcwd(dir); - if (!olddir) - err(1, "Getting current directory"); + /* If it has C files, we expect an object file built from them. */ + return !list_empty(&m->c_files); +} - /* We will fail below if this doesn't exist. */ - if (chdir(dir) != 0) - return false; +static char *build_subdir_objs(struct manifest *m) +{ + struct ccan_file *i; - dep_man = get_manifest(dir); - if (chdir(olddir) != 0) - err(1, "Returning to original directory '%s'", olddir); - talloc_free(olddir); + list_for_each(&m->c_files, i, list) { + char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name); + char *output; - /* 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; + 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; } -static void *check_depends_built(struct manifest *m) +static void check_depends_built(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { - struct ccan_file *i; + struct manifest *i; struct stat st; - char *report = NULL; - list_for_each(&m->dep_dirs, i, list) { - char *objfile; + list_for_each(&m->deps, i, list) { + char *errstr; + if (!expect_obj_file(i)) + continue; - if (!expect_obj_file(i->name)) + i->compiled = talloc_asprintf(i, "%s.o", i->dir); + if (stat(i->compiled, &st) == 0) continue; - objfile = talloc_asprintf(m, "%s.o", i->name); - 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); - } - + if (verbose >= 2) + printf(" Building dependency %s\n", i->dir); + score->error = build_subdir_objs(i); + if (score->error) + return; + i->compiled = build_module(i, keep, &errstr); + if (!i->compiled) { + score->error = talloc_asprintf(score, + "Dependency %s" + " did not build:\n%s", + i->basename, errstr); + return; + } } - /* 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 (stat("../tap.o", &st) != 0) { - report = talloc_asprintf_append(report, - "object file ../tap.o" - " (for tests)\n"); - } + if (!score->error) { + score->pass = true; + score->score = score->total; } - - return talloc_steal(m, report); -} - -static const char *describe_depends_built(struct manifest *m, - void *check_result) -{ - return talloc_asprintf(check_result, - "The following dependencies are not built:\n" - "%s", (char *)check_result); } struct ccanlint depends_built = { - .name = "CCAN dependencies are built", - .total_score = 1, + .key = "depends-built", + .name = "Module's CCAN dependencies can be found or built", .check = check_depends_built, - .describe = describe_depends_built, .can_run = can_build, };