[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proposal for handling .hx files with Sphinx
Re: Proposal for handling .hx files with Sphinx
Mon, 20 Jan 2020 19:20:22 -0500
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0
On 1/17/20 12:30 PM, Peter Maydell wrote:
> Currently our manual creation includes some .texi files which
> are autogenerated from .hx files by running scripts/hxtool.
> .hx files are a simple format, where where a line is either a
> directive or literal text to be output:
> -- comment lines, ignored
> -- mark start/end of chunks of text to put into the texinfo output only
> -- appear in the .h file output verbatim (they are defined as C macros);
> for texi output they are parsed to add in header sections
> For Sphinx, rather than creating a file to include, the most
> natural way to handle this is to have a small custom Sphinx
> extension which will read the .hx file and process it. So
> instead of "makefile produces foo.texi from foo.hx, qemu-doc.texi
> says '@include foo.texi'", we have "qemu-doc.rst says
> 'hxtool-doc:: foo.hx', the Sphinx extension for hxtool has
> code that runs to handle that Sphinx directive, it reads the .hx
> file and emits the appropriate documentation contents". (This is
> pretty much the same way the kerneldoc extension works right now.
> It also has the advantage that it should work for third-party
> services like readthedocs that expect to build the docs directly
> with sphinx rather than by invoking our makefiles.)
> We'll need to update what the markup is to handle having rST
> fragments in it. A very minimalist approach to this would
> simply define a new pair of SRST/ERST directives marking the
> start/end of chunks of rST text to go into the rST only.
> (We might be able to do better than that later, as there's
> some repetition currently going on. But we'll probably get
> a better idea of how easy it is to avoid the repetition if
> we start with a simple conversion.)
> Here's what we do with hx files at the moment. We have four:
> -- defines monitor commands used by monitor.c; generates
> qemu-monitor.texi, used by qemu-doc.texi
> -- ditto, for the "info" command's subcommand;
> generates qemu-monitor-info.texi, used by qemu-doc.texi
> These two use only the "put this in the texi or in the .h file"
> functionality, alternating "raw C code defining an entry for the
> monitor command array" with "lump of raw texi for the docs".
> -- defines options for qemu-img, used by qemu-img.texi
> This uses the STEXI/ETEXI directives to alternate C and texi.
> In the for-the-h-file section the only content is always a DEF()
> macro invocation defining the option; in the texi is only the
> synopsis of the command. This means there's a lot of repetition,
> as the DEF macro includes an argument giving the text of the
> option synopsis, and then the texi also has that synopsis with
> some extra markup. Finally the main qemu-img.texi repeats the
> marked-up synopsis later on when it has the actual main documentation
> of each command.
> -- options for qemu proper, used by qemu-doc.texi
> This uses only the DEF, DEFHEADING, ARCHHEADING macros
> in the for-the-h-file sections (and the DEFHEADING/ARCHHEADING
> are read also for texi generation). This also repeats the
> synopsis in the DEF macro and in the texi fragment.
> So I think my current view is that we should do the very
> simple "add SRST/ERST directives" to start with:
> * scripts/hxtool needs to recognize them and just ignore
> the text inside them
> * write the hxtool sphinx extension (shouldn't be too hard)
> * conversion of any particular .hx file then involves
> replacing the STEXI ...texi stuff... ETEXI sections with
> SRST ...rst stuff... ERST. There's no need for any
> particular .hx file to support both texi and rst output
> at the same time
> I would initially start with qemu-img-cmds.hx, since that's
> pulled in by qemu-img.texi, which we can convert in the
> same way I've been doing qemu-nbd and other standalone-ish
> manpages. The others are part of the big fat qemu-doc.texi,
> which is probably going to be the very last thing we convert...
At one point I did a quick mockup of turning qemu-img-cmds.hx into json
and wrote a small tool I called "pxtool" that was used for generating
all the rest of the subsequent information -- an attempt at getting rid
of .hx files *entirely*.
The idea at heart was: "Can we remove .hx files and describe everything
in terms of the QAPI schema instead?"
I'm still a bit partial to that idea, but realize there are some nasty
complexities when it comes to describing the QEMU CLI as a schema. One
of those is that I doubt we even have a full understanding of what the
CLI syntax is at all.
Still, I do want to ask: Are we sure we want to double-down on keeping
the .hx files around instead of trying to move to a more generic data