1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 static const char *can_build(struct manifest *m)
20 return "Safe mode enabled";
24 static struct ccan_file *main_header(struct manifest *m)
28 list_for_each(&m->h_files, f, list) {
29 if (strstarts(f->name, m->basename)
30 && strlen(f->name) == strlen(m->basename) + 2)
33 /* Should not happen: we depend on has_main_header */
37 static void check_includes_build(struct manifest *m,
38 unsigned int *timeleft, struct score *score)
41 char *tmpsrc, *tmpobj, *cmdout;
43 struct ccan_file *mainh = main_header(m);
45 tmpsrc = temp_file(m, "-included.c", mainh->fullname);
46 tmpobj = temp_file(m, ".o", tmpsrc);
48 fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
50 err(1, "Creating temporary file %s", tmpsrc);
52 contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
53 m->modname, m->basename);
54 if (write(fd, contents, strlen(contents)) != strlen(contents))
55 err(1, "writing to temporary file %s", tmpsrc);
58 if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
61 score->score = score->total;
63 score->error = talloc_asprintf(score,
64 "#include of the main header file:\n%s",
69 struct ccanlint main_header_compiles = {
70 .key = "main_header_compiles",
71 .name = "Modules main header compiles",
72 .check = check_includes_build,
74 .needs = "depends_exist main_header_exists"
77 REGISTER_TEST(main_header_compiles);