tools: use tal instead of talloc.
[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 <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <limits.h>
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <err.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include "build.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 void build_objects(struct manifest *m,
25                    struct score *score, const char *flags,
26                    enum compile_type ctype)
27 {
28         struct ccan_file *i;
29         bool errors = false, warnings = false;
30
31         if (list_empty(&m->c_files))
32                 score->total = 0;
33         else
34                 score->total = 2;
35
36         list_for_each(&m->c_files, i, list) {
37                 char *output;
38                 char *fullfile = tal_fmt(m, "%s/%s", m->dir, i->name);
39
40                 i->compiled[ctype] = temp_file(m, "", fullfile);
41                 if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
42                                     i->compiled[ctype], &output)) {
43                         tal_free(i->compiled[ctype]);
44                         score_file_error(score, i, 0,
45                                          "Compiling object files:\n%s",
46                                          output);
47                         errors = true;
48                 } else if (!streq(output, "")) {
49                         score_file_error(score, i, 0,
50                                          "Compiling object files gave"
51                                          " warnings:\n%s",
52                                          output);
53                         warnings = true;
54                 }
55         }
56
57         if (!errors) {
58                 score->pass = true;
59                 score->score = score->total - warnings;
60         }
61 }
62
63 static void check_objs_build(struct manifest *m,
64                              unsigned int *timeleft, struct score *score)
65 {
66         build_objects(m, score, cflags, COMPILE_NORMAL);
67 }
68
69 struct ccanlint objects_build = {
70         .key = "objects_build",
71         .name = "Module object files can be built",
72         .compulsory = true,
73         .check = check_objs_build,
74         .can_run = can_build,
75         .needs = "depends_exist"
76 };
77
78 REGISTER_TEST(objects_build);