depends_exist.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if (strrchr(updir, '/'))
  41. *strrchr(updir, '/') = '\0';
  42. if (safe_mode)
  43. deps = get_safe_ccan_deps(m, m->dir, true,
  44. &m->info_file->compiled);
  45. else
  46. deps = get_deps(m, m->dir, true, &m->info_file->compiled);
  47. for (i = 0; deps[i]; i++) {
  48. if (!strstarts(deps[i], "ccan/"))
  49. continue;
  50. if (!add_dep(m, deps[i], score))
  51. return;
  52. }
  53. /* We may need libtap for testing, unless we're "tap" */
  54. if (!streq(m->basename, "tap")
  55. && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
  56. if (!add_dep(m, "ccan/tap", score))
  57. return;
  58. }
  59. score->pass = true;
  60. score->score = score->total;
  61. }
  62. struct ccanlint depends_exist = {
  63. .key = "depends_exist",
  64. .name = "Module's CCAN dependencies can be found",
  65. .check = check_depends_exist,
  66. .needs = "info_exists"
  67. };
  68. REGISTER_TEST(depends_exist);