check_depends_exist.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <limits.h>
  10. #include <errno.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <err.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. static bool add_dep(struct manifest *m, const char *dep, struct score *score)
  17. {
  18. struct stat st;
  19. struct manifest *subm;
  20. char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep);
  21. /* FIXME: get_manifest has a tendency to exit. */
  22. if (stat(dir, &st) != 0) {
  23. score->error
  24. = talloc_asprintf(m,
  25. "Could not stat dependency %s: %s",
  26. dir, strerror(errno));
  27. return false;
  28. }
  29. subm = get_manifest(m, dir);
  30. list_add_tail(&m->deps, &subm->list);
  31. return true;
  32. }
  33. static void check_depends_exist(struct manifest *m,
  34. bool keep,
  35. unsigned int *timeleft, struct score *score)
  36. {
  37. unsigned int i;
  38. char **deps;
  39. char *updir = talloc_strdup(m, m->dir);
  40. *strrchr(updir, '/') = '\0';
  41. if (safe_mode)
  42. deps = get_safe_ccan_deps(m, m->dir, true,
  43. &m->info_file->compiled);
  44. else
  45. deps = get_deps(m, m->dir, true, &m->info_file->compiled);
  46. for (i = 0; deps[i]; i++) {
  47. if (!strstarts(deps[i], "ccan/"))
  48. continue;
  49. if (!add_dep(m, deps[i], score))
  50. return;
  51. }
  52. /* We may need libtap for testing, unless we're "tap" */
  53. if (!streq(m->basename, "tap")
  54. && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
  55. if (!add_dep(m, "ccan/tap", score))
  56. return;
  57. }
  58. score->pass = true;
  59. score->score = score->total;
  60. }
  61. struct ccanlint depends_exist = {
  62. .key = "depends_exist",
  63. .name = "Module's CCAN dependencies can be found",
  64. .check = check_depends_exist,
  65. .needs = "info_exists"
  66. };
  67. REGISTER_TEST(depends_exist);