check_depends_exist.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. &m->info_file->compiled);
  40. else
  41. deps = get_deps(m, "..", m->basename, true,
  42. &m->info_file->compiled);
  43. for (i = 0; deps[i]; i++) {
  44. if (!strstarts(deps[i], "ccan/"))
  45. continue;
  46. report = add_dep(report, m, deps[i] + strlen("ccan/"));
  47. }
  48. return report;
  49. }
  50. static const char *describe_depends_exist(struct manifest *m,
  51. void *check_result)
  52. {
  53. return talloc_asprintf(check_result,
  54. "The following dependencies are are expected:\n"
  55. "%s", (char *)check_result);
  56. }
  57. struct ccanlint depends_exist = {
  58. .name = "CCAN dependencies are present",
  59. .total_score = 1,
  60. .check = check_depends_exist,
  61. .describe = describe_depends_exist,
  62. };
  63. REGISTER_TEST(depends_exist, NULL);