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 *cflags_list(const struct manifest *m)
47 char *ret = tal_strdup(m, cflags);
49 char **flags = get_cflags(m, m->dir, get_or_compile_info);
50 for (i = 0; flags[i]; i++)
51 tal_append_fmt(&ret, " %s", flags[i]);
55 static char *lib_list(const struct manifest *m)
59 char *ret = tal_strdup(m, "");
61 libs = get_libs(m, m->dir, "depends", get_or_compile_info);
62 for (i = 0; libs[i]; i++)
63 tal_append_fmt(&ret, "-l%s ", libs[i]);
67 static void check_use_build(struct manifest *m,
68 unsigned int *timeleft, struct score *score)
71 char *tmpfile, *cmdout;
75 tmpfile = temp_file(m, ".c", "example.c");
77 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
79 err(1, "Creating temporary file %s", tmpfile);
81 contents = tal_fmt(tmpfile,
82 "#include <ccan/%s/%s.h>\n"
87 m->modname, m->basename);
88 if (write(fd, contents, strlen(contents)) != strlen(contents))
89 err(1, "Failure writing to temporary file %s", tmpfile);
92 flags = cflags_list(m);
94 if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
95 compiler, flags, lib_list(m),
96 temp_file(m, "", tmpfile),
99 score->score = score->total;
101 score->error = cmdout;
105 struct ccanlint module_links = {
106 .key = "module_links",
107 .name = "Module can be linked against trivial program",
108 .check = check_use_build,
109 .can_run = can_build,
110 .needs = "module_builds depends_build"
113 REGISTER_TEST(module_links);