check_depends_built.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "build.h"
  17. static const char *can_build(struct manifest *m)
  18. {
  19. if (safe_mode)
  20. return "Safe mode enabled";
  21. return NULL;
  22. }
  23. static bool expect_obj_file(struct manifest *m)
  24. {
  25. /* If it has C files, we expect an object file built from them. */
  26. return !list_empty(&m->c_files);
  27. }
  28. static char *build_subdir_objs(struct manifest *m)
  29. {
  30. struct ccan_file *i;
  31. list_for_each(&m->c_files, i, list) {
  32. char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
  33. char *output;
  34. i->compiled = maybe_temp_file(m, "", false, fullfile);
  35. if (!compile_object(m, fullfile, ccan_dir, "", i->compiled,
  36. &output)) {
  37. talloc_free(i->compiled);
  38. i->compiled = NULL;
  39. return talloc_asprintf(m,
  40. "Dependency %s"
  41. " did not build:\n%s",
  42. m->basename, output);
  43. }
  44. }
  45. return NULL;
  46. }
  47. static void check_depends_built(struct manifest *m,
  48. bool keep,
  49. unsigned int *timeleft, struct score *score)
  50. {
  51. struct manifest *i;
  52. struct stat st;
  53. list_for_each(&m->deps, i, list) {
  54. char *errstr;
  55. if (!expect_obj_file(i))
  56. continue;
  57. i->compiled = talloc_asprintf(i, "%s.o", i->dir);
  58. if (stat(i->compiled, &st) == 0)
  59. continue;
  60. if (verbose >= 2)
  61. printf(" Building dependency %s\n", i->dir);
  62. score->error = build_subdir_objs(i);
  63. if (score->error)
  64. return;
  65. i->compiled = build_module(i, keep, &errstr);
  66. if (!i->compiled) {
  67. score->error = talloc_asprintf(score,
  68. "Dependency %s"
  69. " did not build:\n%s",
  70. i->basename, errstr);
  71. return;
  72. }
  73. }
  74. if (!score->error) {
  75. score->pass = true;
  76. score->score = score->total;
  77. }
  78. }
  79. struct ccanlint depends_built = {
  80. .key = "depends-built",
  81. .name = "Module's CCAN dependencies can be found or built",
  82. .check = check_depends_built,
  83. .can_run = can_build,
  84. };
  85. REGISTER_TEST(depends_built, &depends_exist, NULL);