check_depends_built.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 const char *can_build(struct manifest *m)
  17. {
  18. if (safe_mode)
  19. return "Safe mode enabled";
  20. return NULL;
  21. }
  22. /* FIXME: recursive ccanlint if they ask for it. */
  23. static bool expect_obj_file(const char *dir)
  24. {
  25. struct manifest *dep_man;
  26. bool has_c_files;
  27. dep_man = get_manifest(dir, dir);
  28. /* If it has C files, we expect an object file built from them. */
  29. has_c_files = !list_empty(&dep_man->c_files);
  30. talloc_free(dep_man);
  31. return has_c_files;
  32. }
  33. static void *check_depends_built(struct manifest *m)
  34. {
  35. struct ccan_file *i;
  36. struct stat st;
  37. char *report = NULL;
  38. list_for_each(&m->dep_dirs, i, list) {
  39. char *objfile;
  40. if (!expect_obj_file(i->fullname))
  41. continue;
  42. objfile = talloc_asprintf(m, "%s.o", i->fullname);
  43. if (stat(objfile, &st) != 0) {
  44. report = talloc_asprintf_append(report,
  45. "object file %s\n",
  46. objfile);
  47. } else {
  48. struct ccan_file *f = new_ccan_file(m, "", objfile);
  49. list_add_tail(&m->dep_objs, &f->list);
  50. }
  51. }
  52. /* We may need libtap for testing, unless we're "tap" */
  53. if (!streq(m->basename, "tap")
  54. && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
  55. char *tapobj = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir);
  56. if (stat(tapobj, &st) != 0) {
  57. report = talloc_asprintf_append(report,
  58. "object file %s"
  59. " (for tests)\n",
  60. tapobj);
  61. }
  62. }
  63. return talloc_steal(m, report);
  64. }
  65. static const char *describe_depends_built(struct manifest *m,
  66. void *check_result)
  67. {
  68. return talloc_asprintf(check_result,
  69. "The following dependencies are not built:\n"
  70. "%s", (char *)check_result);
  71. }
  72. struct ccanlint depends_built = {
  73. .name = "CCAN dependencies are built",
  74. .total_score = 1,
  75. .check = check_depends_built,
  76. .describe = describe_depends_built,
  77. .can_run = can_build,
  78. };
  79. REGISTER_TEST(depends_built, &depends_exist, NULL);