]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/build.c
ccanlint: use isspace instead of isblank
[ccan] / tools / ccanlint / compulsory_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 (safe_mode)
20                 return "Safe mode enabled";
21         return NULL;
22 }
23
24 static char *obj_list(const struct manifest *m)
25 {
26         char *list = talloc_strdup(m, "");
27         struct ccan_file *i;
28
29         /* Objects from all the C files. */
30         list_for_each(&m->c_files, i, list)
31                 list = talloc_asprintf_append(list, "%s ", i->compiled);
32
33         return list;
34 }
35
36 static void do_build(struct manifest *m,
37                      bool keep,
38                      unsigned int *timeleft,
39                      struct score *score)
40 {
41         char *filename, *errstr;
42
43         if (list_empty(&m->c_files)) {
44                 /* No files?  No score, but we "pass". */
45                 score->total = 0;
46                 score->pass = true;
47                 return;
48         }
49
50         filename = link_objects(m, m->basename, false, obj_list(m), &errstr);
51         if (!filename) {
52                 score->error = "The object file didn't build";
53                 score_file_error(score, NULL, 0, errstr);
54                 return;
55         }
56
57         if (keep) {
58                 char *realname = talloc_asprintf(m, "%s.o", m->dir);
59                 /* We leave this object file around, all built. */
60                 if (!move_file(filename, realname))
61                         err(1, "Renaming %s to %s", filename, realname);
62         }
63         score->pass = true;
64         score->score = score->total;
65 }
66
67 struct ccanlint build = {
68         .key = "build",
69         .name = "Module can be built from object files",
70         .check = do_build,
71         .can_run = can_build,
72 };
73
74 REGISTER_TEST(build, &depends_built, NULL);