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