X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_includes_build.c;h=296b0a3961c10b93d2109ada855d21d2a570fddf;hb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;hp=b3e4ee682b87ce1db21cbfd9654229f80c796caa;hpb=fb4c4c3ddc24772f71a64ec02d2c9ddaeb6e9f6b;p=ccan diff --git a/tools/ccanlint/compulsory_tests/check_includes_build.c b/tools/ccanlint/compulsory_tests/check_includes_build.c index b3e4ee68..296b0a39 100644 --- a/tools/ccanlint/compulsory_tests/check_includes_build.c +++ b/tools/ccanlint/compulsory_tests/check_includes_build.c @@ -32,15 +32,15 @@ static struct ccan_file *main_header(struct manifest *m) return f; } /* Should not happen: we depend on has_main_header */ - return NULL; + abort(); } -static void *check_includes_build(struct manifest *m, - bool keep, - unsigned int *timeleft) +static void check_includes_build(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { char *contents; - char *tmpsrc, *tmpobj; + char *tmpsrc, *tmpobj, *cmdout; int fd; struct ccan_file *mainh = main_header(m); @@ -49,35 +49,30 @@ static void *check_includes_build(struct manifest *m, fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) - return talloc_asprintf(m, "Creating temporary file %s: %s", - tmpsrc, strerror(errno)); + 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)) { - 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); - return compile_object(m, tmpsrc, ccan_dir, tmpobj); -} - -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); + if (compile_object(score, tmpsrc, ccan_dir, "", 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 includes_build = { - .key = "include-main", +struct ccanlint main_header_compiles = { + .key = "main_header_compiles", .name = "Modules main header compiles", - .total_score = 1, .check = check_includes_build, - .describe = describe_includes_build, .can_run = can_build, + .needs = "depends_exist main_header_exists" }; -REGISTER_TEST(includes_build, &depends_exist, &has_main_header, NULL); +REGISTER_TEST(main_header_compiles);