]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/check_depends_exist.c
htable: rehash to clear delete markers
[ccan] / tools / ccanlint / compulsory_tests / check_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 char *add_dep(char *sofar, struct manifest *m, const char *dep)
18 {
19         struct stat st;
20         struct ccan_file *f;
21
22         f = new_ccan_file(m, ccan_dir, talloc_strdup(m, dep));
23         if (stat(f->fullname, &st) != 0) {
24                 return talloc_asprintf_append(sofar,
25                                               "ccan/%s: expected it in"
26                                               " directory %s\n",
27                                               dep, f->fullname);
28         }
29
30         list_add_tail(&m->dep_dirs, &f->list);
31         return sofar;
32 }
33
34 static void *check_depends_exist(struct manifest *m,
35                                  bool keep,
36                                  unsigned int *timeleft)
37 {
38         unsigned int i;
39         char *report = NULL;
40         char **deps;
41         char *updir = talloc_strdup(m, m->dir);
42
43         *strrchr(updir, '/') = '\0';
44
45         if (safe_mode)
46                 deps = get_safe_ccan_deps(m, m->dir, true,
47                                           &m->info_file->compiled);
48         else
49                 deps = get_deps(m, m->dir, true, &m->info_file->compiled);
50
51         for (i = 0; deps[i]; i++) {
52                 if (!strstarts(deps[i], "ccan/"))
53                         continue;
54
55                 report = add_dep(report, m, deps[i]);
56         }
57         return report;
58 }
59
60 static const char *describe_depends_exist(struct manifest *m,
61                                           void *check_result)
62 {
63         return talloc_asprintf(check_result,
64                                "The following dependencies are are expected:\n"
65                                "%s", (char *)check_result);
66 }
67
68 struct ccanlint depends_exist = {
69         .key = "depends-exist",
70         .name = "Module's CCAN dependencies are present",
71         .total_score = 1,
72         .check = check_depends_exist,
73         .describe = describe_depends_exist,
74 };
75
76 REGISTER_TEST(depends_exist, NULL);