summaryrefslogtreecommitdiff
path: root/tools/ccanlint/tests/license_file_compat.c
blob: 08cc31b9a1b2ddd66fbfe76f89b69b19d60b95fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <tools/ccanlint/ccanlint.h>
#include <ccan/foreach/foreach.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <ccan/str/str.h>

static void check_license_file_compat(struct manifest *m,
				      unsigned int *timeleft,
				      struct score *score)
{
	struct list_head *list;

	/* FIXME: Ignore unknown licenses for now. */
	if (m->license == LICENSE_UNKNOWN) {
		score->pass = true;
		score->score = score->total = 0;
		return;
	}

	foreach_ptr(list, &m->c_files, &m->h_files) {
		struct ccan_file *f;

		list_for_each(list, f, list) {
			enum license l;

			/* Check they don't have boilerplate for incompatible
			 * license! */
			for (l = 0; l < LICENSE_UNKNOWN; l++) {
				if (!find_boilerplate(f, l))
					continue;
				if (license_compatible[m->license][l])
					break;
				score_file_error(score, f, 0,
						 "Found boilerplate for license '%s' which is incompatible with '%s'",
						 licenses[l].name,
						 licenses[m->license].name);
				break;
			}
		}
	}

	if (list_empty(&score->per_file_errors)) {
		score->pass = true;
		score->score = score->total;
	}
}

struct ccanlint license_file_compat = {
	.key = "license_file_compat",
	.name = "Source files don't contain incompatible licenses",
	.check = check_license_file_compat,
	.needs = "license_exists"
};
REGISTER_TEST(license_file_compat);