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 char *obj_list(const struct manifest *m)
29 if (m->compiled[COMPILE_NORMAL])
30 list = talloc_strdup(m, m->compiled[COMPILE_NORMAL]);
32 list = talloc_strdup(m, "");
34 /* Other CCAN deps. */
35 list_for_each(&m->deps, i, list) {
36 if (i->compiled[COMPILE_NORMAL])
37 list = talloc_asprintf_append(list, " %s",
44 static char *lib_list(const struct manifest *m)
48 char *ret = talloc_strdup(m, "");
50 libs = get_libs(m, m->dir, true, get_or_compile_info);
51 for (i = 0; libs[i]; i++)
52 ret = talloc_asprintf_append(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;
61 char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
64 tmpfile = temp_file(m, ".c", basename);
66 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
68 err(1, "Creating temporary file %s", tmpfile);
70 contents = talloc_asprintf(tmpfile,
71 "#include <ccan/%s/%s.h>\n"
76 m->basename, m->basename);
77 if (write(fd, contents, strlen(contents)) != strlen(contents))
78 err(1, "Failure writing to temporary file %s", tmpfile);
81 if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
82 compiler, cflags, lib_list(m),
83 temp_file(m, "", tmpfile),
86 score->score = score->total;
88 score->error = cmdout;
92 struct ccanlint module_links = {
93 .key = "module_links",
94 .name = "Module can be linked against trivial program",
95 .check = check_use_build,
97 .needs = "module_builds depends_build"
100 REGISTER_TEST(module_links);