objects_build.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/str/str.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <limits.h>
  9. #include <errno.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <err.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. #include "build.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. void build_objects(struct manifest *m,
  23. struct score *score, const char *flags,
  24. enum compile_type ctype)
  25. {
  26. struct ccan_file *i;
  27. bool errors = false, warnings = false;
  28. if (list_empty(&m->c_files))
  29. score->total = 0;
  30. else
  31. score->total = 2;
  32. list_for_each(&m->c_files, i, list) {
  33. char *output;
  34. char *fullfile = tal_fmt(m, "%s/%s", m->dir, i->name);
  35. i->compiled[ctype] = temp_file(m, "", fullfile);
  36. if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
  37. i->compiled[ctype], &output)) {
  38. tal_free(i->compiled[ctype]);
  39. score_file_error(score, i, 0,
  40. "Compiling object files:\n%s",
  41. output);
  42. errors = true;
  43. } else if (!streq(output, "")) {
  44. score_file_error(score, i, 0,
  45. "Compiling object files gave"
  46. " warnings:\n%s",
  47. output);
  48. warnings = true;
  49. }
  50. }
  51. if (!errors) {
  52. score->pass = true;
  53. score->score = score->total - warnings;
  54. }
  55. }
  56. static void check_objs_build(struct manifest *m,
  57. unsigned int *timeleft, struct score *score)
  58. {
  59. build_objects(m, score, cflags, COMPILE_NORMAL);
  60. }
  61. struct ccanlint objects_build = {
  62. .key = "objects_build",
  63. .name = "Module object files can be built",
  64. .compulsory = true,
  65. .check = check_objs_build,
  66. .can_run = can_build,
  67. .needs = "depends_exist"
  68. };
  69. REGISTER_TEST(objects_build);