All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Jonathan Corbet <corbet@lwn.net>, linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Jani Nikula <jani.nikula@intel.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [RFC 03/10] kernel-doc: support printing exported and non-exported symbols
Date: Tue, 26 Jan 2016 14:08:48 +0200	[thread overview]
Message-ID: <8ccd774442080fa31fb2547cd6392f3cc17fe3e1.1453809420.git.jani.nikula@intel.com> (raw)
In-Reply-To: <cover.1453809420.git.jani.nikula@intel.com>
In-Reply-To: <cover.1453809420.git.jani.nikula@intel.com>

Currently we use docproc to figure out which symbols are exported, and
then docproc calls kernel-doc on specific functions, to get
documentation on exported functions. According to git blame and docproc
comments, this is due to historical reasons, as functions and their
corresponding EXPORT_SYMBOL* may have been in different files. However
for more than ten years the recommendation in CodingStyle has been to
place the EXPORT_SYMBOL* immediately after the closing function brace
line.

Additionally, the kernel-doc comments for functions are generally placed
above the function definition in the .c files (i.e. where the
EXPORT_SYMBOL* is) rather than above the declaration in the .h
files. There are some exceptions to this, but AFAICT none of these are
included in DocBook documentation using the "!E" docproc directive.

Therefore, assuming the EXPORT_SYMBOL* and kernel-doc are with the
function definition, kernel-doc can extract the exported vs. not
information by making two passes on the input file. Add support for that
via the new -export and -internal parameters.

[This should cover most of the cases. If it's not enough, it's trivial
to allow specifying additional files to look for EXPORT_SYMBOL* in.]

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 scripts/kernel-doc | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 15077f910e81..ee2ac9137a43 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -59,6 +59,12 @@ Output format selection (mutually exclusive):
   -text			Output plain text format.
 
 Output selection (mutually exclusive):
+  -export		Only output documentation for symbols that have been
+			exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
+			in the same FILE.
+  -internal		Only output documentation for symbols that have NOT been
+			exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
+			in the same FILE.
   -function NAME	Only output documentation for the given function(s)
 			or DOC: section title(s). All other functions and DOC:
 			sections are ignored. May be specified multiple times.
@@ -380,6 +386,7 @@ my $doc_block = $doc_com . 'DOC:\s*(.*)?';
 my $doc_split_start = '^\s*/\*\*\s*$';
 my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
 my $doc_split_end = '^\s*\*/\s*$';
+my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
 
 my %constants;
 my %parameterdescs;
@@ -444,6 +451,12 @@ while ($ARGV[0] =~ m/^-(.*)/) {
 	$function_only = 2;
 	$function = shift @ARGV;
 	$function_table{$function} = 1;
+    } elsif ($cmd eq "-export") { # only exported symbols
+	$function_only = 3;
+	%function_table = ()
+    } elsif ($cmd eq "-internal") { # only non-exported symbols
+	$function_only = 4;
+	%function_table = ()
     } elsif ($cmd eq "-v") {
 	$verbose = 1;
     } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
@@ -1976,8 +1989,10 @@ sub output_declaration {
     my $functype = shift;
     my $func = "output_${functype}_$output_mode";
     if (($function_only==0) ||
-	( $function_only == 1 && defined($function_table{$name})) ||
-	( $function_only == 2 && !($functype eq "function" && defined($function_table{$name}))))
+	( ($function_only == 1 || $function_only == 3) &&
+	  defined($function_table{$name})) ||
+	( ($function_only == 2 || $function_only == 4) &&
+	  !($functype eq "function" && defined($function_table{$name}))))
     {
 	&$func(@_);
 	$section_counter++;
@@ -2682,6 +2697,16 @@ sub process_file($) {
 
     $. = 1;
 
+    # two passes for -export and -internal
+    if ($function_only == 3 || $function_only == 4) {
+	while (<IN>) {
+	    if (/$export_symbol/o) {
+		$function_table{$2} = 1;
+	    }
+	}
+	seek(IN, 0, 0);
+    }
+
     $section_counter = 0;
     while (<IN>) {
 	while (s/\\\s*$//) {
-- 
2.1.4

  parent reply	other threads:[~2016-01-26 12:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-25 23:28 [RFC] A first shot at asciidoc-based formatted docs Jonathan Corbet
2016-01-25 23:28 ` [PATCH 1/4] kernel-doc: add support for asciidoc output Jonathan Corbet
2016-01-25 23:28 ` [PATCH 2/4] docproc: handle asciidoc templates Jonathan Corbet
2016-01-25 23:28 ` [PATCH 3/4] Docs: Makefile tweaks for " Jonathan Corbet
2016-01-25 23:28 ` [PATCH 4/4] Docs: add a sample asciidoc template Jonathan Corbet
2016-01-26 12:08 ` [RFC] A first shot at asciidoc-based formatted docs Jani Nikula
2016-01-26 12:08   ` [RFC 01/10] kernel-doc: rewrite usage description, remove duplicated comments Jani Nikula
2016-01-26 12:08   ` [RFC 02/10] kernel-doc: add support for asciidoc output Jani Nikula
2016-01-26 12:08   ` Jani Nikula [this message]
2016-01-26 12:08   ` [RFC 04/10] kernel-doc: add support for printing DOC: comments with escaped names Jani Nikula
2016-01-26 12:08   ` [RFC 05/10] scripts: add asciidoc-includes to extract includes from asciidoc Jani Nikula
2016-01-26 12:08   ` [RFC 06/10] scripts: add a kernel-doc helper for special invocation Jani Nikula
2016-01-26 12:08   ` [RFC 07/10] scripts: add tool for generating asciidoc dependencies and rules Jani Nikula
2016-01-26 12:08   ` [RFC 08/10] scripts: add a crude converter from DocBook tmpl to asciidoc Jani Nikula
2016-01-26 12:08   ` [RFC 09/10] Documentation: convert gpu.tmpl to gpu.txt Jani Nikula
2016-01-26 12:08   ` [RFC 10/10] Documentation: build asciidoc documentation Jani Nikula
2016-01-26 12:17   ` [RFC] A first shot at asciidoc-based formatted docs Daniel Vetter
2016-01-26 12:38     ` Jani Nikula
2016-01-26 14:48   ` Jonathan Corbet
2016-01-26 14:52     ` Jonathan Corbet
2016-02-10  0:09   ` Jonathan Corbet
2016-02-10  8:07     ` Daniel Vetter
2016-02-10 14:03       ` Jani Nikula
2016-02-10 16:12         ` Jani Nikula
2016-02-10 20:56         ` Jonathan Corbet
2016-02-11 15:18           ` Keith Packard
2016-02-10 20:45       ` Jonathan Corbet
2016-02-10 23:01     ` Keith Packard
2016-02-11 13:44       ` Jani Nikula
2016-02-11 15:21         ` Keith Packard
2016-02-13  3:20       ` Keith Packard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ccd774442080fa31fb2547cd6392f3cc17fe3e1.1453809420.git.jani.nikula@intel.com \
    --to=jani.nikula@intel.com \
    --cc=corbet@lwn.net \
    --cc=daniel.vetter@ffwll.ch \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.