license_comment.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_comment(struct manifest *m,
  16. bool keep,
  17. unsigned int *timeleft, struct score *score)
  18. {
  19. struct list_head *list;
  20. /* No requirements on public domain. */
  21. if (m->license == LICENSE_PUBLIC_DOMAIN
  22. || m->license == LICENSE_UNKNOWN) {
  23. score->pass = true;
  24. score->score = score->total;
  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. unsigned int i;
  31. char **lines = get_ccan_file_lines(f);
  32. struct line_info *info = get_ccan_line_info(f);
  33. bool found_license = false, found_flavor = false;
  34. for (i = 0; lines[i]; i++) {
  35. if (info[i].type == CODE_LINE)
  36. break;
  37. if (strstr(lines[i], "LICENSE"))
  38. found_license = true;
  39. if (strstr(lines[i],
  40. licenses[m->license].shortname))
  41. found_flavor = true;
  42. }
  43. if ((!found_license || !found_flavor)
  44. && !find_boilerplate(f, m->license)) {
  45. score_file_error(score, f, lines[i] ? i : 0,
  46. "No reference to license"
  47. " found");
  48. }
  49. }
  50. }
  51. if (list_empty(&score->per_file_errors)) {
  52. score->pass = true;
  53. score->score = score->total;
  54. }
  55. }
  56. struct ccanlint license_comment = {
  57. .key = "license_comment",
  58. .name = "Source and header files refer to LICENSE",
  59. .check = check_license_comment,
  60. .needs = "license_exists"
  61. };
  62. REGISTER_TEST(license_comment);