]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/check_depends_built.c
Merge branch 'ronnie'
[ccan] / tools / ccanlint / compulsory_tests / check_depends_built.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 /* FIXME: recursive ccanlint if they ask for it. */
25 static bool expect_obj_file(const char *dir)
26 {
27         struct manifest *dep_man;
28         bool has_c_files;
29
30         dep_man = get_manifest(dir, dir);
31
32         /* If it has C files, we expect an object file built from them. */
33         has_c_files = !list_empty(&dep_man->c_files);
34         talloc_free(dep_man);
35         return has_c_files;
36 }
37
38 static void check_depends_built(struct manifest *m,
39                                 bool keep,
40                                 unsigned int *timeleft, struct score *score)
41 {
42         struct ccan_file *i;
43         struct stat st;
44
45         list_for_each(&m->dep_dirs, i, list) {
46                 if (!expect_obj_file(i->fullname))
47                         continue;
48
49                 i->compiled = talloc_asprintf(i, "%s.o", i->fullname);
50                 if (stat(i->compiled, &st) != 0) {
51                         score->error = "Dependencies are not built";
52                         score_file_error(score, i, 0,
53                                          talloc_asprintf(score,
54                                                         "object file %s",
55                                                          i->compiled));
56                         i->compiled = NULL;
57                 }                       
58         }
59
60         /* We may need libtap for testing, unless we're "tap" */
61         if (!streq(m->basename, "tap")
62             && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
63                 char *tapobj = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir);
64                 if (stat(tapobj, &st) != 0) {
65                         score->error = talloc_asprintf(score,
66                                                "tap object file not built");
67                 }
68         }
69
70         if (!score->error) {
71                 score->pass = true;
72                 score->score = score->total;
73         }
74 }
75
76 struct ccanlint depends_built = {
77         .key = "depends-built",
78         .name = "Module's CCAN dependencies are already built",
79         .check = check_depends_built,
80         .can_run = can_build,
81 };
82
83 REGISTER_TEST(depends_built, &depends_exist, NULL);