license_comment.c 1.7 KB

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