check_depends_built.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, struct score *score)
  36. {
  37. struct ccan_file *i;
  38. struct stat st;
  39. list_for_each(&m->dep_dirs, i, list) {
  40. if (!expect_obj_file(i->fullname))
  41. continue;
  42. i->compiled = talloc_asprintf(i, "%s.o", i->fullname);
  43. if (stat(i->compiled, &st) != 0) {
  44. score->error = "Dependencies are not built";
  45. score_file_error(score, i, 0,
  46. talloc_asprintf(score,
  47. "object file %s",
  48. i->compiled));
  49. i->compiled = NULL;
  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. score->error = talloc_asprintf(score,
  58. "tap object file not built");
  59. }
  60. }
  61. if (!score->error) {
  62. score->pass = true;
  63. score->score = score->total;
  64. }
  65. }
  66. struct ccanlint depends_built = {
  67. .key = "depends-built",
  68. .name = "Module's CCAN dependencies are already built",
  69. .check = check_depends_built,
  70. .can_run = can_build,
  71. };
  72. REGISTER_TEST(depends_built, &depends_exist, NULL);