license_file_compat.c 1.5 KB

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