]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/license_depends_compat.c
ccanlint: make depends_accurate test more accurate.
[ccan] / tools / ccanlint / tests / license_depends_compat.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <ccan/foreach/foreach.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <limits.h>
8 #include <errno.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <err.h>
12 #include <ccan/talloc/talloc.h>
13 #include <ccan/str/str.h>
14 #include <ccan/str_talloc/str_talloc.h>
15
16 static void check_license_depends_compat(struct manifest *m,
17                                          unsigned int *timeleft,
18                                          struct score *score)
19 {
20         struct manifest *i;
21
22         score->pass = true;
23
24         /* If our license is unknown, we can't know the answer. */
25         if (m->license == LICENSE_UNKNOWN) {
26                 score->score = score->total = 0;
27                 return;
28         }
29
30         list_for_each(&m->deps, i, list) {
31                 struct doc_section *d = find_license_tag(i);
32                 i->license = which_license(d);
33
34                 if (i->license != LICENSE_UNKNOWN
35                     && !license_compatible[m->license][i->license]) {
36                         score_file_error(score, i->info_file, 0,
37                                          "Dependency ccan/%s has"
38                                          " incompatible license '%s'",
39                                          i->basename,
40                                          licenses[i->license].name);
41                         score->pass = false;
42                 }
43         }
44
45         if (score->pass)
46                 score->score = score->total;
47 }
48
49 struct ccanlint license_depends_compat = {
50         .key = "license_depends_compat",
51         .name = "CCAN dependencies don't contain incompatible licenses",
52         .check = check_license_depends_compat,
53         .needs = "license_exists depends_exist"
54 };
55 REGISTER_TEST(license_depends_compat);