depends_build.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, compiler, cflags,
  36. i->compiled, &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. char *build_submodule(struct manifest *m)
  48. {
  49. char *errstr;
  50. if (m->compiled)
  51. return NULL;
  52. if (!expect_obj_file(m))
  53. return NULL;
  54. if (verbose >= 2)
  55. printf(" Building dependency %s\n", m->dir);
  56. errstr = build_subdir_objs(m);
  57. if (errstr)
  58. return errstr;
  59. m->compiled = build_module(m, false, &errstr);
  60. if (!m->compiled)
  61. return errstr;
  62. return NULL;
  63. }
  64. static void check_depends_built(struct manifest *m,
  65. bool keep,
  66. unsigned int *timeleft, struct score *score)
  67. {
  68. struct manifest *i;
  69. list_for_each(&m->deps, i, list) {
  70. char *errstr = build_submodule(i);
  71. if (errstr) {
  72. score->error = talloc_asprintf(score,
  73. "Dependency %s"
  74. " did not build:\n%s",
  75. i->basename, errstr);
  76. return;
  77. }
  78. }
  79. score->pass = true;
  80. score->score = score->total;
  81. }
  82. struct ccanlint depends_build = {
  83. .key = "depends_build",
  84. .name = "Module's CCAN dependencies can be found or built",
  85. .check = check_depends_built,
  86. .can_run = can_build,
  87. .needs = "depends_exist"
  88. };
  89. REGISTER_TEST(depends_build);