X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Flicense_file_compat.c;fp=tools%2Fccanlint%2Ftests%2Flicense_file_compat.c;h=d1834c06452aec0146199ccc79ca12dda1fd5801;hb=4c1a5ebd8720c26e264c89f8256df02a93db683a;hp=0000000000000000000000000000000000000000;hpb=e67de75f0d64096956ad40ecb09462dac6fc5f03;p=ccan diff --git a/tools/ccanlint/tests/license_file_compat.c b/tools/ccanlint/tests/license_file_compat.c new file mode 100644 index 00000000..d1834c06 --- /dev/null +++ b/tools/ccanlint/tests/license_file_compat.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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);