X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fmodule_builds.c;fp=tools%2Fccanlint%2Fcompulsory_tests%2Fmodule_builds.c;h=9d697a303a57399a1754da32db7dfc0c20d1ffa0;hb=051db34fb275491d4d5dfa5bf7970e8e525766d8;hp=0000000000000000000000000000000000000000;hpb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;p=ccan diff --git a/tools/ccanlint/compulsory_tests/module_builds.c b/tools/ccanlint/compulsory_tests/module_builds.c new file mode 100644 index 00000000..9d697a30 --- /dev/null +++ b/tools/ccanlint/compulsory_tests/module_builds.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "build.h" + +static const char *can_build(struct manifest *m) +{ + if (safe_mode) + return "Safe mode enabled"; + return NULL; +} + +static char *obj_list(const struct manifest *m) +{ + char *list = talloc_strdup(m, ""); + struct ccan_file *i; + + /* Objects from all the C files. */ + list_for_each(&m->c_files, i, list) + list = talloc_asprintf_append(list, "%s ", i->compiled); + + return list; +} + +char *build_module(struct manifest *m, bool keep, char **errstr) +{ + char *name = link_objects(m, m->basename, false, obj_list(m), errstr); + if (name) { + if (keep) { + char *realname = talloc_asprintf(m, "%s.o", m->dir); + /* We leave this object file around, all built. */ + if (!move_file(name, realname)) + err(1, "Renaming %s to %s", name, realname); + name = realname; + } + } + return name; +} + +static void do_build(struct manifest *m, + bool keep, + unsigned int *timeleft, + struct score *score) +{ + char *errstr; + + if (list_empty(&m->c_files)) { + /* No files? No score, but we "pass". */ + score->total = 0; + score->pass = true; + return; + } + + m->compiled = build_module(m, keep, &errstr); + if (!m->compiled) { + score_file_error(score, NULL, 0, errstr); + return; + } + + score->pass = true; + score->score = score->total; +} + +struct ccanlint module_builds = { + .key = "module_builds", + .name = "Module can be built from object files", + .check = do_build, + .can_run = can_build, + .needs = "objects_build" +}; + +REGISTER_TEST(module_builds);