]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/depends_exist.c
ccanlint: remove argument to -k/--keep
[ccan] / tools / ccanlint / tests / depends_exist.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 bool add_dep(struct manifest *m, const char *dep, struct score *score)
18 {
19         struct stat st;
20         struct manifest *subm;
21         char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep);
22
23         /* FIXME: get_manifest has a tendency to exit. */
24         if (stat(dir, &st) != 0) {
25                 score->error
26                         = talloc_asprintf(m,
27                                           "Could not stat dependency %s: %s",
28                                           dir, strerror(errno));
29                 return false;
30         }
31         subm = get_manifest(m, dir);
32         list_add_tail(&m->deps, &subm->list);
33         return true;
34 }
35
36 /* FIXME: check this is still true once we reduce features. */
37 static void check_depends_exist(struct manifest *m,
38                                 unsigned int *timeleft, struct score *score)
39 {
40         unsigned int i;
41         char **deps;
42         char *updir = talloc_strdup(m, m->dir);
43         bool needs_tap;
44
45         if (strrchr(updir, '/'))
46                 *strrchr(updir, '/') = '\0';
47
48         /* We may need libtap for testing, unless we're "tap" */
49         if (streq(m->basename, "tap")) {
50                 needs_tap = false;
51         } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
52                 needs_tap = false;
53         } else {
54                 needs_tap = true;
55         }
56
57         if (safe_mode)
58                 deps = get_safe_ccan_deps(m, m->dir, true);
59         else
60                 deps = get_deps(m, m->dir, true,
61                                 &m->info_file->compiled[COMPILE_NORMAL]);
62
63         for (i = 0; deps[i]; i++) {
64                 if (!strstarts(deps[i], "ccan/"))
65                         continue;
66
67                 if (!add_dep(m, deps[i], score))
68                         return;
69
70                 if (streq(deps[i], "ccan/tap")) {
71                         needs_tap = false;
72                 }
73         }
74
75         if (needs_tap && !add_dep(m, "ccan/tap", score)) {
76                 return;
77         }
78
79         score->pass = true;
80         score->score = score->total;
81 }
82
83 struct ccanlint depends_exist = {
84         .key = "depends_exist",
85         .name = "Module's CCAN dependencies can be found",
86         .compulsory = true,
87         .check = check_depends_exist,
88         .needs = "info_exists"
89 };
90
91 REGISTER_TEST(depends_exist);