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