info_exists.c 2.0 KB

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