check_depends_built.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. bool keep,
  35. unsigned int *timeleft)
  36. {
  37. struct ccan_file *i;
  38. struct stat st;
  39. char *report = NULL;
  40. list_for_each(&m->dep_dirs, i, list) {
  41. if (!expect_obj_file(i->fullname))
  42. continue;
  43. i->compiled = talloc_asprintf(i, "%s.o", i->fullname);
  44. if (stat(i->compiled, &st) != 0) {
  45. report = talloc_asprintf_append(report,
  46. "object file %s\n",
  47. i->compiled);
  48. i->compiled = NULL;
  49. }
  50. }
  51. /* We may need libtap for testing, unless we're "tap" */
  52. if (!streq(m->basename, "tap")
  53. && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
  54. char *tapobj = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir);
  55. if (stat(tapobj, &st) != 0) {
  56. report = talloc_asprintf_append(report,
  57. "object file %s"
  58. " (for tests)\n",
  59. tapobj);
  60. }
  61. }
  62. return talloc_steal(m, report);
  63. }
  64. static const char *describe_depends_built(struct manifest *m,
  65. void *check_result)
  66. {
  67. return talloc_asprintf(check_result,
  68. "The following dependencies are not built:\n"
  69. "%s", (char *)check_result);
  70. }
  71. struct ccanlint depends_built = {
  72. .key = "depends-built",
  73. .name = "Module's CCAN dependencies are already 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);