depends_accurate.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/talloc/talloc.h>
  4. #include <ccan/str/str.h>
  5. #include <ccan/str_talloc/str_talloc.h>
  6. #include <ccan/foreach/foreach.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <unistd.h>
  11. #include <limits.h>
  12. #include <errno.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <err.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. static bool has_dep(struct manifest *m, const char *depname)
  19. {
  20. struct manifest *i;
  21. /* We can include ourselves, of course. */
  22. if (streq(depname, m->basename))
  23. return true;
  24. list_for_each(&m->deps, i, list) {
  25. if (streq(i->basename, depname))
  26. return true;
  27. }
  28. return false;
  29. }
  30. static void check_depends_accurate(struct manifest *m,
  31. unsigned int *timeleft, struct score *score)
  32. {
  33. struct list_head *list;
  34. foreach_ptr(list, &m->c_files, &m->h_files,
  35. &m->run_tests, &m->api_tests,
  36. &m->compile_ok_tests, &m->compile_fail_tests,
  37. &m->other_test_c_files) {
  38. struct ccan_file *f;
  39. list_for_each(list, f, list) {
  40. unsigned int i;
  41. char **lines = get_ccan_file_lines(f);
  42. struct line_info *li = get_ccan_line_info(f);
  43. for (i = 0; lines[i]; i++) {
  44. char *mod;
  45. if (!strreg(f, lines[i],
  46. "^[ \t]*#[ \t]*include[ \t]*[<\"]"
  47. "ccan/+([^/]+)/", &mod))
  48. continue;
  49. if (has_dep(m, mod))
  50. continue;
  51. /* FIXME: we can't be sure about
  52. * conditional includes, so don't
  53. * complain. */
  54. if (!li[i].cond) {
  55. score_file_error(score, f, i+1,
  56. "%s not listed in _info",
  57. mod);
  58. }
  59. }
  60. }
  61. }
  62. if (!score->error) {
  63. score->score = score->total;
  64. score->pass = true;
  65. }
  66. }
  67. struct ccanlint depends_accurate = {
  68. .key = "depends_accurate",
  69. .name = "Module's CCAN dependencies are the only CCAN files #included",
  70. .check = check_depends_accurate,
  71. .needs = "depends_exist"
  72. };
  73. REGISTER_TEST(depends_accurate);