X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fmain_header_compiles.c;fp=tools%2Fccanlint%2Ftests%2Fmain_header_compiles.c;h=99f3aa38855928e8611dc0967f4ff854a65e6ed9;hb=441a3cb13e428cfa4973d83acb68e231a7cd4cf4;hp=0000000000000000000000000000000000000000;hpb=c59407178991758de6541740f912578e33c7e50b;p=ccan diff --git a/tools/ccanlint/tests/main_header_compiles.c b/tools/ccanlint/tests/main_header_compiles.c new file mode 100644 index 00000000..99f3aa38 --- /dev/null +++ b/tools/ccanlint/tests/main_header_compiles.c @@ -0,0 +1,79 @@ +#include +#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 struct ccan_file *main_header(struct manifest *m) +{ + struct ccan_file *f; + + list_for_each(&m->h_files, f, list) { + if (strstarts(f->name, m->basename) + && strlen(f->name) == strlen(m->basename) + 2) + return f; + } + /* Should not happen: we depend on has_main_header */ + abort(); +} + +static void check_includes_build(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) +{ + char *contents; + char *tmpsrc, *tmpobj, *cmdout; + int fd; + struct ccan_file *mainh = main_header(m); + + tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname); + tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc); + + fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600); + if (fd < 0) + err(1, "Creating temporary file %s", tmpsrc); + + contents = talloc_asprintf(tmpsrc, "#include \n", + m->basename, m->basename); + if (write(fd, contents, strlen(contents)) != strlen(contents)) + err(1, "writing to temporary file %s", tmpsrc); + close(fd); + + if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags, + tmpobj, &cmdout)) { + score->pass = true; + score->score = score->total; + } else { + score->error = talloc_asprintf(score, + "#include of the main header file:\n%s", + cmdout); + } +} + +struct ccanlint main_header_compiles = { + .key = "main_header_compiles", + .name = "Modules main header compiles", + .check = check_includes_build, + .can_run = can_build, + .needs = "depends_exist main_header_exists" +}; + +REGISTER_TEST(main_header_compiles);