]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/build.c
Build tests for ccan.
[ccan] / tools / ccanlint / tests / build.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <limits.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <err.h>
14 #include <string.h>
15 #include <ctype.h>
16
17 static const char *can_build(struct manifest *m)
18 {
19         if (list_empty(&m->c_files))
20                 return "No C files in module";
21         if (safe_mode)
22                 return "Safe mode enabled";
23         return NULL;
24 }
25
26 static char *obj_list(const struct manifest *m)
27 {
28         char *list = talloc_strdup(m, "");
29         struct ccan_file *i;
30
31         /* Object from all the C files. */
32         list_for_each(&m->c_files, i, list)
33                 list = talloc_asprintf_append(list, "%.*s.o ",
34                                               strlen(i->name) - 2, i->name);
35
36         return list;
37 }
38
39 /* We leave this object file around after ccanlint runs, all built. */
40 static void *do_build(struct manifest *m)
41 {
42         return run_command(m, "ld -r -o ../%s.o %s", m->basename, obj_list(m));
43 }
44
45 static const char *describe_build(struct manifest *m, void *check_result)
46 {
47         return talloc_asprintf(check_result, 
48                                "The object file for the module didn't build:\n"
49                                "%s", (char *)check_result);
50 }
51
52 struct ccanlint build = {
53         .name = "Module can be built",
54         .total_score = 1,
55         .check = do_build,
56         .describe = describe_build,
57         .can_run = can_build,
58 };
59
60 REGISTER_TEST(build, &depends_built, NULL);