objects_build.c 1.7 KB

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