depends_exist.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /* FIXME: check this is still true once we reduce features. */
  34. static void check_depends_exist(struct manifest *m,
  35. unsigned int *timeleft, struct score *score)
  36. {
  37. unsigned int i;
  38. char **deps;
  39. char *updir = talloc_strdup(m, m->dir);
  40. bool needs_tap;
  41. if (strrchr(updir, '/'))
  42. *strrchr(updir, '/') = '\0';
  43. /* We may need libtap for testing, unless we're "tap" */
  44. if (streq(m->basename, "tap")) {
  45. needs_tap = false;
  46. } else if (list_empty(&m->run_tests) && list_empty(&m->api_tests)) {
  47. needs_tap = false;
  48. } else {
  49. needs_tap = true;
  50. }
  51. if (safe_mode)
  52. deps = get_safe_ccan_deps(m, m->dir, true);
  53. else
  54. deps = get_deps(m, m->dir, true, get_or_compile_info);
  55. for (i = 0; deps[i]; i++) {
  56. if (!strstarts(deps[i], "ccan/"))
  57. continue;
  58. if (!add_dep(m, deps[i], score))
  59. return;
  60. if (streq(deps[i], "ccan/tap")) {
  61. needs_tap = false;
  62. }
  63. }
  64. if (needs_tap && !add_dep(m, "ccan/tap", score)) {
  65. return;
  66. }
  67. score->pass = true;
  68. score->score = score->total;
  69. }
  70. struct ccanlint depends_exist = {
  71. .key = "depends_exist",
  72. .name = "Module's CCAN dependencies can be found",
  73. .compulsory = true,
  74. .check = check_depends_exist,
  75. .needs = "info_exists"
  76. };
  77. REGISTER_TEST(depends_exist);