depends_exist.c 1.8 KB

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