build.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. bool keep,
  33. unsigned int *timeleft)
  34. {
  35. char *filename, *err;
  36. if (list_empty(&m->c_files)) {
  37. /* No files? No score, but we "pass". */
  38. build.total_score = 0;
  39. return NULL;
  40. }
  41. filename = link_objects(m, m->basename, false, obj_list(m), &err);
  42. if (filename && keep) {
  43. char *realname = talloc_asprintf(m, "%s.o", m->dir);
  44. /* We leave this object file around, all built. */
  45. if (!move_file(filename, realname))
  46. return talloc_asprintf(m, "Failed to rename %s to %s",
  47. filename, realname);
  48. return NULL;
  49. }
  50. return err;
  51. }
  52. static const char *describe_build(struct manifest *m, void *check_result)
  53. {
  54. return talloc_asprintf(check_result,
  55. "The object file for the module didn't build:\n"
  56. "%s", (char *)check_result);
  57. }
  58. struct ccanlint build = {
  59. .key = "build",
  60. .name = "Module can be built from object files",
  61. .total_score = 1,
  62. .check = do_build,
  63. .describe = describe_build,
  64. .can_run = can_build,
  65. };
  66. REGISTER_TEST(build, &depends_built, NULL);