]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: check for incompatible license boilerplates within subfiles.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 21 Jul 2011 04:59:03 +0000 (14:29 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 21 Jul 2011 04:59:03 +0000 (14:29 +0930)
This checks to make sure you're not accidentally relicensing code;
eg. it's OK (though a bit impolite) to turn a BSD-licensed file into a
GPL module, but not the other way around.

tools/ccanlint/licenses.c
tools/ccanlint/licenses.h
tools/ccanlint/tests/license_file_compat.c [new file with mode: 0644]

index 9bfa1d2b8d57b3bb005fccc653ba4d209cebf5c8..c2a4871d6c3ae2467b37ef105ae671c4339652d8 100644 (file)
@@ -72,6 +72,36 @@ const struct license_info licenses[] = {
        },
 };
 
        },
 };
 
+/* License compatibilty chart (simplified: we don't test that licenses between
+ * files are compatible). */
+bool license_compatible[LICENSE_UNKNOWN+1][LICENSE_UNKNOWN] = {
+/*       LGPL2+ LGPL2 LGPL3 LGPL  GPL2+ GPL2  GPL3  GPL   BSD   MIT   PD   */
+/* _info says: LGPL2+ */
+       { true, false,false,true, false,false,false,false,true, true, true },
+/* _info says: LGPL2 only */
+       { true, true, false,true, false,false,false,false,true, true, true },
+/* _info says: LGPL3 (or any later version) */
+       { true, false,true, true, false,false,false,false,true, true, true },
+/* _info says: LGPL (no version specified) */
+       { true, true, true, true, false,false,false,false,true, true, true },
+/* _info says: GPL2+ */
+       { true, true, true, true, true, false,false,true, true, true, true },
+/* _info says: GPL2 only */
+       { true, true, true, true, true, true, false,true, true, true, true },
+/* _info says: GPL3 (or any later version) */
+       { true, true, true, true, true, false,true, true, true, true, true },
+/* _info says: GPL (unknown version) */
+       { true, true, true, true, true, true, true, true, true, true, true },
+/* _info says: BSD (3-clause) */
+       { false,false,false,false,false,false,false,false,true, true, true },
+/* _info says: MIT */
+       { false,false,false,false,false,false,false,false,false,true, true },
+/* _info says: Public domain */
+       { false,false,false,false,false,false,false,false,false,false,true },
+/* _info says something we don't understand */
+       { false,false,false,false,false,false,false,false,false,false,true }
+};
+
 const char *get_ccan_simplified(struct ccan_file *f)
 {
        if (!f->simplified) {
 const char *get_ccan_simplified(struct ccan_file *f)
 {
        if (!f->simplified) {
index 7b70bfac2109f2279c417738b49a1b3463abdd53..72b14d2516a47ba3faa030f0f937e9640c9ed5b1 100644 (file)
@@ -26,6 +26,9 @@ struct license_info {
        const char *clause[NUM_CLAUSES];
 };
 
        const char *clause[NUM_CLAUSES];
 };
 
+/* Is [project license][file license] compatible? */
+bool license_compatible[LICENSE_UNKNOWN+1][LICENSE_UNKNOWN];
+
 extern const struct license_info licenses[];
 
 struct ccan_file;
 extern const struct license_info licenses[];
 
 struct ccan_file;
diff --git a/tools/ccanlint/tests/license_file_compat.c b/tools/ccanlint/tests/license_file_compat.c
new file mode 100644 (file)
index 0000000..d1834c0
--- /dev/null
@@ -0,0 +1,64 @@
+#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/talloc/talloc.h>
+#include <ccan/str/str.h>
+#include <ccan/str_talloc/str_talloc.h>
+
+static void check_license_file_compat(struct manifest *m,
+                                     bool keep,
+                                     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 0;
+       }
+
+       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);