]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/license_depends_compat.c
c4f4cb7f98506bfdd40d2f1ffe895d95e71e0f88
[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                                          bool keep,
18                                          unsigned int *timeleft,
19                                          struct score *score)
20 {
21         struct manifest *i;
22
23         score->pass = true;
24
25         /* If our license is unknown, we can't know the answer. */
26         if (m->license == LICENSE_UNKNOWN) {
27                 score->score = score->total = 0;
28                 return;
29         }
30
31         list_for_each(&m->deps, i, list) {
32                 struct doc_section *d = find_license_tag(i);
33                 i->license = which_license(d);
34
35                 if (i->license != LICENSE_UNKNOWN
36                     && !license_compatible[m->license][i->license]) {
37                         score_file_error(score, i->info_file, 0,
38                                          "Dependency ccan/%s has"
39                                          " incompatible license '%s'",
40                                          i->basename,
41                                          licenses[i->license].name);
42                         score->pass = false;
43                 }
44         }
45
46         if (score->pass)
47                 score->score = score->total;
48 }
49
50 struct ccanlint license_depends_compat = {
51         .key = "license_depends_compat",
52         .name = "CCAN dependencies don't contain incompatible licenses",
53         .check = check_license_depends_compat,
54         .needs = "license_exists depends_exist"
55 };
56 REGISTER_TEST(license_depends_compat);