info_exists.c 2.0 KB

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