]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/objects_build.c
d44b7e7464fd2410071697570fa9267a7de541bb
[ccan] / tools / ccanlint / tests / objects_build.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/tal/path/path.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 void build_objects(struct manifest *m,
26                    struct score *score, const char *flags,
27                    enum compile_type ctype)
28 {
29         struct ccan_file *i;
30         bool errors = false, warnings = false;
31
32         if (list_empty(&m->c_files))
33                 score->total = 0;
34         else
35                 score->total = 2;
36
37         list_for_each(&m->c_files, i, list) {
38                 char *output;
39                 char *fullfile = path_join(m, m->dir, i->name);
40
41                 i->compiled[ctype] = temp_file(m, "", fullfile);
42                 if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
43                                     i->compiled[ctype], &output)) {
44                         tal_free(i->compiled[ctype]);
45                         score_file_error(score, i, 0,
46                                          "Compiling object files:\n%s",
47                                          output);
48                         errors = true;
49                 } else if (!streq(output, "")) {
50                         score_file_error(score, i, 0,
51                                          "Compiling object files gave"
52                                          " warnings:\n%s",
53                                          output);
54                         warnings = true;
55                 }
56         }
57
58         if (!errors) {
59                 score->pass = true;
60                 score->score = score->total - warnings;
61         } else
62                 build_failed = true;
63 }
64
65 static void check_objs_build(struct manifest *m,
66                              unsigned int *timeleft, struct score *score)
67 {
68         build_objects(m, score, cflags, COMPILE_NORMAL);
69 }
70
71 struct ccanlint objects_build = {
72         .key = "objects_build",
73         .name = "Module object files can be built",
74         .compulsory = true,
75         .check = check_objs_build,
76         .can_run = can_build,
77         .needs = "depends_exist"
78 };
79
80 REGISTER_TEST(objects_build);