Features/Documentation: Difference between revisions

From QEMU
No edit summary
(Overhaul entirely to document the current plan-of-record (as sent to qemu-devel))
Line 18: Line 18:
: doc comments in the source code
: doc comments in the source code
: automatically generated docs for Python classes in qemu-iotests and scripts/qmp
: automatically generated docs for Python classes in qemu-iotests and scripts/qmp
: not to be shipped to end users (unlike the other manuals)


== Choices ==
== Choices ==
Line 23: Line 24:
Based on experience from the Linux kernel, QEMU's docs pipeline is going to be based on Sphinx ([http://people.linaro.org/~peter.maydell/sphinx/memory.html sample developer doc], [http://people.redhat.com/pbonzini/qemu-test-doc/_build/html/ sample user doc].  Sphinx is extensible and it is easy to add new input formats and input directives.
Based on experience from the Linux kernel, QEMU's docs pipeline is going to be based on Sphinx ([http://people.linaro.org/~peter.maydell/sphinx/memory.html sample developer doc], [http://people.redhat.com/pbonzini/qemu-test-doc/_build/html/ sample user doc].  Sphinx is extensible and it is easy to add new input formats and input directives.


Currently, QEMU documentation is written in a mix of Texinfo and text files roughly based on Markdown.  Sphinx's native format is reStructuredText (rST). Texinfo input is not supported by Sphinx, but Paolo has a [http://docutils.sourceforge.net/ docutils] (Sphinx-compatible) parser for Docbook; Texinfo is able to convert .texi input files into Docbook. This parser was used to produce the sample user doc above.
Currently, QEMU documentation is written in a mix of Texinfo and text files roughly based on Markdown.  Sphinx's native format is reStructuredText (rST). The plan is to (eventually) convert everything to rST format.


Currently, QEMU doc comments have never been actually used together with a actual documentation generator in mind, but they are roughly based on gtk-doc syntax.  We will probably end up keeping a copy of the Linux kernel's kernel-doc script.  kernel-doc's main supported backends are rST and Docbook.
Currently, QEMU doc comments have never been actually used together with a actual documentation generator in mind, but they are roughly based on gtk-doc syntax.  We will probably end up keeping a copy of the Linux kernel's kernel-doc script.  kernel-doc's main supported backend is rST. There is a GSoC project to look at generating API documentation from our doc comments.


As a first step, we should decide how to evolve this into something more structured.
== Pre-Sphinx status ==


