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 int cleanup_testfile(char *testfile)
30 static char *obj_list(const struct manifest *m)
32 char *list = talloc_strdup(m, "");
35 /* Other CCAN deps. */
36 list_for_each(&m->dep_objs, i, list)
37 list = talloc_asprintf_append(list, "%s ", i->name);
42 static char *lib_list(const struct manifest *m)
45 char **libs = get_libs(m, ".", ".", &num);
46 char *ret = talloc_strdup(m, "");
48 for (i = 0; i < num; i++)
49 ret = talloc_asprintf_append(ret, "-l %s ", libs[i]);
53 static void *check_use_build(struct manifest *m)
56 char *tmpfile, *outfile;
59 tmpfile = talloc_strdup(m, tempnam("/tmp", "ccanlint"));
60 talloc_set_destructor(tmpfile, cleanup_testfile);
61 outfile = talloc_strdup(m, tempnam("/tmp", "ccanlint"));
62 talloc_set_destructor(outfile, cleanup_testfile);
64 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
66 return talloc_asprintf(m, "Creating temporary file: %s",
69 contents = talloc_asprintf(tmpfile,
70 "#include <ccan/%s/%s.h>\n"
75 m->basename, m->basename);
76 if (write(fd, contents, strlen(contents)) != strlen(contents)) {
78 return "Failure writing to temporary file";
82 return run_command(m, "cc " CFLAGS " -o %s -x c %s -x none %s %s",
83 outfile, tmpfile, obj_list(m), lib_list(m));
86 static const char *describe_use_build(struct manifest *m, void *check_result)
88 return talloc_asprintf(check_result,
89 "Linking against module:\n"
90 "%s", (char *)check_result);
93 struct ccanlint check_build = {
94 .name = "Module can be used",
96 .check = check_use_build,
97 .describe = describe_use_build,
101 REGISTER_TEST(check_build, &build, NULL);