check_depends_exist.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 char *add_dep(char *sofar, struct manifest *m, const char *dep)
  17. {
  18. char *dir;
  19. struct stat st;
  20. struct ccan_file *f;
  21. dir = talloc_asprintf(m, "../%s", dep);
  22. if (stat(dir, &st) != 0) {
  23. return talloc_asprintf_append(sofar,
  24. "ccan/%s: expected it in"
  25. " directory %s\n",
  26. dep, dir);
  27. }
  28. f = new_ccan_file(m, dir);
  29. list_add_tail(&m->dep_dirs, &f->list);
  30. return sofar;
  31. }
  32. static void *check_depends_exist(struct manifest *m)
  33. {
  34. unsigned int i;
  35. char *report = NULL;
  36. char **deps;
  37. if (safe_mode)
  38. deps = get_safe_ccan_deps(m, "..", m->basename, true);
  39. else
  40. deps = get_deps(m, "..", m->basename, true);
  41. for (i = 0; deps[i]; i++) {
  42. if (!strstarts(deps[i], "ccan/"))
  43. continue;
  44. report = add_dep(report, m, deps[i] + strlen("ccan/"));
  45. }
  46. return report;
  47. }
  48. static const char *describe_depends_exist(struct manifest *m,
  49. void *check_result)
  50. {
  51. return talloc_asprintf(check_result,
  52. "The following dependencies are are expected:\n"
  53. "%s", (char *)check_result);
  54. }
  55. struct ccanlint depends_exist = {
  56. .name = "CCAN dependencies are present",
  57. .total_score = 1,
  58. .check = check_depends_exist,
  59. .describe = describe_depends_exist,
  60. };
  61. REGISTER_TEST(depends_exist, NULL);