X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fobjects_build.c;fp=tools%2Fccanlint%2Fcompulsory_tests%2Fobjects_build.c;h=13d34a14e041fb90b2fcbba7df020c06805aec31;hp=0000000000000000000000000000000000000000;hb=051db34fb275491d4d5dfa5bf7970e8e525766d8;hpb=2926cafb52b9d95646d9dafa877d53f2368d8b2c diff --git a/tools/ccanlint/compulsory_tests/objects_build.c b/tools/ccanlint/compulsory_tests/objects_build.c new file mode 100644 index 00000000..13d34a14 --- /dev/null +++ b/tools/ccanlint/compulsory_tests/objects_build.c @@ -0,0 +1,68 @@ +#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; +} + +static void check_objs_build(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) +{ + struct ccan_file *i; + bool errors = false, warnings = false; + + if (list_empty(&m->c_files)) + score->total = 0; + else + score->total = 2; + + list_for_each(&m->c_files, i, list) { + char *output; + char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name); + + i->compiled = maybe_temp_file(m, "", keep, fullfile); + if (!compile_object(score, fullfile, ccan_dir, "", i->compiled, + &output)) { + talloc_free(i->compiled); + score->error = "Compiling object files"; + score_file_error(score, i, 0, output); + errors = true; + } else if (!streq(output, "")) { + score->error = "Compiling object files gave warnings"; + score_file_error(score, i, 0, output); + warnings = true; + } + } + + if (!errors) { + score->pass = true; + score->score = score->total - warnings; + } +} + +struct ccanlint objects_build = { + .key = "objects_build", + .name = "Module object files can be built", + .check = check_objs_build, + .can_run = can_build, + .needs = "depends_exist" +}; + +REGISTER_TEST(objects_build);