X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcheck_depends_built.c;fp=tools%2Fccanlint%2Ftests%2Fcheck_depends_built.c;h=02fa83b83a7e43774bf2e4a139ad6b488090a809;hb=61088f5c752c555172e2ab6cf93a7967f79f3f2c;hp=0000000000000000000000000000000000000000;hpb=3460418c419dfcc84316ad65497b0a00950480b9;p=ccan diff --git a/tools/ccanlint/tests/check_depends_built.c b/tools/ccanlint/tests/check_depends_built.c new file mode 100644 index 00000000..02fa83b8 --- /dev/null +++ b/tools/ccanlint/tests/check_depends_built.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *can_build(struct manifest *m) +{ + if (safe_mode) + return "Safe mode enabled"; + return NULL; +} + +/* FIXME: recursive ccanlint if they ask for it. */ +static bool expect_obj_file(const char *dir) +{ + char *olddir; + struct manifest *dep_man; + bool has_c_files; + + olddir = talloc_getcwd(dir); + if (!olddir) + err(1, "Getting current directory"); + + /* We will fail below if this doesn't exist. */ + if (chdir(dir) != 0) + return false; + + dep_man = get_manifest(dir); + if (chdir(olddir) != 0) + err(1, "Returning to original directory '%s'", olddir); + talloc_free(olddir); + + /* 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; +} + +static void *check_depends_built(struct manifest *m) +{ + struct ccan_file *i; + char *report = NULL; + + list_for_each(&m->dep_dirs, i, list) { + char *objfile; + struct stat st; + + if (!expect_obj_file(i->name)) + 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); + } + + } + 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, + .check = check_depends_built, + .describe = describe_depends_built, + .can_run = can_build, +}; + +REGISTER_TEST(depends_built, &depends_exist, NULL);