license_file_compat.c 1.5 KB

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