depends_exist.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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,
  55. &m->info_file->compiled[COMPILE_NORMAL]);
  56. for (i = 0; deps[i]; i++) {
  57. if (!strstarts(deps[i], "ccan/"))
  58. continue;
  59. if (!add_dep(m, deps[i], score))
  60. return;
  61. if (streq(deps[i], "ccan/tap")) {
  62. needs_tap = false;
  63. }
  64. }
  65. if (needs_tap && !add_dep(m, "ccan/tap", score)) {
  66. return;
  67. }
  68. score->pass = true;
  69. score->score = score->total;
  70. }
  71. struct ccanlint depends_exist = {
  72. .key = "depends_exist",
  73. .name = "Module's CCAN dependencies can be found",
  74. .compulsory = true,
  75. .check = check_depends_exist,
  76. .needs = "info_exists"
  77. };
  78. REGISTER_TEST(depends_exist);