has_info.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. {
  18. if (m->info_file)
  19. return NULL;
  20. return m;
  21. }
  22. static const char *describe_has_info(struct manifest *m, void *check_result)
  23. {
  24. return "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. 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, void *check_result)
  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 has_info = {
  71. .key = "info",
  72. .name = "Module has _info file",
  73. .check = check_has_info,
  74. .describe = describe_has_info,
  75. .handle = create_info_template,
  76. };
  77. REGISTER_TEST(has_info, NULL);