license_file_compat.c 1.4 KB

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