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)
26 char *list = talloc_strdup(m, "");
29 /* Other CCAN deps. */
30 list_for_each(&m->deps, i, list) {
31 if (i->compiled[COMPILE_NORMAL])
32 list = talloc_asprintf_append(list, "%s ",
39 static char *lib_list(const struct manifest *m)
42 char **libs = get_libs(m, ".",
43 &num, &m->info_file->compiled[COMPILE_NORMAL]);
44 char *ret = talloc_strdup(m, "");
46 for (i = 0; i < num; i++)
47 ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
51 static void check_use_build(struct manifest *m,
53 unsigned int *timeleft, struct score *score)
56 char *tmpfile, *cmdout;
57 char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
60 tmpfile = maybe_temp_file(m, ".c", keep, basename);
62 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
64 err(1, "Creating temporary file %s", tmpfile);
66 contents = talloc_asprintf(tmpfile,
67 "#include <ccan/%s/%s.h>\n"
72 m->basename, m->basename);
73 if (write(fd, contents, strlen(contents)) != strlen(contents))
74 err(1, "Failure writing to temporary file %s", tmpfile);
77 if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
78 compiler, cflags, lib_list(m),
79 maybe_temp_file(m, "", keep, tmpfile),
82 score->score = score->total;
84 score->error = cmdout;
88 struct ccanlint module_links = {
89 .key = "module_links",
90 .name = "Module can be linked against trivial program",
91 .check = check_use_build,
93 .needs = "module_builds depends_build"
96 REGISTER_TEST(module_links);