build.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /* Object from all the C files. */
  27. list_for_each(&m->c_files, i, list)
  28. list = talloc_asprintf_append(list, "%.*s.o ",
  29. strlen(i->name) - 2, i->name);
  30. return list;
  31. }
  32. /* We leave this object file around after ccanlint runs, all built. */
  33. static void *do_build(struct manifest *m)
  34. {
  35. if (list_empty(&m->c_files)) {
  36. /* No files? No score, but we "pass". */
  37. build.total_score = 0;
  38. return NULL;
  39. }
  40. return run_command(m, "ld -r -o ../%s.o %s", m->basename, obj_list(m));
  41. }
  42. static const char *describe_build(struct manifest *m, void *check_result)
  43. {
  44. return talloc_asprintf(check_result,
  45. "The object file for the module didn't build:\n"
  46. "%s", (char *)check_result);
  47. }
  48. struct ccanlint build = {
  49. .name = "Module can be built",
  50. .total_score = 1,
  51. .check = do_build,
  52. .describe = describe_build,
  53. .can_run = can_build,
  54. };
  55. REGISTER_TEST(build, &depends_built, NULL);