build.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. static char *obj_list(const struct manifest *m)
  23. {
  24. char *list = talloc_strdup(m, "");
  25. struct ccan_file *i;
  26. /* Objects from all the C files. */
  27. list_for_each(&m->c_files, i, list)
  28. list = talloc_asprintf_append(list, "%s ", i->compiled);
  29. return list;
  30. }
  31. static void *do_build(struct manifest *m)
  32. {
  33. char *filename, *err;
  34. if (list_empty(&m->c_files)) {
  35. /* No files? No score, but we "pass". */
  36. build.total_score = 0;
  37. return NULL;
  38. }
  39. filename = link_objects(m, obj_list(m), &err);
  40. if (filename) {
  41. char *realname = talloc_asprintf(m, "%s.o", m->dir);
  42. /* We leave this object file around, all built. */
  43. if (!move_file(filename, realname))
  44. return talloc_asprintf(m, "Failed to rename %s to %s",
  45. filename, realname);
  46. return NULL;
  47. }
  48. return err;
  49. }
  50. static const char *describe_build(struct manifest *m, void *check_result)
  51. {
  52. return talloc_asprintf(check_result,
  53. "The object file for the module didn't build:\n"
  54. "%s", (char *)check_result);
  55. }
  56. struct ccanlint build = {
  57. .name = "Module can be built",
  58. .total_score = 1,
  59. .check = do_build,
  60. .describe = describe_build,
  61. .can_run = can_build,
  62. };
  63. REGISTER_TEST(build, &depends_built, NULL);