info_exists.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <ccan/tal/tal.h>
  3. #include <ccan/tal/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 <ccan/noerr/noerr.h>
  15. static void check_has_info(struct manifest *m,
  16. unsigned int *timeleft UNNEEDED,
  17. struct score *score)
  18. {
  19. if (m->info_file) {
  20. score->pass = true;
  21. score->score = score->total;
  22. add_info_options(m);
  23. } else {
  24. score->error = tal_strdup(score,
  25. "You have no _info file.\n\n"
  26. "The file _info contains the metadata for a ccan package: things\n"
  27. "like the dependencies, the documentation for the package as a whole\n"
  28. "and license information.\n");
  29. }
  30. }
  31. static const char template[] =
  32. "#include \"config.h\"\n"
  33. "#include <stdio.h>\n"
  34. "#include <string.h>\n"
  35. "\n"
  36. "/**\n"
  37. " * %s - YOUR-ONE-LINE-DESCRIPTION-HERE\n"
  38. " *\n"
  39. " * This code ... YOUR-BRIEF-SUMMARY-HERE\n"
  40. " *\n"
  41. " * Example:\n"
  42. " * FULLY-COMPILABLE-INDENTED-TRIVIAL-BUT-USEFUL-EXAMPLE-HERE\n"
  43. " */\n"
  44. "int main(int argc, char *argv[])\n"
  45. "{\n"
  46. " /* Expect exactly one argument */\n"
  47. " if (argc != 2)\n"
  48. " return 1;\n"
  49. "\n"
  50. " if (strcmp(argv[1], \"depends\") == 0) {\n"
  51. " PRINTF-CCAN-PACKAGES-YOU-NEED-ONE-PER-LINE-IF-ANY\n"
  52. " return 0;\n"
  53. " }\n"
  54. "\n"
  55. " return 1;\n"
  56. "}\n";
  57. static void create_info_template(struct manifest *m,
  58. struct score *score UNNEEDED)
  59. {
  60. FILE *info;
  61. const char *filename;
  62. if (!ask("Should I create a template _info file for you?"))
  63. return;
  64. filename = tal_fmt(m, "%s/%s", m->dir, "_info");
  65. info = fopen(filename, "w");
  66. if (!info)
  67. err(1, "Trying to create a template _info in %s", filename);
  68. if (fprintf(info, template, m->modname) < 0) {
  69. unlink_noerr(filename);
  70. err(1, "Writing template into %s", filename);
  71. }
  72. fclose(info);
  73. }
  74. struct ccanlint info_exists = {
  75. .key = "info_exists",
  76. .name = "Module has _info file",
  77. .compulsory = true,
  78. .check = check_has_info,
  79. .handle = create_info_template,
  80. .needs = ""
  81. };
  82. REGISTER_TEST(info_exists);