ccanlint: remove argument to -k/--keep
[ccan] / tools / ccanlint / tests / license_file_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_file_compat(struct manifest *m,
17                                       unsigned int *timeleft,
18                                       struct score *score)
19 {
20         struct list_head *list;
21
22         /* FIXME: Ignore unknown licenses for now. */
23         if (m->license == LICENSE_UNKNOWN) {
24                 score->pass = true;
25                 score->score = score->total = 0;
26                 return;
27         }
28
29         foreach_ptr(list, &m->c_files, &m->h_files) {
30                 struct ccan_file *f;
31
32                 list_for_each(list, f, list) {
33                         enum license l;
34
35                         /* Check they don't have boilerplate for incompatible
36                          * license! */
37                         for (l = 0; l < LICENSE_UNKNOWN; l++) {
38                                 if (!find_boilerplate(f, l))
39                                         continue;
40                                 if (license_compatible[m->license][l])
41                                         break;
42                                 score_file_error(score, f, 0,
43                                                  "Found boilerplate for license '%s' which is incompatible with '%s'",
44                                                  licenses[l].name,
45                                                  licenses[m->license].name);
46                                 break;
47                         }
48                 }
49         }
50
51         if (list_empty(&score->per_file_errors)) {
52                 score->pass = true;
53                 score->score = score->total;
54         }
55 }
56
57 struct ccanlint license_file_compat = {
58         .key = "license_file_compat",
59         .name = "Source files don't contain incompatible licenses",
60         .check = check_license_file_compat,
61         .needs = "license_exists"
62 };
63 REGISTER_TEST(license_file_compat);