depends_accurate.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. bool keep,
  32. unsigned int *timeleft, struct score *score)
  33. {
  34. struct list_head *list;
  35. /* FIXME: This isn't reliable enough with #ifdefs, so we don't fail. */
  36. score->pass = true;
  37. foreach_ptr(list, &m->c_files, &m->h_files,
  38. &m->run_tests, &m->api_tests,
  39. &m->compile_ok_tests, &m->compile_fail_tests,
  40. &m->other_test_c_files) {
  41. struct ccan_file *f;
  42. list_for_each(list, f, list) {
  43. unsigned int i;
  44. char **lines = get_ccan_file_lines(f);
  45. for (i = 0; lines[i]; i++) {
  46. char *mod;
  47. if (!strreg(f, lines[i],
  48. "^[ \t]*#[ \t]*include[ \t]*[<\"]"
  49. "ccan/+([^/]+)/", &mod))
  50. continue;
  51. if (has_dep(m, mod))
  52. continue;
  53. score_file_error(score, f, i+1,
  54. "%s not listed in _info",
  55. mod);
  56. }
  57. }
  58. }
  59. if (!score->error) {
  60. score->score = score->total;
  61. }
  62. }
  63. struct ccanlint depends_accurate = {
  64. .key = "depends_accurate",
  65. .name = "Module's CCAN dependencies are the only CCAN files #included",
  66. .check = check_depends_accurate,
  67. .needs = "depends_exist"
  68. };
  69. REGISTER_TEST(depends_accurate);