docs: integrate doc comments with Sphinx build
cover docs: integrate doc comments with Sphinx build
This merges my series and Peter's into one. Both the memory API and bitwise operation APIs are covered.
Paolo Bonzini (4):
docs: import Linux kernel-doc script and extension
docs: tweak kernel-doc for QEMU coding standards memory.h: Silence kernel-doc complaints
docs: add memory API reference
Peter Maydell (4):
docs/conf.py: Enable use of kerneldoc sphinx extension
Makefile: disable Sphinx nitpicking
bitops.h: Silence kernel-doc complaints
docs: Create bitops.rst as example of kernel-docs
Makefile | 2 +- docs/conf.py | 7 +- docs/devel/bitops.rst | 8 + docs/devel/index.rst | 1 + docs/devel/memory.rst | 5 + docs/sphinx/kerneldoc.py | 172 +++ docs/sphinx/kernellog.py | 28 + include/exec/memory.h | 16 +- include/qemu/bitops.h | 52 +- scripts/kernel-doc | 2236 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 2499 insertions(+), 28 deletions(-) create mode 100644 docs/devel/bitops.rst create mode 100644 docs/sphinx/kerneldoc.py create mode 100644 docs/sphinx/kernellog.py create mode 100755 scripts/kernel-doc
Signature · 1 line
2.21.0
PATCH 1/8 docs: import Linux kernel-doc script and extension
Import Linux's kernel-doc script, as well as the Linux extension to call kernel-doc according to the arguments and parameters given to a reStructuredText directive.
The kernel-doc extension accepts a filename, which is relative to the QEMU source tree root. The extension also notifies Sphinx about the document dependency on the file, causing the document to be rebuilt when the file has been changed.
--- docs/sphinx/kerneldoc.py | 172 +++ docs/sphinx/kernellog.py | 28 + scripts/kernel-doc | 2226 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 2426 insertions(+) create mode 100644 docs/sphinx/kerneldoc.py create mode 100644 docs/sphinx/kernellog.py create mode 100755 scripts/kernel-doc
docs/sphinx/kerneldoc.py new file +172 -0
@@ -0,0 +1,172 @@ +# coding=utf-8 +# +# Copyright © 2016 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# Authors: +# Jani Nikula <[email protected]> +# +# Please make sure this works on both python2 and python3. +# + +import codecs +import os +import subprocess +import sys +import re +import glob + +from docutils import nodes, statemachine +from docutils.statemachine import ViewList +from docutils.parsers.rst import directives, Directive + +# +# AutodocReporter is only good up to Sphinx 1.7 +# +import sphinx + +Use_SSI = sphinx.__version__[:3] >= '1.7' +if Use_SSI: + from sphinx.util.docutils import switch_source_input +else: + from sphinx.ext.autodoc import AutodocReporter + +import kernellog + +__version__ = '1.0' + +class KernelDocDirective(Directive): + """Extract kernel-doc comments from the specified file""" + required_argument = 1 + optional_arguments = 4 + option_spec = { + 'doc': directives.unchanged_required, + 'functions': directives.unchanged, + 'export': directives.unchanged, + 'internal': directives.unchanged, + } + has_content = False + + def run(self): + env = self.state.document.settings.env + cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno'] + + filename = env.config.kerneldoc_srctree + '/' + self.arguments[0] + export_file_patterns = [] + + # Tell sphinx of the dependency + env.note_dependency(os.path.abspath(filename)) + + tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) + + # FIXME: make this nicer and more robust against errors + if 'export' in self.options: + cmd += ['-export'] + export_file_patterns = str(self.options.get('export')).split() + elif 'internal' in self.options: + cmd += ['-internal'] + export_file_patterns = str(self.options.get('internal')).split() + elif 'doc' in self.options: + cmd += ['-function', str(self.options.get('doc'))] + elif 'functions' in self.options: + functions = self.options.get('functions').split() + if functions: + for f in functions: + cmd += ['-function', f] + else: + cmd += ['-no-doc-sections'] + + for pattern in export_file_patterns: + for f in glob.glob(env.config.kerneldoc_srctree + '/' + pattern): + env.note_dependency(os.path.abspath(f)) + cmd += ['-export-file', f] + + cmd += [filename] + + try: + kernellog.verbose(env.app, + 'calling kernel-doc \'%s\'' % (" ".join(cmd))) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + + out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') + + if p.returncode != 0: + sys.stderr.write(err) + + kernellog.warn(env.app, + 'kernel-doc \'%s\' failed with return code %d' % (" ".join(cmd), p.returncode)) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + elif env.config.kerneldoc_verbosity > 0: + sys.stderr.write(err) + + lines = statemachine.string2lines(out, tab_width, convert_whitespace=True) + result = ViewList() + + lineoffset = 0; + line_regex = re.compile("^#define LINENO ([0-9]+)$") + for line in lines: + match = line_regex.search(line) + if match: + # sphinx counts lines from 0 + lineoffset = int(match.group(1)) - 1 + # we must eat our comments since the upset the markup + else: + result.append(line, filename, lineoffset) + lineoffset += 1 + + node = nodes.section() + self.do_parse(result, node) + + return node.children + + except Exception as e: # pylint: disable=W0703 + kernellog.warn(env.app, 'kernel-doc \'%s\' processing failed with: %s' % + (" ".join(cmd), str(e))) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + + def do_parse(self, result, node): + if Use_SSI: + with switch_source_input(self.state, result): + self.state.nested_parse(result, 0, node, match_titles=1) + else: + save = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter + self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter) + self.state.memo.title_styles, self.state.memo.section_level = [], 0 + try: + self.state.nested_parse(result, 0, node, match_titles=1) + finally: + self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = save + + +def setup(app): + app.add_config_value('kerneldoc_bin', None, 'env') + app.add_config_value('kerneldoc_srctree', None, 'env') + app.add_config_value('kerneldoc_verbosity', 1, 'env') + + app.add_directive('kernel-doc', KernelDocDirective) + + return dict( + version = __version__, + parallel_read_safe = True, + parallel_write_safe = True + )
docs/sphinx/kernellog.py new file +28 -0
@@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Sphinx has deprecated its older logging interface, but the replacement +# only goes back to 1.6. So here's a wrapper layer to keep around for +# as long as we support 1.4. +# +import sphinx + +if sphinx.__version__[:3] >= '1.6': + UseLogging = True + from sphinx.util import logging + logger = logging.getLogger('kerneldoc') +else: + UseLogging = False + +def warn(app, message): + if UseLogging: + logger.warning(message) + else: + app.warn(message) + +def verbose(app, message): + if UseLogging: + logger.verbose(message) + else: + app.verbose(message) + +
scripts/kernel-doc new file +2226 -0
2,226 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 1/8] docs: import Linux kernel-doc script and extension
Quoted 11 lines · Paolo Bonzini
Import Linux's kernel-doc script, as well as the Linux extension to call kernel-doc according to the arguments and parameters given to a reStructuredText directive.
The kernel-doc extension accepts a filename, which is relative to the QEMU source tree root. The extension also notifies Sphinx about the document dependency on the file, causing the document to be rebuilt when the file has been changed.
Signed-off-by Paolo Bonzini <[email protected]>
Could you quote the kernel git commit that you did the import from in the commit message?
Otherwise
thanks
-- PMM
PATCH 2/8 docs: tweak kernel-doc for QEMU coding standards
In reply to Paolo BonziniSurprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names.
Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy.
--- scripts/kernel-doc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
scripts/kernel-doc +19 -9
@@ -215,12 +215,12 @@ my $type_func = '(\w+)\(\)'; my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params my $type_env = '(\$\w+)'; -my $type_enum = '\&(enum\s*([_\w]+))'; -my $type_struct = '\&(struct\s*([_\w]+))'; -my $type_typedef = '\&(typedef\s*([_\w]+))'; -my $type_union = '\&(union\s*([_\w]+))'; -my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; -my $type_fallback = '\&([_\w]+)'; +my $type_enum = '#(enum\s*([_\w]+))'; +my $type_struct = '#(struct\s*([_\w]+))'; +my $type_typedef = '#(([A-Z][_\w]*))'; +my $type_union = '#(union\s*([_\w]+))'; +my $type_member = '#([_\w]+)(\.|->)([_\w]+)'; +my $type_fallback = '(?!)'; # this never matches my $type_member_func = $type_member . '\(\)'; # Output conversion substitutions.
@@ -1050,6 +1050,14 @@ sub output_blockhead { sub dump_declaration($$) { no strict 'refs'; my ($prototype, $file) = @_; + if ($decl_type eq 'type name') { + if ($prototype =~ /^(enum|struct|union)\s+/) { + $decl_type = $1; + } else { + return; + } + } + my $func = "dump_" . $decl_type; &$func(@_); }
@@ -1878,7 +1886,7 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; - if (/\s*([\w\s]+?)(\(\))?\s*-/) { + if (/\s*([\w\s]+?)(\s*-|:)/) { $identifier = $1; }
@@ -1888,7 +1896,7 @@ sub process_name($$) { $contents = ""; $section = $section_default; $new_start_line = $. + 1; - if (/-(.*)/) { + if (/[-:](.*)/) { # strip leading/trailing/multiple spaces $descr= $1; $descr =~ s/^\s*//;
@@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; } - if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union';
Signature · 1 line
2.21.0
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 28 lines · Paolo Bonzini
Surprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in
accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names.Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy.
Signed-off-by Paolo Bonzini <[email protected]>--- scripts/kernel-doc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)scripts/kernel-doc +0
-1@@ -215,12 +215,12 @@ my $type_func = '(\w+)\(\)'; my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params my $type_env = '(\$\w+)'; -my $type_enum = '\&(enum\s*([_\w]+))';
scripts/kernel-doc my $type_func = '(\w+)\(\)'; · line 222
Quoted 10 lines
scripts/kernel-doc +5
-5-my $type_struct = '\&(struct\s*([_\w]+))'; -my $type_typedef = '\&(typedef\s*([_\w]+))'; -my $type_union = '\&(union\s*([_\w]+))'; -my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; -my $type_fallback = '\&([_\w]+)'; +my $type_enum = '#(enum\s*([_\w]+))'; +my $type_struct = '#(struct\s*([_\w]+))'; +my $type_typedef = '#(([A-Z][_\w]*))'; +my $type_union = '#(union\s*([_\w]+))'; +my $type_member = '#([_\w]+)(\.|->)([_\w]+)';
perlre(1) says that \w includes _' so I think '[_\w]' is a funny way of writing '\w', but on
the other hand it's in the existing code too...
Quoted 29 lines
scripts/kernel-doc +10
-1+my $type_fallback = '(?!)'; # this never matches my $type_member_func = $type_member . '\(\)'; # Output conversion substitutions.@@ -1050,6 +1050,14 @@ sub output_blockhead { sub dump_declaration($$) { no strict 'refs'; my ($prototype, $file) = @_; + if ($decl_type eq 'type name') { + if ($prototype =~ /^(enum|struct|union)\s+/) { + $decl_type = $1; + } else { + return; + } + } + my $func = "dump_" . $decl_type; &$func(@_); }@@ -1878,7 +1886,7 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; - if (/\s*([\w\s]+?)(\(\))?\s*-/) { + if (/\s*([\w\s]+?)(\s*-|:)/) { $identifier = $1; }
scripts/kernel-doc sub process_name($$) { · line 1902
Quoted 8 lines
scripts/kernel-doc +1
-1@@ -1888,7 +1896,7 @@ sub process_name($$) { $contents = ""; $section = $section_default; $new_start_line = $. + 1; - if (/-(.*)/) { + if (/[-:](.*)/) { # strip leading/trailing/multiple spaces $descr= $1; $descr =~ s/^\s*//;
These two bits seem to be a third thing not mentioned in the commit message -- permitting either colon or hyphen in the "Thing: short description" introductory line, where kernel style insists on a hyphen.
(You could make the argument that this is an unnecessary drift from the kernel-doc style and we should just fix up all those colons...)
scripts/kernel-doc sub process_name($$) { · line 1922
Quoted 11 lines
scripts/kernel-doc +3
-1@@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; } - if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union';
The match for 'type name' is pretty wide but I guess we can find out through experience if we need to narrow it.
thanks
-- PMM
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 18 lines · Peter Maydell
scripts/kernel-doc sub process_name($$) { · line 1902
Quoted 13 lines
scripts/kernel-doc +2
-1+ if (/\s*([\w\s]+?)(\s*-|:)/) { $identifier = $1; }@@ -1888,7 +1896,7 @@ sub process_name($$) { $contents = ""; $section = $section_default; $new_start_line = $. + 1; - if (/-(.*)/) { + if (/[-:](.*)/) { # strip leading/trailing/multiple spaces $descr= $1; $descr =~ s/^\s*//;These two bits seem to be a third thing not mentioned in the commit message -- permitting either colon or hyphen in the "Thing: short description" introductory line, where kernel style insists on a hyphen.
Quoted 3 lines
(You could make the argument that this is an unnecessary drift from the kernel-doc style and we should just fix up all those colons...)
Perhaps we could yeah. Problem is, there are just three hyphens (one in include/hw/stream.h, two in include/qemu/host-utils.h) so that would be quite a big patch. We could do that as we add kernel-doc directive, if you prefer that, or do it in one shot after committing this series, or just live with the two lines changed above.
Paolo
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
In reply to Peter MaydellQuoted 16 lines · Peter Maydell
Quoted 15 lines · Paolo Bonzini
Surprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in
accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names.Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy.
Signed-off-by Paolo Bonzini <[email protected]>
[...]
Quoted 4 lines
Quoted 4 lines
scripts/kernel-doc +0
-0@@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; }
Quoted 10 lines
scripts/kernel-doc sub process_name($$) { · line 1922
Quoted 7 lines
scripts/kernel-doc +3
-1- if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union';The match for 'type name' is pretty wide but I guess we can find out through experience if we need to narrow it.
This change seems to make it impossible to document any macros with uppercase names.
(for example, most of the macros in object.h are not included in the generated docs)
What exactly is the purpose of the hunk above?
Signature · 1 line
Eduardo
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 34 lines · Eduardo Habkost
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Paolo Bonzini
Surprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in
accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names.Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy.
Signed-off-by Paolo Bonzini <[email protected]>[...]
Quoted 4 lines
Quoted 4 lines
scripts/kernel-doc +0
-0@@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; }Quoted 10 lines
scripts/kernel-doc sub process_name($$) { · line 1922
Quoted 7 lines
scripts/kernel-doc +3
-1- if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union';The match for 'type name' is pretty wide but I guess we can find out through experience if we need to narrow it.
Quoted 7 lines
This change seems to make it impossible to document any macros with uppercase names.
(for example, most of the macros in
object.hare not included in the generated docs)What exactly is the purpose of the hunk above?
It's so that QEMU's bare type names like MemoryRegionSection get recognized as being types. Kernel naming style always prefers to say "struct MemoryRegionSection" where we use the typedef and say "MemoryRegionSection", which is why the upstream kernel-doc doesn't care about this. IIRC, without it, doc comments which reference a type like '#TypeName' like:
* @log_sync:
*
* Called by memory_region_snapshot_and_clear_dirty() and
* memory_global_dirty_log_sync(), before accessing QEMU's "official"
* copy of the dirty memory bitmap for a #MemoryRegionSection. *
don't correctly render the typename into a link to the struct definition.
thanks
-- PMM
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 57 lines · Peter Maydell
Quoted 34 lines · Eduardo Habkost
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Paolo Bonzini
Surprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in
accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names.Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy.
Signed-off-by Paolo Bonzini <[email protected]>[...]
Quoted 4 lines
Quoted 4 lines
scripts/kernel-doc +0
-0@@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; }Quoted 10 lines
scripts/kernel-doc sub process_name($$) { · line 1922
Quoted 7 lines
scripts/kernel-doc +3
-1- if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union';The match for 'type name' is pretty wide but I guess we can find out through experience if we need to narrow it.
Quoted 7 lines
This change seems to make it impossible to document any macros with uppercase names.
(for example, most of the macros in
object.hare not included in the generated docs)What exactly is the purpose of the hunk above?
It's so that QEMU's bare type names like MemoryRegionSection get recognized as being types. Kernel naming style always prefers to say "struct MemoryRegionSection" where we use the typedef and say "MemoryRegionSection", which is why the upstream kernel-doc doesn't care about this. IIRC, without it, doc comments which reference a type like '#TypeName' like:
* @log_sync:
*
* Called bymemory_region_snapshot_and_clear_dirty()and
*memory_global_dirty_log_sync(), before accessing QEMU's "official"
* copy of the dirty memory bitmap for a #MemoryRegionSection. *
Quoted 2 lines
don't correctly render the typename into a link to the struct definition.
This is not the code that parses "#MemoryRegionSection", it is the code that parses:
/**
* MemoryRegionSection: describes a fragment of a #MemoryRegion ^^^^^^^ this line
Signature · 1 line
Eduardo
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 6 lines · Eduardo Habkost
This is not the code that parses "#MemoryRegionSection", it is the code that parses:
/**
* MemoryRegionSection: describes a fragment of a #MemoryRegion ^^^^^^^ this line
We can probably just adjust the comments to include the "struct" keyword first. There aren't that many, (un)fortunately.
It may even be possible to print to stderr the file and line number so that the script tells us where the hack is firing.
Paolo
Re: [PATCH 2/8] docs: tweak kernel-doc for QEMU coding standards
Quoted 8 lines · Paolo Bonzini
Quoted 6 lines · Eduardo Habkost
This is not the code that parses "#MemoryRegionSection", it is the code that parses:
/**
* MemoryRegionSection: describes a fragment of a #MemoryRegion ^^^^^^^ this line
Quoted 6 lines
We can probably just adjust the comments to include the "struct" keyword first. There aren't that many, (un)fortunately.
It may even be possible to print to stderr the file and line number so that the script tells us where the hack is firing.
There are 3 lines where the hack is correctly triggered, but we can just change it to use "struct MyTypeName" instead:
include/exec/memory.h:681: HEREinclude/exec/memory.h:699: HEREinclude/exec/memory.h:743: HERE
And 29 lines where it's probably being triggered by mistake:
include/qom/object.h:47: HEREinclude/qom/object.h:66: HEREinclude/qom/object.h:78: HEREinclude/qom/object.h:87: HEREinclude/qom/object.h:110: HEREinclude/qom/object.h:118: HEREinclude/qom/object.h:140: HEREinclude/qom/object.h:162: HEREinclude/qom/object.h:179: HEREinclude/qom/object.h:200: HEREinclude/qom/object.h:218: HEREinclude/qom/object.h:241: HEREinclude/qom/object.h:259: HEREinclude/qom/object.h:313: HEREinclude/qom/object.h:330: HEREinclude/qom/object.h:353: HEREinclude/qom/object.h:370: HEREinclude/qom/object.h:432: HEREinclude/qom/object.h:442: HEREinclude/qom/object.h:452: HEREinclude/qom/object.h:469: HEREinclude/qom/object.h:483: HEREinclude/qom/object.h:496: HEREinclude/qom/object.h:506: HEREinclude/qom/object.h:521: HEREinclude/qom/object.h:531: HEREinclude/qom/object.h:543: HEREinclude/qom/object.h:861: HERE
Signature · 1 line
Eduardo
PATCH 3/8 docs/conf.py: Enable use of kerneldoc sphinx extension
In reply to Paolo BonziniFrom: Peter Maydell <[email protected]>
Message-Id: <[email protected]>
--- docs/conf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
docs/conf.py +6 -1
@@ -54,7 +54,7 @@ needs_sphinx = '1.3' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['qmp_lexer'] +extensions = ['kerneldoc', 'qmp_lexer'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']
@@ -216,3 +216,8 @@ texinfo_documents = [ +# We use paths starting from qemu_docdir here so that you can run +# sphinx-build from anywhere and the kerneldoc extension can still +# find everything. +kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc') +kerneldoc_srctree = os.path.join(qemu_docdir, '..')
Signature · 1 line
2.21.0
PATCH 4/8 Makefile: disable Sphinx nitpicking
In reply to Paolo BonziniFrom: Peter Maydell <[email protected]>
Turn off Sphinx nitpicking as a temporary (?) measure so sphinx builds complete even with warnings about missing references.
Message-Id: <[email protected]>
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -1010,7 +1010,7 @@ sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html $(MANUAL_BUILDDIR)/interop/index # Note the use of different doctree for each (manual, builder) tuple; # this works around Sphinx not handling parallel invocation on # a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946 -build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -n -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") +build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") # We assume all RST files in the manual's directory are used in it manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py
Signature · 1 line
2.21.0
PATCH 5/8 bitops.h: Silence kernel-doc complaints
In reply to Paolo BonziniFrom: Peter Maydell <[email protected]>
Fix the problems with kernel-doc/sphinx syntax in the doc comments for the shuffle and unshuffle functions:
* mismatch between comment and prototype for argument name
* the inline bit patterns need to be marked up so they are processed properly and rendered as monospace
Message-Id: <[email protected]>
--- include/qemu/bitops.h | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-)
include/qemu/bitops.h +32 -20
@@ -424,13 +424,16 @@ static inline uint64_t deposit64(uint64_t value, int start, int length,/** * half_shuffle32: -* @value: 32-bit value (of which only the bottom 16 bits are of interest) +* @x: 32-bit value (of which only the bottom 16 bits are of interest) +* +* Given an input value:: +* +* xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * -* Given an input value: -* xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * return the value where the bottom 16 bits are spread out into -* the odd bits in the word, and the even bits are zeroed: -* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P +* the odd bits in the word, and the even bits are zeroed:: +* +* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P * * Any bits set in the top half of the input are ignored. *
@@ -450,13 +453,16 @@ static inline uint32_t half_shuffle32(uint32_t x)/** * half_shuffle64: -* @value: 64-bit value (of which only the bottom 32 bits are of interest) +* @x: 64-bit value (of which only the bottom 32 bits are of interest) +* +* Given an input value:: +* +* xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * -* Given an input value: -* xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * return the value where the bottom 32 bits are spread out into -* the odd bits in the word, and the even bits are zeroed: -* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f +* the odd bits in the word, and the even bits are zeroed:: +* +* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f * * Any bits set in the top half of the input are ignored. *
@@ -477,13 +483,16 @@ static inline uint64_t half_shuffle64(uint64_t x)/** * half_unshuffle32: -* @value: 32-bit value (of which only the odd bits are of interest) +* @x: 32-bit value (of which only the odd bits are of interest) +* +* Given an input value:: +* +* xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * -* Given an input value: -* xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * return the value where all the odd bits are compressed down -* into the low half of the word, and the high half is zeroed: -* 0000 0000 0000 0000 ABCD EFGH IJKL MNOP +* into the low half of the word, and the high half is zeroed:: +* +* 0000 0000 0000 0000 ABCD EFGH IJKL MNOP * * Any even bits set in the input are ignored. *
@@ -504,13 +513,16 @@ static inline uint32_t half_unshuffle32(uint32_t x)/** * half_unshuffle64: -* @value: 64-bit value (of which only the odd bits are of interest) +* @x: 64-bit value (of which only the odd bits are of interest) +* +* Given an input value:: +* +* xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * -* Given an input value: -* xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * return the value where all the odd bits are compressed down -* into the low half of the word, and the high half is zeroed: -* 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef +* into the low half of the word, and the high half is zeroed:: +* +* 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * * Any even bits set in the input are ignored. *
Signature · 1 line
2.21.0
PATCH 6/8 docs: Create bitops.rst as example of kernel-docs
In reply to Paolo BonziniFrom: Peter Maydell <[email protected]>
Create a bitops.rst which is just a container for the kernel-doc comments in qemu/bitops.h.
This is mostly a test of the kernel-doc extension machinery.
Message-Id: <[email protected]>
--- docs/devel/bitops.rst | 8 ++++++++ docs/devel/index.rst | 1 + 2 files changed, 9 insertions(+) create mode 100644 docs/devel/bitops.rst
docs/devel/bitops.rst new file +8 -0
@@ -0,0 +1,8 @@ +================== +Bitwise operations +================== + +The header ``qemu/bitops.h`` provides utility functions for +performing bitwise operations. + +.. kernel-doc:: include/qemu/bitops.h
docs/devel/index.rst +1 -0
@@ -23,3 +23,4 @@ Contents: secure-coding-practices tcg tcg-plugins + bitops
Signature · 1 line
2.21.0
PATCH 7/8 memory.h: Silence kernel-doc complaints
In reply to Paolo BonziniFix a few instances where kernel-doc complains about doc comments in memory.h.
--- include/exec/memory.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
include/exec/memory.h +10 -6
@@ -360,10 +360,14 @@ typedef struct IOMMUMemoryRegionClass {typedef struct CoalescedMemoryRange CoalescedMemoryRange ;typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd ; +/** MemoryRegion: +* +* A struct representing a memory region. +*/ struct MemoryRegion {Object parent_obj; -/* All fields are private - violators will be prosecuted */ +/* private: */ /* The following fields should fit in a cache line */ bool romd_mode;
@@ -452,7 +456,7 @@ struct MemoryListener {* AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { -/* All fields are private. */ +/* private: */ struct rcu_head rcu;char *name;MemoryRegion *root;
@@ -1673,8 +1677,8 @@ bool memory_region_is_mapped(MemoryRegion *mr);* * Returns a #MemoryRegionSection that describes a contiguous overlap. * It will have the following characteristics: -* .@size = 0 iff no overlap was found -* .@mr is non-%NULL iff an overlap was found +* - @size = 0 iff no overlap was found +* - @mr is non-%NULL iff an overlap was found * * Remember that in the return value the @offset_within_region is * relative to the returned region (in the .@mr field), not to the
@@ -1685,8 +1689,8 @@ bool memory_region_is_mapped(MemoryRegion *mr);* returned one. However, in the special case where the @mr argument * has no container (and thus is the root of the address space), the * following will hold: -* .@offset_within_address_space >= @addr -* .@offset_within_address_space + .@size <= @addr + @size +* - @offset_within_address_space >= @addr +* - @offset_within_address_space + .@size <= @addr + @size * * @mr: a MemoryRegion within which @addr is a relative address * @addr: start of the area within @as to be searched
Signature · 1 line
2.21.0
Re: [PATCH 7/8] memory.h: Silence kernel-doc complaints
Quoted 14 lines · Paolo Bonzini
Fix a few instances where kernel-doc complains about doc comments in
memory.h.Signed-off-by Paolo Bonzini <[email protected]>--- include/exec/memory.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)include/exec/memory.h +0
-0
include/exec/memory.h typedef struct IOMMUMemoryRegionClass { · line 363
Quoted 4 lines
include/exec/memory.h +1
-0@@ -360,10 +360,14 @@ typedef struct IOMMUMemoryRegionClass {typedef struct CoalescedMemoryRange CoalescedMemoryRange ;typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd ; +/** MemoryRegion:
Checkpatch thinks there should be a newline after the /**.
Quoted 43 lines
include/exec/memory.h +9
-7+* +* A struct representing a memory region. +*/ struct MemoryRegion {Object parent_obj; -/* All fields are private - violators will be prosecuted */ +/* private: */ /* The following fields should fit in a cache line */ bool romd_mode;@@ -452,7 +456,7 @@ struct MemoryListener {* AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { -/* All fields are private. */ +/* private: */ struct rcu_head rcu;char *name;MemoryRegion *root;@@ -1673,8 +1677,8 @@ bool memory_region_is_mapped(MemoryRegion *mr);* * Returns a #MemoryRegionSection that describes a contiguous overlap. * It will have the following characteristics: -* .@size = 0 iff no overlap was found -* .@mr is non-%NULL iff an overlap was found +* - @size = 0 iff no overlap was found +* - @mr is non-%NULL iff an overlap was found * * Remember that in the return value the @offset_within_region is * relative to the returned region (in the .@mr field), not to the @@ -1685,8 +1689,8 @@ bool memory_region_is_mapped(MemoryRegion *mr);* returned one. However, in the special case where the @mr argument * has no container (and thus is the root of the address space), the * following will hold: -* .@offset_within_address_space >= @addr -* .@offset_within_address_space + .@size <= @addr + @size +* - @offset_within_address_space >= @addr +* - @offset_within_address_space + .@size <= @addr + @size * * @mr: a MemoryRegion within which @addr is a relative address * @addr: start of the area within @as to be searched --
Quoted 1 line
2.21.0
thanks
-- PMM
PATCH 8/8 docs: add memory API reference
In reply to Paolo BonziniAdd kernel-doc directive to parse and include doc comments from include/exec/memory.h.
--- docs/devel/memory.rst | 5 +++++ 1 file changed, 5 insertions(+)
docs/devel/memory.rst +5 -0
@@ -361,3 +361,8 @@ callbacks are called: - .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses. + +API Reference +------------- + +.. kernel-doc:: include/exec/memory.h
Signature · 1 line
2.21.0
Re: [PATCH 8/8] docs: add memory API reference
Quoted 23 lines · Paolo Bonzini
Add kernel-doc directive to parse and include doc comments from
include/exec/memory.h.Signed-off-by Paolo Bonzini <[email protected]>--- docs/devel/memory.rst | 5 +++++ 1 file changed, 5 insertions(+)docs/devel/memory.rst +5
-1@@ -361,3 +361,8 @@ callbacks are called: - .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses. + +API Reference +------------- + +.. kernel-doc:: include/exec/memory.h --
Quoted 1 line
2.21.0
thanks
-- PMM
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [PATCH for-5.0 0/8] docs: integrate doc comments with Sphinx build
Type: series
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Switched to a new branch 'test'
b3ce185 docs: add memory API reference
de50eba memory.h: Silence kernel-doc complaints 0f0cc93 docs: Create bitops.rst as example of kernel-docs 7de419c bitops.h: Silence kernel-doc complaints 0ac6a81 Makefile: disable Sphinx nitpicking
0b3c7c9 docs/conf.py: Enable use of kerneldoc sphinx extension 10457ca docs: tweak kernel-doc for QEMU coding standards f7a1036 docs: import Linux kernel-doc script and extension
=== OUTPUT BEGIN ===
1/8 Checking commit f7a103632856 (docs: import Linux kernel-doc script and extension)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #20:
new file mode 100644
WARNING: line over 80 characters
#102: FILE: docs/sphinx/kerneldoc.py:78:
+ tab_width = self.options.get('tab-width', self.state.document.settings.tab_width)
WARNING: line over 80 characters
#132: FILE: docs/sphinx/kerneldoc.py:108:
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ERROR: line over 90 characters
#141: FILE: docs/sphinx/kerneldoc.py:117:
+ 'kernel-doc \'%s\' failed with return code %d' % (" ".join(cmd), p.returncode))
WARNING: line over 80 characters
#142: FILE: docs/sphinx/kerneldoc.py:118:
+ return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
WARNING: line over 80 characters
#146: FILE: docs/sphinx/kerneldoc.py:122:
+ lines = statemachine.string2lines(out, tab_width, convert_whitespace=True)
WARNING: line over 80 characters
#167: FILE: docs/sphinx/kerneldoc.py:143:
+ kernellog.warn(env.app, 'kernel-doc \'%s\' processing failed with: %s' %
WARNING: line over 80 characters
#169: FILE: docs/sphinx/kerneldoc.py:145:
+ return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
ERROR: line over 90 characters
#176: FILE: docs/sphinx/kerneldoc.py:152:
+ save = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
WARNING: line over 80 characters
#177: FILE: docs/sphinx/kerneldoc.py:153:
+ self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter)
ERROR: line over 90 characters
#182: FILE: docs/sphinx/kerneldoc.py:158:
+ self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = save
total: 3 errors, 8 warnings, 2426 lines checked
Patch 1/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
2/8 Checking commit 10457ca7be94 (docs: tweak kernel-doc for QEMU coding standards) 3/8 Checking commit 0b3c7c9f8788 (docs/conf.py: Enable use of kerneldoc sphinx extension) 4/8 Checking commit 0ac6a8162879 (Makefile: disable Sphinx nitpicking)
5/8 Checking commit 7de419c91dc7 (bitops.h: Silence kernel-doc complaints) 6/8 Checking commit 0f0cc9310e25 (docs: Create bitops.rst as example of kernel-docs)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100644
total: 0 errors, 1 warnings, 12 lines checked
Patch 6/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/8 Checking commit de50ebaf7d96 (memory.h: Silence kernel-doc complaints)
WARNING: Block comments use a leading /* on a separate line #21: FILE: include/exec/memory.h:363:
+/** MemoryRegion:
total: 0 errors, 1 warnings, 43 lines checked
Patch 7/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/8 Checking commit b3ce1857d7cb (docs: add memory API reference) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 10 lines · Paolo Bonzini
This merges my series and Peter's into one. Both the memory API and bitwise operation APIs are covered.
Paolo Bonzini (4):
docs: import Linux kernel-doc script and extension
docs: tweak kernel-doc for QEMU coding standardsmemory.h: Silence kernel-doc complaints
docs: add memory API reference
Quoted 5 lines
Peter Maydell (4):
docs/conf.py: Enable use of kerneldoc sphinx extension
Makefile: disable Sphinx nitpicking
bitops.h: Silence kernel-doc complaints
docs: Createbitops.rstas example of kernel-docs
Thanks for folding those two series together; I've left review comments on the parts I didn't write.
Do you have a URL of a rendered version of the docs somewhere handy to save me applying the series locally ?
thanks
-- PMM
Quoted 17 lines · Peter Maydell
Quoted 10 lines · Paolo Bonzini
This merges my series and Peter's into one. Both the memory API and bitwise operation APIs are covered.
Paolo Bonzini (4):
docs: import Linux kernel-doc script and extension
docs: tweak kernel-doc for QEMU coding standardsmemory.h: Silence kernel-doc complaints
docs: add memory API referenceQuoted 5 lines
Peter Maydell (4):
docs/conf.py: Enable use of kerneldoc sphinx extension
Makefile: disable Sphinx nitpicking
bitops.h: Silence kernel-doc complaints
docs: Createbitops.rstas example of kernel-docs
Quoted 5 lines
Thanks for folding those two series together; I've left review comments on the parts I didn't write.
Do you have a URL of a rendered version of the docs somewhere handy to save me applying the series locally ?
No, I don't.
Paolo