]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/module_builds.c
ccanlint: remove argument to -k/--keep
[ccan] / tools / ccanlint / tests / module_builds.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 #include "build.h"
17
18 static const char *can_build(struct manifest *m)
19 {
20         if (safe_mode)
21                 return "Safe mode enabled";
22         return NULL;
23 }
24
25 static char *obj_list(const struct manifest *m, enum compile_type ctype)
26 {
27         char *list = talloc_strdup(m, "");
28         struct ccan_file *i;
29
30         /* Objects from all the C files. */
31         list_for_each(&m->c_files, i, list)
32                 list = talloc_asprintf_append(list, "%s ",
33                                               i->compiled[ctype]);
34
35         return list;
36 }
37
38 char *build_module(struct manifest *m,
39                    enum compile_type ctype, char **errstr)
40 {
41         return link_objects(m, m->basename, obj_list(m, ctype), errstr);
42 }
43
44 static void do_build(struct manifest *m,
45                      unsigned int *timeleft,
46                      struct score *score)
47 {
48         char *errstr;
49
50         if (list_empty(&m->c_files)) {
51                 /* No files?  No score, but we "pass". */
52                 score->total = 0;
53                 score->pass = true;
54                 return;
55         }
56
57         m->compiled[COMPILE_NORMAL]
58                 = build_module(m, COMPILE_NORMAL, &errstr);
59         if (!m->compiled[COMPILE_NORMAL]) {
60                 score_file_error(score, NULL, 0, "%s", errstr);
61                 return;
62         }
63
64         score->pass = true;
65         score->score = score->total;
66 }
67
68 struct ccanlint module_builds = {
69         .key = "module_builds",
70         .name = "Module can be built from object files",
71         .compulsory = true,
72         .check = do_build,
73         .can_run = can_build,
74         .needs = "objects_build"
75 };
76
77 REGISTER_TEST(module_builds);