objects_build.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. static char *cflags_list(const struct manifest *m)
  24. {
  25. unsigned int i;
  26. char *ret = tal_strdup(m, cflags);
  27. char **flags = get_cflags(m, m->dir, get_or_compile_info);
  28. for (i = 0; flags[i]; i++)
  29. tal_append_fmt(&ret, " %s", flags[i]);
  30. return ret;
  31. }
  32. void build_objects(struct manifest *m,
  33. struct score *score, const char *flags,
  34. enum compile_type ctype)
  35. {
  36. struct ccan_file *i;
  37. bool errors = false, warnings = false;
  38. if (list_empty(&m->c_files))
  39. score->total = 0;
  40. else
  41. score->total = 2;
  42. list_for_each(&m->c_files, i, list) {
  43. char *output;
  44. char *fullfile = path_join(m, m->dir, i->name);
  45. i->compiled[ctype] = temp_file(m, "", fullfile);
  46. if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
  47. i->compiled[ctype], &output)) {
  48. tal_free(i->compiled[ctype]);
  49. score_file_error(score, i, 0,
  50. "Compiling object files:\n%s",
  51. output);
  52. errors = true;
  53. } else if (!streq(output, "")) {
  54. score_file_error(score, i, 0,
  55. "Compiling object files gave"
  56. " warnings:\n%s",
  57. output);
  58. warnings = true;
  59. }
  60. }
  61. if (!errors) {
  62. score->pass = true;
  63. score->score = score->total - warnings;
  64. } else
  65. build_failed = true;
  66. }
  67. static void check_objs_build(struct manifest *m,
  68. unsigned int *timeleft, struct score *score)
  69. {
  70. const char *flags;
  71. flags = cflags_list(m);
  72. build_objects(m, score, flags, COMPILE_NORMAL);
  73. }
  74. struct ccanlint objects_build = {
  75. .key = "objects_build",
  76. .name = "Module object files can be built",
  77. .compulsory = true,
  78. .check = check_objs_build,
  79. .can_run = can_build,
  80. .needs = "depends_exist info_ported"
  81. };
  82. REGISTER_TEST(objects_build);