module_builds.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/str/str.h>
  4. #include <ccan/take/take.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 char *obj_list(const struct manifest *m, enum compile_type ctype)
  24. {
  25. char *list = tal_strdup(m, "");
  26. struct ccan_file *i;
  27. /* Objects from all the C files. */
  28. list_for_each(&m->c_files, i, list) {
  29. list = tal_strcat(m, take(list), i->compiled[ctype]);
  30. list = tal_strcat(m, take(list), " ");
  31. }
  32. return list;
  33. }
  34. char *build_module(struct manifest *m,
  35. enum compile_type ctype, char **errstr)
  36. {
  37. return link_objects(m, m->basename, obj_list(m, ctype), errstr);
  38. }
  39. static void do_build(struct manifest *m,
  40. unsigned int *timeleft,
  41. struct score *score)
  42. {
  43. char *errstr;
  44. if (list_empty(&m->c_files)) {
  45. /* No files? No score, but we "pass". */
  46. score->total = 0;
  47. score->pass = true;
  48. return;
  49. }
  50. m->compiled[COMPILE_NORMAL]
  51. = build_module(m, COMPILE_NORMAL, &errstr);
  52. if (!m->compiled[COMPILE_NORMAL]) {
  53. score_file_error(score, NULL, 0, "%s", errstr);
  54. return;
  55. }
  56. score->pass = true;
  57. score->score = score->total;
  58. }
  59. struct ccanlint module_builds = {
  60. .key = "module_builds",
  61. .name = "Module can be built from object files",
  62. .compulsory = true,
  63. .check = do_build,
  64. .can_run = can_build,
  65. .needs = "objects_build"
  66. };
  67. REGISTER_TEST(module_builds);