license_depends_compat.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_depends_compat(struct manifest *m,
  16. bool keep,
  17. unsigned int *timeleft,
  18. struct score *score)
  19. {
  20. struct manifest *i;
  21. score->pass = true;
  22. /* If our license is unknown, we can't know the answer. */
  23. if (m->license == LICENSE_UNKNOWN) {
  24. score->score = score->total = 0;
  25. return;
  26. }
  27. list_for_each(&m->deps, i, list) {
  28. struct doc_section *d = find_license_tag(i);
  29. i->license = which_license(d);
  30. if (i->license != LICENSE_UNKNOWN
  31. && !license_compatible[m->license][i->license]) {
  32. score_file_error(score, i->info_file, 0,
  33. "Dependency ccan/%s has"
  34. " incompatible license '%s'",
  35. i->basename,
  36. licenses[i->license].name);
  37. score->pass = false;
  38. }
  39. }
  40. if (score->pass)
  41. score->score = score->total;
  42. }
  43. struct ccanlint license_depends_compat = {
  44. .key = "license_depends_compat",
  45. .name = "CCAN dependencies don't contain incompatible licenses",
  46. .check = check_license_depends_compat,
  47. .needs = "license_exists depends_exist"
  48. };
  49. REGISTER_TEST(license_depends_compat);