[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/36] doc/sphinx/hxtool.py: add optional label argument to SRST d
From: |
Peter Maydell |
Subject: |
[PULL 12/36] doc/sphinx/hxtool.py: add optional label argument to SRST directive |
Date: |
Fri, 2 Feb 2024 15:36:13 +0000 |
From: David Woodhouse <dwmw@amazon.co.uk>
We can't just embed labels directly into files like qemu-options.hx which
are included from multiple top-level rST files, because Sphinx sees the
labels as duplicate: https://github.com/sphinx-doc/sphinx/issues/9707
So add an optional argument to the SRST directive which causes a label
of the form '.. _DOCNAME-HXFILE-LABEL:' to be emitted, where 'DOCNAME'
is the name of the top level rST file, 'HXFILE' is the filename of the
.hx file, and 'LABEL' is the text provided within the 'SRST()' directive.
Using the DOCNAME of the top-level rST document means that it is unique
even when the .hx file is included from two different documents, as is
the case for qemu-options.hx
Now where the Xen PV documentation refers to the documentation for the
-initrd command line option, it can emit a link directly to it as
'<system/invocation-qemu-options-initrd>'.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20240130190348.682912-1-dwmw2@infradead.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
docs/devel/docs.rst | 12 ++++++++++--
docs/sphinx/hxtool.py | 16 ++++++++++++++++
docs/system/i386/xen.rst | 3 ++-
qemu-options.hx | 2 +-
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/docs/devel/docs.rst b/docs/devel/docs.rst
index 7da067905b8..50ff0d67f84 100644
--- a/docs/devel/docs.rst
+++ b/docs/devel/docs.rst
@@ -30,6 +30,13 @@ nor the documentation output.
``SRST`` starts a reStructuredText section. Following lines
are put into the documentation verbatim, and discarded from the C output.
+The alternative form ``SRST()`` is used to define a label which can be
+referenced from elsewhere in the rST documentation. The label will take
+the form ``<DOCNAME-HXFILE-LABEL>``, where ``DOCNAME`` is the name of the
+top level rST file, ``HXFILE`` is the filename of the .hx file without
+the ``.hx`` extension, and ``LABEL`` is the text provided within the
+``SRST()`` directive. For example,
+``<system/invocation-qemu-options-initrd>``.
``ERST`` ends the documentation section started with ``SRST``,
and switches back to a C code section.
@@ -53,8 +60,9 @@ text, but in ``hmp-commands.hx`` the C code sections are
elements
of an array of structs of type ``HMPCommand`` which define the
name, behaviour and help text for each monitor command.
-In the file ``qemu-options.hx``, do not try to define a
+In the file ``qemu-options.hx``, do not try to explicitly define a
reStructuredText label within a documentation section. This file
is included into two separate Sphinx documents, and some
versions of Sphinx will complain about the duplicate label
-that results.
+that results. Use the ``SRST()`` directive documented above, to
+emit an unambiguous label.
diff --git a/docs/sphinx/hxtool.py b/docs/sphinx/hxtool.py
index 9f6b9d87dcc..3729084a36c 100644
--- a/docs/sphinx/hxtool.py
+++ b/docs/sphinx/hxtool.py
@@ -78,6 +78,14 @@ def parse_archheading(file, lnum, line):
serror(file, lnum, "Invalid ARCHHEADING line")
return match.group(1)
+def parse_srst(file, lnum, line):
+ """Handle an SRST directive"""
+ # The input should be either "SRST", or "SRST(label)".
+ match = re.match(r'SRST(\((.*?)\))?', line)
+ if match is None:
+ serror(file, lnum, "Invalid SRST line")
+ return match.group(2)
+
class HxtoolDocDirective(Directive):
"""Extract rST fragments from the specified .hx file"""
required_argument = 1
@@ -113,6 +121,14 @@ def run(self):
serror(hxfile, lnum, 'expected ERST, found SRST')
else:
state = HxState.RST
+ label = parse_srst(hxfile, lnum, line)
+ if label:
+ rstlist.append("", hxfile, lnum - 1)
+ # Build label as _DOCNAME-HXNAME-LABEL
+ hx = os.path.splitext(os.path.basename(hxfile))[0]
+ refline = ".. _" + env.docname + "-" + hx + \
+ "-" + label + ":"
+ rstlist.append(refline, hxfile, lnum - 1)
elif directive == 'ERST':
if state == HxState.CTEXT:
serror(hxfile, lnum, 'expected SRST, found ERST')
diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst
index 81898768baa..46db5f34c1d 100644
--- a/docs/system/i386/xen.rst
+++ b/docs/system/i386/xen.rst
@@ -132,7 +132,8 @@ The example above provides the guest kernel command line
after a separator
(" ``--`` ") on the Xen command line, and does not provide the guest kernel
with an actual initramfs, which would need to listed as a second multiboot
module. For more complicated alternatives, see the command line
-documentation for the ``-initrd`` option.
+:ref:`documentation <system/invocation-qemu-options-initrd>` for the
+``-initrd`` option.
Host OS requirements
--------------------
diff --git a/qemu-options.hx b/qemu-options.hx
index 40e938c4877..5adbed11013 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3994,7 +3994,7 @@ ERST
DEF("initrd", HAS_ARG, QEMU_OPTION_initrd, \
"-initrd file use 'file' as initial ram disk\n", QEMU_ARCH_ALL)
-SRST
+SRST(initrd)
``-initrd file``
Use file as initial ram disk.
--
2.34.1
- [PULL 10/36] tests/qtest/xlnx-versal-trng-test.c: Drop use of variable length array, (continued)
- [PULL 10/36] tests/qtest/xlnx-versal-trng-test.c: Drop use of variable length array, Peter Maydell, 2024/02/02
- [PULL 07/36] system/vl.c: Fix handling of '-serial none -serial something', Peter Maydell, 2024/02/02
- [PULL 11/36] target/arm: Reinstate "vfp" property on AArch32 CPUs, Peter Maydell, 2024/02/02
- [PULL 13/36] hw/arm/exynos: Add missing QOM parent for CPU cores, Peter Maydell, 2024/02/02
- [PULL 14/36] hw/arm/exynos: Check for CPU types in machine_run_board_init(), Peter Maydell, 2024/02/02
- [PULL 15/36] hw/arm/highbank: Add missing QOM parent for CPU cores, Peter Maydell, 2024/02/02
- [PULL 16/36] hw/arm/highbank: Check for CPU types in machine_run_board_init(), Peter Maydell, 2024/02/02
- [PULL 20/36] hw/arm/vexpress: Check for CPU types in machine_run_board_init(), Peter Maydell, 2024/02/02
- [PULL 18/36] hw/arm/musca: Simplify setting MachineClass::valid_cpu_types[], Peter Maydell, 2024/02/02
- [PULL 17/36] hw/arm/msf2: Simplify setting MachineClass::valid_cpu_types[], Peter Maydell, 2024/02/02
- [PULL 12/36] doc/sphinx/hxtool.py: add optional label argument to SRST directive,
Peter Maydell <=
- [PULL 19/36] hw/arm/npcm7xx_boards: Simplify setting MachineClass::valid_cpu_types[], Peter Maydell, 2024/02/02
- [PULL 22/36] pci-host: designware: Limit value range of iATU viewport register, Peter Maydell, 2024/02/02
- [PULL 24/36] hw/arm/z2: convert DPRINTF to trace events and guest errors, Peter Maydell, 2024/02/02
- [PULL 26/36] hw/xen/xen-mapcache.c: convert DPRINTF to tracepoints, Peter Maydell, 2024/02/02
- [PULL 27/36] hw/xen/xen-hvm-common.c: convert DPRINTF to tracepoints, Peter Maydell, 2024/02/02
- [PULL 21/36] hw/arm/zynq: Check for CPU types in machine_run_board_init(), Peter Maydell, 2024/02/02
- [PULL 28/36] hw/xen: convert stderr prints to error/warn reports, Peter Maydell, 2024/02/02
- [PULL 30/36] hw/arm: Add GMAC devices to NPCM7XX SoC, Peter Maydell, 2024/02/02
- [PULL 32/36] hw/net: GMAC Rx Implementation, Peter Maydell, 2024/02/02
- [PULL 29/36] hw/net: Add NPCMXXX GMAC device, Peter Maydell, 2024/02/02