license_comment.c 1.6 KB

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