objects_build.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. static const char *can_build(struct manifest *m)
  17. {
  18. if (safe_mode)
  19. return "Safe mode enabled";
  20. return NULL;
  21. }
  22. static void check_objs_build(struct manifest *m,
  23. bool keep,
  24. unsigned int *timeleft, struct score *score)
  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 = talloc_asprintf(m, "%s/%s", m->dir, i->name);
  35. i->compiled = maybe_temp_file(m, "", keep, fullfile);
  36. if (!compile_object(score, fullfile, ccan_dir, "", i->compiled,
  37. &output)) {
  38. talloc_free(i->compiled);
  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. struct ccanlint objects_build = {
  57. .key = "objects_build",
  58. .name = "Module object files can be built",
  59. .check = check_objs_build,
  60. .can_run = can_build,
  61. .needs = "depends_exist"
  62. };
  63. REGISTER_TEST(objects_build);