depends_exist.c 2.0 KB

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