X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_includes_build.c;h=cc5edc4ccaabbf2525b9072a4e64da3ceef6d02f;hp=f50e54300940f7a54526ba0e7c9084de0ea05e96;hb=8566131a68d4e0e5e10a5179bd50e18106ac646d;hpb=304652023042670b3173de0ad5dc0eb7c836618c diff --git a/tools/ccanlint/compulsory_tests/check_includes_build.c b/tools/ccanlint/compulsory_tests/check_includes_build.c index f50e5430..cc5edc4c 100644 --- a/tools/ccanlint/compulsory_tests/check_includes_build.c +++ b/tools/ccanlint/compulsory_tests/check_includes_build.c @@ -22,47 +22,57 @@ static const char *can_build(struct manifest *m) return NULL; } -static void *check_includes_build(struct manifest *m, unsigned int *timeleft) +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 *tmpfile, *err; + char *tmpsrc, *tmpobj; int fd; + struct ccan_file *mainh = main_header(m); - tmpfile = temp_file(m, ".c"); + tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname); + tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc); - fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600); + fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) - return talloc_asprintf(m, "Creating temporary file: %s", - strerror(errno)); + err(1, "Creating temporary file %s", tmpsrc); - contents = talloc_asprintf(tmpfile, "#include \n", + contents = talloc_asprintf(tmpsrc, "#include \n", m->basename, m->basename); - if (write(fd, contents, strlen(contents)) != strlen(contents)) { - close(fd); - return "Failure writing to temporary file"; - } + if (write(fd, contents, strlen(contents)) != strlen(contents)) + err(1, "writing to temporary file %s", tmpsrc); close(fd); - if (compile_object(m, tmpfile, ccan_dir, &err)) - return NULL; - return err; -} - -static const char *describe_includes_build(struct manifest *m, - void *check_result) -{ - return talloc_asprintf(check_result, - "#include of the main header file:\n" - "%s", (char *)check_result); + score->error = compile_object(m, tmpsrc, ccan_dir, "", tmpobj); + if (score->error) { + score->error = talloc_asprintf(score, + "#include of the main header file:\n%s", + score->error); + } else { + score->pass = true; + score->score = score->total; + } } struct ccanlint includes_build = { .key = "include-main", .name = "Modules main header compiles", - .total_score = 1, .check = check_includes_build, - .describe = describe_includes_build, .can_run = can_build, }; -REGISTER_TEST(includes_build, &depends_exist, NULL); +REGISTER_TEST(includes_build, &depends_exist, &has_main_header, NULL);