1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/grab_file/grab_file.h>
5 #include <ccan/str/str.h>
18 static const char *can_build(struct manifest *m)
21 return "Safe mode enabled";
25 static struct ccan_file *main_header(struct manifest *m)
29 list_for_each(&m->h_files, f, list) {
30 if (strstarts(f->name, m->basename)
31 && strlen(f->name) == strlen(m->basename) + 2)
34 /* Should not happen: we depend on has_main_header */
38 static void check_includes_build(struct manifest *m,
39 unsigned int *timeleft, struct score *score)
42 char *tmpsrc, *tmpobj, *cmdout;
44 struct ccan_file *mainh = main_header(m);
46 tmpsrc = temp_file(m, "-included.c", mainh->fullname);
47 tmpobj = temp_file(m, ".o", tmpsrc);
49 fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
51 err(1, "Creating temporary file %s", tmpsrc);
53 contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
54 m->basename, m->basename);
55 if (write(fd, contents, strlen(contents)) != strlen(contents))
56 err(1, "writing to temporary file %s", tmpsrc);
59 if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
62 score->score = score->total;
64 score->error = talloc_asprintf(score,
65 "#include of the main header file:\n%s",
70 struct ccanlint main_header_compiles = {
71 .key = "main_header_compiles",
72 .name = "Modules main header compiles",
73 .check = check_includes_build,
75 .needs = "depends_exist main_header_exists"
78 REGISTER_TEST(main_header_compiles);