]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/build_objs.c
ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / compulsory_tests / build_objs.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 void check_objs_build(struct manifest *m,
25                              bool keep,
26                              unsigned int *timeleft, struct score *score)
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 = talloc_asprintf(m, "%s/%s", m->dir, i->name);
39
40                 i->compiled = maybe_temp_file(m, "", keep, fullfile);
41                 if (!compile_object(score, fullfile, ccan_dir, "", i->compiled,
42                                     &output)) {
43                         talloc_free(i->compiled);
44                         score->error = "Compiling object files";
45                         score_file_error(score, i, 0, output);
46                         errors = true;
47                 } else if (!streq(output, "")) {
48                         score->error = "Compiling object files gave warnings";
49                         score_file_error(score, i, 0, output);
50                         warnings = true;
51                 }
52         }
53
54         if (!errors) {
55                 score->pass = true;
56                 score->score = score->total - warnings;
57         }
58 }
59
60 struct ccanlint objects_build = {
61         .key = "objects_build",
62         .name = "Module object files can be built",
63         .check = check_objs_build,
64         .can_run = can_build,
65         .needs = "depends_exist"
66 };
67
68 REGISTER_TEST(objects_build);