build.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. struct score *score)
  35. {
  36. char *filename, *errstr;
  37. if (list_empty(&m->c_files)) {
  38. /* No files? No score, but we "pass". */
  39. score->total = 0;
  40. score->pass = true;
  41. return;
  42. }
  43. filename = link_objects(m, m->basename, false, obj_list(m), &errstr);
  44. if (!filename) {
  45. score->error = "The object file didn't build";
  46. score_file_error(score, NULL, 0, errstr);
  47. return;
  48. }
  49. if (keep) {
  50. char *realname = talloc_asprintf(m, "%s.o", m->dir);
  51. /* We leave this object file around, all built. */
  52. if (!move_file(filename, realname))
  53. err(1, "Renaming %s to %s", filename, realname);
  54. }
  55. score->pass = true;
  56. score->score = score->total;
  57. }
  58. struct ccanlint build = {
  59. .key = "build",
  60. .name = "Module can be built from object files",
  61. .check = do_build,
  62. .can_run = can_build,
  63. };
  64. REGISTER_TEST(build, &depends_built, NULL);