1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/take/take.h>
17 static const char *can_build(struct manifest *m)
20 return "Safe mode enabled";
24 static char *obj_list(const struct manifest *m)
29 if (m->compiled[COMPILE_NORMAL])
30 list = tal_strdup(m, m->compiled[COMPILE_NORMAL]);
32 list = tal_strdup(m, "");
34 /* Other CCAN deps. */
35 list_for_each(&m->deps, i, list) {
36 if (!i->compiled[COMPILE_NORMAL])
38 list = tal_strcat(m, take(list), " ");
39 list = tal_strcat(m, take(list), i->compiled[COMPILE_NORMAL]);
44 static char *lib_list(const struct manifest *m)
48 char *ret = tal_strdup(m, "");
50 libs = get_libs(m, m->dir, "depends", get_or_compile_info);
51 for (i = 0; libs[i]; i++)
52 tal_append_fmt(&ret, "-l%s ", libs[i]);
56 static void check_use_build(struct manifest *m,
57 unsigned int *timeleft, struct score *score)
60 char *tmpfile, *cmdout;
63 tmpfile = temp_file(m, ".c", "example.c");
65 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
67 err(1, "Creating temporary file %s", tmpfile);
69 contents = tal_fmt(tmpfile,
70 "#include <ccan/%s/%s.h>\n"
75 m->modname, m->basename);
76 if (write(fd, contents, strlen(contents)) != strlen(contents))
77 err(1, "Failure writing to temporary file %s", tmpfile);
80 if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
81 compiler, cflags, lib_list(m),
82 temp_file(m, "", tmpfile),
85 score->score = score->total;
87 score->error = cmdout;
91 struct ccanlint module_links = {
92 .key = "module_links",
93 .name = "Module can be linked against trivial program",
94 .check = check_use_build,
96 .needs = "module_builds depends_build"
99 REGISTER_TEST(module_links);