info_exists.c 2.0 KB

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