X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_includes_build.c;h=79d10d29775d65c7fa3a7e2695c113429ff17d35;hp=7e0ab945f290dfaaa83e373b3255520a4e61fc20;hb=6ceee26828dcb8bf1d607a8221f0d9f8261d448b;hpb=5f44c8ca0eb66503db51e0df1b65ff173eb42f57 diff --git a/tools/ccanlint/compulsory_tests/check_includes_build.c b/tools/ccanlint/compulsory_tests/check_includes_build.c index 7e0ab945..79d10d29 100644 --- a/tools/ccanlint/compulsory_tests/check_includes_build.c +++ b/tools/ccanlint/compulsory_tests/check_includes_build.c @@ -22,20 +22,37 @@ static const char *can_build(struct manifest *m) return NULL; } -static void *check_includes_build(struct manifest *m) +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 */ + return NULL; +} + +static void *check_includes_build(struct manifest *m, + bool keep, + unsigned int *timeleft) { 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)); + return talloc_asprintf(m, "Creating temporary file %s: %s", + tmpsrc, strerror(errno)); - 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); @@ -43,9 +60,7 @@ static void *check_includes_build(struct manifest *m) } close(fd); - if (compile_object(m, tmpfile, &err)) - return NULL; - return err; + return compile_object(m, tmpsrc, ccan_dir, "", tmpobj); } static const char *describe_includes_build(struct manifest *m, @@ -57,11 +72,12 @@ static const char *describe_includes_build(struct manifest *m, } struct ccanlint includes_build = { - .name = "Can compile against main header", + .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);