module_builds.c 1.6 KB

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