For text, the two possible choices should ultimately be:
(This concentrates on the documentation that's installed by 'make install', because anything else is for developers only, making it lower priority to clean up and more amenable to messing around with anyway.)


# Convert everything to reStructuredText
As of QEMU 4.0 (early 2019) we install:
#:'''Advantages:''' Flexible enough, native format for Sphinx, Linux is using it
#:'''Disadvantages:''' Less "obvious" than Markdown (looks somewhat weird when you use more advanced features, though a basic conversion seems to be simple enough), expect some hand editing after Texinfo->rST conversion (makeinfo --docbook + either Pandoc or db2rst.py).
# Convert everything to Texinfo
#:'''Advantages:''' qemu-doc.texi and command-line doc comments are already written in Texinfo, QAPI automatically generated docs also use Texinfo in the current version of the patches; more traditional/"precise" markup
#:'''Disadvantages:''' Most different from basic ASCII text, markup not supported by kernel-doc


Even though docs/ is currently written in Markdown-like format and there is a Sphinx extension to parse Markdown, it's unlikely to be a third contender.
* in $DESTDIR/usr/local/share/doc/qemu:
qemu-doc.html
qemu-ga-ref.html
qemu-qmp-ref.html
qemu-doc.txt
qemu-ga-ref.txt
qemu-qmp-ref.txt
interop/  (the only Sphinx manual we currently ship)


For C doc comments, the three possible choices are:
* in $DESTDIR/usr/local/share/man/:
man1/qemu.1
man1/qemu-img.1
man1/virtfs-proxy-helper.1
man1/qemu-trace-stap.1
man8/qemu-ga.8
man8/qemu-nbd.8
man7/qemu-block-drivers.7
man7/qemu-cpu-models.7
man7/qemu-ga-ref.7
man7/qemu-qmp-ref.7
(possibly I missed one or two files, because what we install depends on configure options and maybe my test build-n-install didn't build everything we might ship.)


# Use reStructuredText markup
This documentation is generated from a mix of:
#:'''Advantages:''' Flexible enough, native format for Sphinx, Linux is using it
#:'''Disadvantages:''' Would use rST for doc comments but not for the rest of docs/, or for command-line doc comments?
# Extend kernel-doc to support Texinfo markup, and convert that to Docbook
#:'''Advantages:''' qemu-doc.texi and command-line doc comments are already written in Texinfo
#:'''Disadvantages:''' More work to do, Rube Goldberg would be proud
# Use no markup, apart from annotating fields, functions etc. using sigils (e.g. kernel-doc's <tt>&struct Foo</tt> or <tt>%Foo</tt>).
#:'''Advantages:''' Simplest solution, can use any kernel-doc backend (DocBook and rST), doesn't conflict with chioce of format for docs/
#:'''Disadvantages:''' none?


We should also choose whether to place comments close to the definition or the declaration of functionsLinux seems to place comments close to the definition&mdash;the disadvantage being that struct comments must obviously be placed in headers.
* hand-written texinfo:
qemu-doc.texi (a top level file with both content and @include directives)
qemu-deprecated.texi
qemu-ga.texi
qemu-img.texi
qemu-nbd.texi
qemu-option-trace.texi
  qemu-tech.texi
docs/security.texi
docs/qemu-cpu-models.texi
docs/qemu-block-drivers.texi
docs/interop/qemu-ga-ref.texi
docs/interop/qemu-qmp-ref.texi
fsdev/virtfs-proxy-helper.texi
scripts/qemu-trace-stap.texi
* texinfo sections extracted from *.hx files by hxtool
* texinfo autogenerated from json by qapi-gen.py


== Sample command-line invocation ==
(The .html and .txt files are generated from the texinfo directly; the manpages via texi2pod and pod2man, which effectively create the manpages from marked-up subsqections of the input texi.)
The build-time workflow for Texinfo-based documentation is:
* convert Texinfo to docbook4 using makeinfo
* convert docbook4 to docbook5 using [http://docbook.org/xml/5.0b9/tools/db4-upgrade.xsl xsltproc]
* split the huge docbook output using [http://doccookbook.sourceforge.net/html/en/dbc.structure.splitting-into-topics.html xsltproc again]


makeinfo --docbook -o qemu-doc.xml ../qemu-doc.texi
== Intended final status ==
xsltproc db4-upgrade.xsl qemu-doc.xml | \
  xsltproc --stringparam chunk.section.depth 1 \
            --stringparam assembly.filename index.xml \
            --stringparam base.dir topics/ \
            /usr/share/sgml/docbook/xsl-ns-stylesheets-1.79.1/assembly/topic-maker-chunk.xsl


For docs/-based documentation, each .txt file becomes one .texi file, included by a "master" document with lines like
We eventually want to have:


@chapter ACPI interface
* in $DESTDIR/usr/local/share/doc/qemu:
  @include acpi-cpu-hotplug.texi
  interop/ sphinx manual
   
  system/ sphinx manual (system emulation user's guide)
  @chapter Registries
  user/ sphinx manual (user-mode emulation user's guide)
  @include pci-ids.texi
  specs/ sphinx manual (guest hardware etc specs)


where each .texi file defines a @section.
* in $DESTDIR/usr/local/share/man/:
the same set of manpages we have currently


Sphinx can invoke kernel-doc through the same extension that Linux is using (if using the rST backend) or a similar one (if using the docbook backend). The Texinfo markup would look like the following:
* not actually installed:
  devel/ sphinx manual


@macro kerneldoc{file}
Sphinx supports a "plain text" output format, so we could create a "one big text file" format output for each of our four installed manuals. However there doesn't seem to be much support for retaining a plain-text version of the documentation, so we should just ship the HTML version.
@docbook
<sphinx:directive xmlns:sphinx="https://pypi.python.org/pypi/db4sphinx"
        sphinx:name="kernel-doc" sphinx:arg="\file\"/>
@end docbook
@end macro
@kerneldoc{include/exec/memory.h}


== Things to do ==
== Transition plan ==


For now in no particular order:
This is based on the plan proposed in this email: https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg04932.html
* Prepare five wiki pages to work collaboratively on the manuals' table of contents, populate them with current qemu-doc.texi ToC and a list of docs/ files.
* Split qemu-doc.texi so that the bulk of its contents is included from small files in docs/
* Annotate developer documentation in {{src|path=docs/}} with the corresponding C source code, so as to prioritize where to add doc comments


Things missing in the Sphinx docbook frontend:
=== 0: API documentation generation ===
* needs to be tested against Marc-André's QAPI generator
 
Work on generating API documentation can be done independently and is not addressed here, because that will just go into the devel/
manual, and doesn't interact at all with the user-facing manuals.
 
=== 1: qemu-ga-ref and qemu-qmp-ref ===
 
qemu-ga-ref and qemu-qmp-ref will become part of the interop/ manual. This requires:
* adding rst-generation support to qapi-gen.py
* converting the hand-written texinfo parts to rst
* listing those new .rst files in docs/interop/index.rst
* makefile runes to create manpages via the 'man' sphinx builder from docs/interop/qemu-ga-ref.rst and qemu-qmp-ref.rst
* there is a tests/qapi-schema/doc-good.test.texi which I think is acting as a test of the texi doc generation; this should be converted to test the rst doc generation instead
* delete all the old texinfo build machinery, install runes, etc
 
We could do this as its own patch series which would end up with a result that would be fine to ship, even if we don't get any of the
other manuals converted for a particular QEMU release.  It's the easiest part because these docs already have an obvious home in a Sphinx manual we're already shipping.
 
For the "create manpage" part, Sphinx supports a "manpage" builder, which I have not yet investigated closely but which I'm hoping will do what we need. It works by specifying a list of "this .rst becomes this manpage in this manpage-section", so we can for instance have the qemu-ga-ref and qemu-qmp-ref be subsections of the HTML interop/ manual but also pulled out into their own manpages. (It is also possible to make sections of a .rst file be output only for particular builders, but there seem to be some limitations on it -- notably it filters the output but it doesn't affect things like tables of contents for formats which have them. I am hoping we can do what we want without it.)
 
=== 2: Move developer docs into devel manual ===
 
Any parts of the texi docs which are really "developer docs" should be moved into devel/
 
This is easy because we don't need to maintain a very coherent manual for devel/, we can just have it be a bucket of random documents for the moment. In particular:
 
* the qemu-tech.texi "translator internals" section should be moved (I suspect it's a bit out of date so we should add a warning note at the top of the new file about that)
* I think we should just delete the "QEMU compared to other emulators" section of qemu-tech.texi (and the accompanying bibliography of URLs) since it hasn't been updated in several years and it's not really documenting QEMU. This sort of general-information stuff would  live better on the wiki if we care about it at all.
* I don't think there's anything else that's really developer documentation, but I haven't looked too closely
 
A patchset doing this has been sent to the list.
 
=== 3: Convert things which are mostly standalone manpages ===
 
Round about here things start to get trickier because we are looking at things which are part of the big fat qemu-doc.html.  The easiest next pieces to pull out are the ones which are standalone manpages which we're also just using @include to stuff into qemu-doc.html:
* qemu-ga.texi
* qemu-nbd.texi
* qemu-img.texi
* qemu-cpu-models.texi
* qemu-block-drivers.texi
* virtfs-proxy-helper.texi
* scripts/qemu-trace-stap.texi
 
We can:
* convert each of these to a .rst file in the right sphinx manual (probably mostly system/)
* generate the manpage output using sphinx as we did for qemu-ga-ref etc
* just drop the @include from qemu-doc.texi
 
qemu-img.texi here will be the tricky one as it uses hxtool to generate the texi for the command line option descriptions. I'm not sure how best to handle hxtool, because it is really just a mechanism for slicing the right fragments out of the input file. Perhaps we need to add SRST/ERST directives to match the STEXI/ETEXI ones we have at the moment.
 
This will result in a slightly "bucket of distinct docs" feel to the system/ manual at this point, but these files are all basically mostly self-contained, so it wouldn't be too terrible to ship a QEMU in this state.
 
=== 4: Convert everything else ===
 
At this point what we have left is:
* qemu-doc.texi itself
* qemu-deprecated.texi
* docs/security.texi
* qemu-option-trace.texi
* the leftovers from qemu-tech.texi
* the stuff generated via hxtool from hmp-commands-info.hx, hmp-commands.hx and qemu-options.hx
 
and we pretty much need to:
* convert all that over to rst in the system/ and user/ manuals (perhaps sometimes interop/)
* generate the qemu.1 manpage
* delete all the leftover machinery
 
We could do at least some of this in chunks, but if we had to release QEMU midway through this part of the transition we'd have a very weird setup where half the core-emulator-docs were in the old html file and the other half were in the new style manuals, so we should definitely try to avoid doing that.

Revision as of 17:35, 7 June 2019

QEMU's documentation needs some reorganization.

Ultimately there should be five manuals:

QEMU user mode emulation (docs/user, Features/Documentation/user)
currently in qemu-doc.texi
QEMU full-system emulation user's guide (docs/system, Features/Documentation/system)
Category:User documentation
the largest part of qemu-doc.texi
also covers qemu-img, qemu-io
docs/ (not subdirectories)
QEMU full-system emulation management and interoperability guide (docs/interop, Features/Documentation/interop)
QEMU full-system emulation guest hardware specifications (docs/specs, Features/Documentation/specs)
QEMU developer's guide (docs/devel, Features/Documentation/devel)
Category:Developer documentation
docs/devel/
the implementation notes in qemu-doc.texi
tcg/README
doc comments in the source code
automatically generated docs for Python classes in qemu-iotests and scripts/qmp
not to be shipped to end users (unlike the other manuals)

Choices

Based on experience from the Linux kernel, QEMU's docs pipeline is going to be based on Sphinx (sample developer doc, sample user doc. Sphinx is extensible and it is easy to add new input formats and input directives.

Currently, QEMU documentation is written in a mix of Texinfo and text files roughly based on Markdown. Sphinx's native format is reStructuredText (rST). The plan is to (eventually) convert everything to rST format.

Currently, QEMU doc comments have never been actually used together with a actual documentation generator in mind, but they are roughly based on gtk-doc syntax. We will probably end up keeping a copy of the Linux kernel's kernel-doc script. kernel-doc's main supported backend is rST. There is a GSoC project to look at generating API documentation from our doc comments.

Pre-Sphinx status

(This concentrates on the documentation that's installed by 'make install', because anything else is for developers only, making it lower priority to clean up and more amenable to messing around with anyway.)

As of QEMU 4.0 (early 2019) we install:

  • in $DESTDIR/usr/local/share/doc/qemu:
qemu-doc.html
qemu-ga-ref.html
qemu-qmp-ref.html
qemu-doc.txt
qemu-ga-ref.txt
qemu-qmp-ref.txt
interop/  (the only Sphinx manual we currently ship)
  • in $DESTDIR/usr/local/share/man/:
man1/qemu.1
man1/qemu-img.1
man1/virtfs-proxy-helper.1
man1/qemu-trace-stap.1
man8/qemu-ga.8
man8/qemu-nbd.8
man7/qemu-block-drivers.7
man7/qemu-cpu-models.7
man7/qemu-ga-ref.7
man7/qemu-qmp-ref.7

(possibly I missed one or two files, because what we install depends on configure options and maybe my test build-n-install didn't build everything we might ship.)

This documentation is generated from a mix of:

  • hand-written texinfo:
qemu-doc.texi (a top level file with both content and @include directives)
qemu-deprecated.texi
qemu-ga.texi
qemu-img.texi
qemu-nbd.texi
qemu-option-trace.texi
qemu-tech.texi
docs/security.texi
docs/qemu-cpu-models.texi
docs/qemu-block-drivers.texi
docs/interop/qemu-ga-ref.texi
docs/interop/qemu-qmp-ref.texi
fsdev/virtfs-proxy-helper.texi
scripts/qemu-trace-stap.texi
  • texinfo sections extracted from *.hx files by hxtool
  • texinfo autogenerated from json by qapi-gen.py

(The .html and .txt files are generated from the texinfo directly; the manpages via texi2pod and pod2man, which effectively create the manpages from marked-up subsqections of the input texi.)

Intended final status

We eventually want to have:

  • in $DESTDIR/usr/local/share/doc/qemu:
interop/ sphinx manual
system/ sphinx manual (system emulation user's guide)
user/ sphinx manual (user-mode emulation user's guide)
specs/ sphinx manual (guest hardware etc specs)
  • in $DESTDIR/usr/local/share/man/:
the same set of manpages we have currently
  • not actually installed:
devel/ sphinx manual

Sphinx supports a "plain text" output format, so we could create a "one big text file" format output for each of our four installed manuals. However there doesn't seem to be much support for retaining a plain-text version of the documentation, so we should just ship the HTML version.

Transition plan

This is based on the plan proposed in this email: https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg04932.html

0: API documentation generation

Work on generating API documentation can be done independently and is not addressed here, because that will just go into the devel/ manual, and doesn't interact at all with the user-facing manuals.

1: qemu-ga-ref and qemu-qmp-ref

qemu-ga-ref and qemu-qmp-ref will become part of the interop/ manual. This requires:

  • adding rst-generation support to qapi-gen.py
  • converting the hand-written texinfo parts to rst
  • listing those new .rst files in docs/interop/index.rst
  • makefile runes to create manpages via the 'man' sphinx builder from docs/interop/qemu-ga-ref.rst and qemu-qmp-ref.rst
  • there is a tests/qapi-schema/doc-good.test.texi which I think is acting as a test of the texi doc generation; this should be converted to test the rst doc generation instead
  • delete all the old texinfo build machinery, install runes, etc

We could do this as its own patch series which would end up with a result that would be fine to ship, even if we don't get any of the other manuals converted for a particular QEMU release. It's the easiest part because these docs already have an obvious home in a Sphinx manual we're already shipping.

For the "create manpage" part, Sphinx supports a "manpage" builder, which I have not yet investigated closely but which I'm hoping will do what we need. It works by specifying a list of "this .rst becomes this manpage in this manpage-section", so we can for instance have the qemu-ga-ref and qemu-qmp-ref be subsections of the HTML interop/ manual but also pulled out into their own manpages. (It is also possible to make sections of a .rst file be output only for particular builders, but there seem to be some limitations on it -- notably it filters the output but it doesn't affect things like tables of contents for formats which have them. I am hoping we can do what we want without it.)

2: Move developer docs into devel manual

Any parts of the texi docs which are really "developer docs" should be moved into devel/

This is easy because we don't need to maintain a very coherent manual for devel/, we can just have it be a bucket of random documents for the moment. In particular:

  • the qemu-tech.texi "translator internals" section should be moved (I suspect it's a bit out of date so we should add a warning note at the top of the new file about that)
  • I think we should just delete the "QEMU compared to other emulators" section of qemu-tech.texi (and the accompanying bibliography of URLs) since it hasn't been updated in several years and it's not really documenting QEMU. This sort of general-information stuff would live better on the wiki if we care about it at all.
  • I don't think there's anything else that's really developer documentation, but I haven't looked too closely

A patchset doing this has been sent to the list.

3: Convert things which are mostly standalone manpages

Round about here things start to get trickier because we are looking at things which are part of the big fat qemu-doc.html. The easiest next pieces to pull out are the ones which are standalone manpages which we're also just using @include to stuff into qemu-doc.html:

  • qemu-ga.texi
  • qemu-nbd.texi
  • qemu-img.texi
  • qemu-cpu-models.texi
  • qemu-block-drivers.texi
  • virtfs-proxy-helper.texi
  • scripts/qemu-trace-stap.texi

We can:

  • convert each of these to a .rst file in the right sphinx manual (probably mostly system/)
  • generate the manpage output using sphinx as we did for qemu-ga-ref etc
  • just drop the @include from qemu-doc.texi

qemu-img.texi here will be the tricky one as it uses hxtool to generate the texi for the command line option descriptions. I'm not sure how best to handle hxtool, because it is really just a mechanism for slicing the right fragments out of the input file. Perhaps we need to add SRST/ERST directives to match the STEXI/ETEXI ones we have at the moment.

This will result in a slightly "bucket of distinct docs" feel to the system/ manual at this point, but these files are all basically mostly self-contained, so it wouldn't be too terrible to ship a QEMU in this state.

4: Convert everything else

At this point what we have left is:

  • qemu-doc.texi itself
  • qemu-deprecated.texi
  • docs/security.texi
  • qemu-option-trace.texi
  • the leftovers from qemu-tech.texi
  • the stuff generated via hxtool from hmp-commands-info.hx, hmp-commands.hx and qemu-options.hx

and we pretty much need to:

  • convert all that over to rst in the system/ and user/ manuals (perhaps sometimes interop/)
  • generate the qemu.1 manpage
  • delete all the leftover machinery

We could do at least some of this in chunks, but if we had to release QEMU midway through this part of the transition we'd have a very weird setup where half the core-emulator-docs were in the old html file and the other half were in the new style manuals, so we should definitely try to avoid doing that.