1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/doc_extract.h>
3 #include <tools/tools.h>
13 #include <ccan/str/str.h>
14 #include <ccan/talloc/talloc.h>
15 #include <ccan/noerr/noerr.h>
16 #include <ccan/grab_file/grab_file.h>
18 static void check_info_documentation_exists(struct manifest *m,
19 unsigned int *timeleft,
22 static struct ccanlint info_documentation_exists = {
23 .key = "info_documentation_exists",
24 .name = "Module has documentation in _info",
25 .check = check_info_documentation_exists,
26 .needs = "info_exists"
29 static void create_info_template_doc(struct manifest *m, struct score *score)
35 if (!ask("Should I prepend description to _info file for you?"))
38 fd = open("_info.new", O_WRONLY|O_CREAT|O_EXCL, 0666);
39 if (fd < 0 || !(new = fdopen(fd, "w")))
40 err(1, "Creating _info.new to insert documentation");
44 " * %s - [[ONE LINE DESCRIPTION HERE]]\n"
46 " * Paragraphs why %s exists and where to use it.\n"
48 " * Followed by an Example: section with a standalone\n"
49 " * (trivial and usually useless) program\n"
50 " */\n", m->modname, m->basename) < 0) {
51 unlink_noerr("_info.new");
52 err(1, "Writing to _info.new to insert documentation");
55 oldcontents = grab_file(m, m->info_file->fullname, NULL);
57 unlink_noerr("_info.new");
58 err(1, "Reading %s", m->info_file->fullname);
60 if (fprintf(new, "%s", oldcontents) < 0) {
61 unlink_noerr("_info.new");
62 err(1, "Appending _info to _info.new");
64 if (fclose(new) != 0) {
65 unlink_noerr("_info.new");
66 err(1, "Closing _info.new");
68 if (!move_file("_info.new", m->info_file->fullname)) {
69 unlink_noerr("_info.new");
70 err(1, "Renaming _info.new to %s", m->info_file->fullname);
74 static void check_info_documentation_exists(struct manifest *m,
75 unsigned int *timeleft,
78 struct list_head *infodocs = get_ccan_file_docs(m->info_file);
79 struct doc_section *d;
80 bool summary = false, description = false;
82 /* We don't fail ccanlint for this. */
85 list_for_each(infodocs, d, list) {
86 if (!streq(d->function, m->modname))
88 if (streq(d->type, "summary"))
90 if (streq(d->type, "description"))
94 if (summary && description) {
95 score->score = score->total;
96 } else if (!summary) {
97 score->error = talloc_strdup(score,
98 "_info file has no module documentation.\n\n"
99 "CCAN modules use /**-style comments for documentation: the\n"
100 "overall documentation belongs in the _info metafile.\n");
101 info_documentation_exists.handle = create_info_template_doc;
102 } else if (!description) {
103 score->error = talloc_strdup(score,
104 "_info file has no module description.\n\n"
105 "The lines after the first summary line in the _info file\n"
106 "documentation should describe the purpose and use of the\n"
107 "overall package\n");
111 REGISTER_TEST(info_documentation_exists);