Skip to contentSkip to conversation

qapi doc generation (whole version, squashed)

PATCH Superseded Marc-André Lureau 4 participants 28 messages Nov 7, 2016 – Nov 15, 2016 Kbuild

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover qapi doc generation (whole version, squashed)

Add a qapi2texi script to generate the documentation from the qapi schemas.

The 13th patch in this series is a squashed version of the documentation move from qmp-commands.txt to the schemas. The whole version (not sent on the ML to avoid spamming) is in the following git
branch: https://github.com/elmarco/qemu/commits/qapi-doc

v3:
- many improvements to the doc parser:
- throws an error in various malformated conditions
- allows multiple meta-sections, except for "Since:" and "Return:"
- build a list of docs, instead of attaching docs to expressions
- accept() breaks on new doc block, and get_doc() returns a QAPIDoc
- fix more documentation to fit the new parser
- use a master texi file that includes the generated file, instead of templated texi file
- texi fixes after Markus review
- only build and install html and man pages by default
- fix .gitignore

v2:
- change licence to be lgpl2+
- fix some comments & commit message
- add more code comments
- improve the doc parsing to treat only "Since" as a special case not requiring ":" (common notation in the doc)
- include some early schema doc fixes (to fix generated doc)
- include the squashed version of the doc move
- include the man page and installation build changes

Marc-André Lureau (14):
qapi: add missing 'bus' argument in device_add qga/schema: fix double-return in doc qga/schema: improve guest-set-vcpus Returns: section
qapi: fix schema symbol sections
qapi: fix missing symbol @prefix
qapi: fix various symbols mismatch in documentation
qapi: use one symbol per line
qapi: add missing colon-ending for section name
qapi: add some sections in docs
docs: add master qapi texi files
qapi: add qapi2texi script
texi2pod: learn quotation, deftp and deftypefn
qmp-commands: (SQUASHED) move doc to schema
build-sys: add qapi doc generation targets

 Makefile                      |   57 +-
 scripts/qapi.py               |  175 +-
 scripts/qapi2texi.py          |  316 ++++
 scripts/texi2pod.pl           |   44 +-
 .gitignore                    |   11 +-
 docs/qapi-code-gen.txt        |   44 +-
 docs/qemu-ga-ref.texi         |   65 +
 docs/qemu-qmp-ref.texi        |  156 ++
 docs/qmp-commands.txt         | 3824 -----------------------------------------
 docs/qmp-events.txt           |  731 --------
 docs/qmp-intro.txt            |   87 -
 docs/writing-qmp-commands.txt |    2 +-
 qapi-schema.json              | 1621 +++++++++++++++--
 qapi/block-core.json          |  894 ++++++++--
 qapi/block.json               |   82 +-
 qapi/common.json              |   52 +-
 qapi/crypto.json              |   41 +-
 qapi/event.json               |  304 +++-
 qapi/introspect.json          |   28 +-
 qapi/rocker.json              |   63 +-
 qapi/trace.json               |   25 +-
 qga/qapi-schema.json          |   64 +-
 22 files changed, 3583 insertions(+), 5103 deletions(-)
 create mode 100755 scripts/qapi2texi.py
 create mode 100644 docs/qemu-ga-ref.texi
 create mode 100644 docs/qemu-qmp-ref.texi
 delete mode 100644 docs/qmp-commands.txt
 delete mode 100644 docs/qmp-events.txt
 delete mode 100644 docs/qmp-intro.txt
Signature · 1 line
2.10.0
#1 lore raw

PATCH v3 1/14 qapi: add missing 'bus' argument in device_add

'device_add' is incomplete for now, but 'bus' is a common argument for regarless of the device, and is present in documentation. Add it to the device_add schema definition.

---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi-schema.json +1 -1
index b0b4bf6..4ba5772 100644
@@ -2317,7 +2317,7 @@
 # Since: 0.13
 ##
 { 'command': 'device_add',
-  'data': {'driver': 'str', 'id': 'str'},
+  'data': {'driver': 'str', '*bus': 'str', 'id': 'str'},
   'gen': false } # so we can get the additional arguments
 
 ##
Signature · 1 line
2.10.0
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/14] qapi: add missing 'bus' argument in device_add

Quoted 14 lines · Marc-André Lureau

'device_add' is incomplete for now, but 'bus' is a common argument for regarless of the device, and is present in documentation. Add it to the device_add schema definition.

---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi-schema.json +0 -0
index b0b4bf6..4ba5772 100644

qapi-schema.json line 2323

Quoted 8 lines
qapi-schema.json +1 -1
@@ -2317,7 +2317,7 @@
 # Since: 0.13
 ##
 { 'command': 'device_add',
-  'data': {'driver': 'str', 'id': 'str'},
+  'data': {'driver': 'str', '*bus': 'str', 'id': 'str'},
   'gen': false } # so we can get the additional arguments
 
 ##

Makes sense.

@id is actually optional, care to fix that, too?

#3 lore raw

Re: [Qemu-devel] [PATCH v3 01/14] qapi: add missing 'bus' argument in device_add

In reply to Marc-André Lureau
Quoted 2 lines · Marc-André Lureau

'device_add' is incomplete for now, but 'bus' is a common argument for regarless of the device, and is present in documentation. Add it to the

s/regarless/regardless/

Quoted 21 lines

device_add schema definition.

---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi-schema.json +1 -1
index b0b4bf6..4ba5772 100644
@@ -2317,7 +2317,7 @@
 # Since: 0.13
 ##
 { 'command': 'device_add',
-  'data': {'driver': 'str', 'id': 'str'},
+  'data': {'driver': 'str', '*bus': 'str', 'id': 'str'},
   'gen': false } # so we can get the additional arguments
 
 ##
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

PATCH v3 2/14 qga/schema: fix double-return in doc

In reply to Marc-André Lureau

guest-get-memory-block-info documentation should have only one "Returns:".

---
 qga/qapi-schema.json | 1 -
 1 file changed, 1 deletion(-)
qga/qapi-schema.json +0 -1
index c21f308..758803a 100644
@@ -952,7 +952,6 @@
 #
 # Get information relating to guest memory blocks.
 #
-# Returns: memory block size in bytes.
 # Returns: @GuestMemoryBlockInfo
 #
 # Since 2.3
Signature · 1 line
2.10.0
Reviewed-by on v3 2/14
#5 lore raw

Re: [Qemu-devel] [PATCH v3 02/14] qga/schema: fix double-return in doc

Quoted 7 lines · Marc-André Lureau

guest-get-memory-block-info documentation should have only one "Returns:".

---
 qga/qapi-schema.json | 1 -
 1 file changed, 1 deletion(-)
Quoted 14 lines
qga/qapi-schema.json +0 -1
index c21f308..758803a 100644
@@ -952,7 +952,6 @@
 #
 # Get information relating to guest memory blocks.
 #
-# Returns: memory block size in bytes.
 # Returns: @GuestMemoryBlockInfo
 #
 # Since 2.3
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

PATCH v3 3/14 qga/schema: improve guest-set-vcpus Returns: section

In reply to Marc-André Lureau

The documentation parser finishes a section after an empty line. Fix the
Returns: section of guest-set-vcpus, and itemize the possible return values.

---
 qga/qapi-schema.json | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
qga/qapi-schema.json +4 -8
index 758803a..cb68c17 100644
@@ -696,22 +696,18 @@
 #
 # Returns: The length of the initial sublist that has been successfully
 #          processed. The guest agent maximizes this value. Possible cases:
-#
-#          0:                if the @vcpus list was empty on input. Guest state
+#          - 0:              if the @vcpus list was empty on input. Guest state
 #                            has not been changed. Otherwise,
-#
-#          Error:            processing the first node of @vcpus failed for the
+#          - Error:          processing the first node of @vcpus failed for the
 #                            reason returned. Guest state has not been changed.
 #                            Otherwise,
-#
-#          < length(@vcpus): more than zero initial nodes have been processed,
+#          - < length(@vcpus): more than zero initial nodes have been processed,
 #                            but not the entire @vcpus list. Guest state has
 #                            changed accordingly. To retrieve the error
 #                            (assuming it persists), repeat the call with the
 #                            successfully processed initial sublist removed.
 #                            Otherwise,
-#
-#          length(@vcpus):   call successful.
+#          - length(@vcpus): call successful.
 #
 # Since: 1.5
 ##
Signature · 1 line
2.10.0
#7 lore raw

Re: [Qemu-devel] [PATCH v3 03/14] qga/schema: improve guest-set-vcpus Returns: section

Quoted 1 line · Marc-André Lureau

The documentation parser finishes a section after an empty line. Fix the

Suggest "The documentation parser we're going to add".

Quoted 29 lines

Returns: section of guest-set-vcpus, and itemize the possible return values.

---
 qga/qapi-schema.json | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
qga/qapi-schema.json +3 -6
index 758803a..cb68c17 100644
@@ -696,22 +696,18 @@
 #
 # Returns: The length of the initial sublist that has been successfully
 #          processed. The guest agent maximizes this value. Possible cases:
-#
-#          0:                if the @vcpus list was empty on input. Guest state
+#          - 0:              if the @vcpus list was empty on input. Guest state
 #                            has not been changed. Otherwise,
-#
-#          Error:            processing the first node of @vcpus failed for the
+#          - Error:          processing the first node of @vcpus failed for the
 #                            reason returned. Guest state has not been changed.
 #                            Otherwise,
-#
-#          < length(@vcpus): more than zero initial nodes have been processed,
+#          - < length(@vcpus): more than zero initial nodes have been processed,
 #                            but not the entire @vcpus list. Guest state has

qga/qapi-schema.json line 713

Quoted 10 lines
qga/qapi-schema.json +1 -2
 #                            changed accordingly. To retrieve the error
 #                            (assuming it persists), repeat the call with the
 #                            successfully processed initial sublist removed.
 #                            Otherwise,
-#
-#          length(@vcpus):   call successful.
+#          - length(@vcpus): call successful.
 #
 # Since: 1.5
 ##

Matches how we format similar lists elswhere.

If the "empty line ends section" syntax turns out to be inconvenient, we can try to consider indentation. But not now.

#8 lore raw

PATCH v3 4/14 qapi: fix schema symbol sections

In reply to Marc-André Lureau

According to docs/qapi-code-gen.txt, there needs to be '##' to start a and end a symbol section, that's also what the documentation parser expects.

---
 qapi-schema.json     | 18 +++++++++++++-----
 qapi/block-core.json |  1 +
 qga/qapi-schema.json |  3 +++
 3 files changed, 17 insertions(+), 5 deletions(-)
qapi-schema.json +13 -5
index 4ba5772..1d8ad72 100644
@@ -65,6 +65,7 @@
 { 'enum': 'LostTickPolicy',
   'data': ['discard', 'delay', 'merge', 'slew' ] }
 
+##
 # @add_client
 #
 # Allow client connections for VNC, Spice and socket based
@@ -442,6 +443,7 @@
            'cache-miss': 'int', 'cache-miss-rate': 'number',
            'overflow': 'int' } }
 
+##
 # @MigrationStatus:
 #
 # An enumeration of migration status.
@@ -627,6 +629,7 @@
 ##
 { 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
 
+##
 # @MigrationParameter
 #
 # Migration parameters enumeration
@@ -685,7 +688,7 @@
            'tls-creds', 'tls-hostname', 'max-bandwidth',
            'downtime-limit', 'x-checkpoint-delay' ] }
 
-#
+##
 # @migrate-set-parameters
 #
 # Set various migration parameters.  See MigrationParameters for details.
@@ -697,7 +700,7 @@
 { 'command': 'migrate-set-parameters', 'boxed': true,
   'data': 'MigrationParameters' }
 
-#
+##
 # @MigrationParameters
 #
 # Optional members can be omitted on input ('migrate-set-parameters')
@@ -795,6 +798,7 @@
 # command.
 #
 # Since: 2.5
+##
 { 'command': 'migrate-start-postcopy' }
 
 ##
@@ -2252,6 +2256,7 @@
 ##
 { 'command': 'migrate-incoming', 'data': {'uri': 'str' } }
 
+##
 # @xen-save-devices-state:
 #
 # Save the state of all devices to file. The RAM and the block devices
@@ -3482,6 +3487,7 @@
             'modelb': 'CpuModelInfo' },
   'returns': 'CpuModelBaselineInfo' }
 
+##
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
@@ -4530,14 +4536,16 @@
 ##
 { 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] }
 
-## @ACPISlotType
+##
+# @ACPISlotType
 #
 # @DIMM: memory slot
 # @CPU: logical CPU slot (since 2.7)
-#
+##
 { 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }
 
-## @ACPIOSTInfo
+##
+# @ACPIOSTInfo
 #
 # OSPM Status Indication for a device
 # For description of possible values of @source and @status fields
qapi/block-core.json +1 -0
index bcd3b9e..5108b42 100644
@@ -2810,6 +2810,7 @@
             'offset': 'int',
             'speed' : 'int' } }
 
+##
 # @PreallocMode
 #
 # Preallocation mode of QEMU image file
qga/qapi-schema.json +3 -0
index cb68c17..5173c4a 100644
@@ -833,6 +833,7 @@
 { 'command': 'guest-set-user-password',
   'data': { 'username': 'str', 'password': 'str', 'crypted': 'bool' } }
 
+##
 # @GuestMemoryBlock:
 #
 # @phys-index: Arbitrary guest-specific unique identifier of the MEMORY BLOCK.
@@ -932,6 +933,7 @@
   'data':    {'mem-blks': ['GuestMemoryBlock'] },
   'returns': ['GuestMemoryBlockResponse'] }
 
+##
 # @GuestMemoryBlockInfo:
 #
 # @size: the size (in bytes) of the guest memory blocks,
@@ -955,6 +957,7 @@
 { 'command': 'guest-get-memory-block-info',
   'returns': 'GuestMemoryBlockInfo' }
 
+##
 # @GuestExecStatus:
 #
 # @exited: true if process has already terminated.
Signature · 1 line
2.10.0
Reviewed-by on v3 4/14
#9 lore raw

Re: [Qemu-devel] [PATCH v3 04/14] qapi: fix schema symbol sections

Quoted 10 lines · Marc-André Lureau

According to docs/qapi-code-gen.txt, there needs to be '##' to start a and end a symbol section, that's also what the documentation parser expects.

---
 qapi-schema.json     | 18 +++++++++++++-----
 qapi/block-core.json |  1 +
 qga/qapi-schema.json |  3 +++
 3 files changed, 17 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

PATCH v3 5/14 qapi: fix missing symbol @prefix

In reply to Marc-André Lureau
---
 qapi-schema.json     |  4 ++--
 qapi/block-core.json |  4 ++--
 qapi/crypto.json     | 36 ++++++++++++++++++------------------
 3 files changed, 22 insertions(+), 22 deletions(-)
qapi-schema.json +2 -2
index 1d8ad72..5f377fa 100644
@@ -4650,7 +4650,7 @@
 { 'include': 'qapi/rocker.json' }
 
 ##
-# ReplayMode:
+# @ReplayMode:
 #
 # Mode of the replay subsystem.
 #
@@ -4718,7 +4718,7 @@
 { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
 
 ##
-# CpuInstanceProperties
+# @CpuInstanceProperties
 #
 # List of properties to be used for hotplugging a CPU instance,
 # it should be passed by management with device_add command when
qapi/block-core.json +2 -2
index 5108b42..372889c 100644
@@ -1144,7 +1144,7 @@
   'data': 'DriveMirror' }
 
 ##
-# DriveMirror
+# @DriveMirror
 #
 # A set of parameters describing drive mirror setup.
 #
@@ -1368,7 +1368,7 @@
   'data': 'BlockIOThrottle' }
 
 ##
-# BlockIOThrottle
+# @BlockIOThrottle
 #
 # A set of parameters describing block throttling.
 #
qapi/crypto.json +18 -18
index 5c9d7d4..15d296e 100644
@@ -3,7 +3,7 @@
 # QAPI crypto definitions
 
 ##
-# QCryptoTLSCredsEndpoint:
+# @QCryptoTLSCredsEndpoint:
 #
 # The type of network endpoint that will be using the credentials.
 # Most types of credential require different setup / structures
@@ -22,7 +22,7 @@
 
 
 ##
-# QCryptoSecretFormat:
+# @QCryptoSecretFormat:
 #
 # The data format that the secret is provided in
 #
@@ -36,7 +36,7 @@
 
 
 ##
-# QCryptoHashAlgorithm:
+# @QCryptoHashAlgorithm:
 #
 # The supported algorithms for computing content digests
 #
@@ -55,7 +55,7 @@
 
 
 ##
-# QCryptoCipherAlgorithm:
+# @QCryptoCipherAlgorithm:
 #
 # The supported algorithms for content encryption ciphers
 #
@@ -82,7 +82,7 @@
 
 
 ##
-# QCryptoCipherMode:
+# @QCryptoCipherMode:
 #
 # The supported modes for content encryption ciphers
 #
@@ -98,7 +98,7 @@
 
 
 ##
-# QCryptoIVGenAlgorithm:
+# @QCryptoIVGenAlgorithm:
 #
 # The supported algorithms for generating initialization
 # vectors for full disk encryption. The 'plain' generator
@@ -116,7 +116,7 @@
   'data': ['plain', 'plain64', 'essiv']}
 
 ##
-# QCryptoBlockFormat:
+# @QCryptoBlockFormat:
 #
 # The supported full disk encryption formats
 #
@@ -131,7 +131,7 @@
   'data': ['qcow', 'luks']}
 
 ##
-# QCryptoBlockOptionsBase:
+# @QCryptoBlockOptionsBase:
 #
 # The common options that apply to all full disk
 # encryption formats
@@ -144,7 +144,7 @@
   'data': { 'format': 'QCryptoBlockFormat' }}
 
 ##
-# QCryptoBlockOptionsQCow:
+# @QCryptoBlockOptionsQCow:
 #
 # The options that apply to QCow/QCow2 AES-CBC encryption format
 #
@@ -158,7 +158,7 @@
   'data': { '*key-secret': 'str' }}
 
 ##
-# QCryptoBlockOptionsLUKS:
+# @QCryptoBlockOptionsLUKS:
 #
 # The options that apply to LUKS encryption format
 #
@@ -172,7 +172,7 @@
 
 
 ##
-# QCryptoBlockCreateOptionsLUKS:
+# @QCryptoBlockCreateOptionsLUKS:
 #
 # The options that apply to LUKS encryption format initialization
 #
@@ -202,7 +202,7 @@
 
 
 ##
-# QCryptoBlockOpenOptions:
+# @QCryptoBlockOpenOptions:
 #
 # The options that are available for all encryption formats
 # when opening an existing volume
@@ -217,7 +217,7 @@
 
 
 ##
-# QCryptoBlockCreateOptions:
+# @QCryptoBlockCreateOptions:
 #
 # The options that are available for all encryption formats
 # when initializing a new volume
@@ -232,7 +232,7 @@
 
 
 ##
-# QCryptoBlockInfoBase:
+# @QCryptoBlockInfoBase:
 #
 # The common information that applies to all full disk
 # encryption formats
@@ -246,7 +246,7 @@
 
 
 ##
-# QCryptoBlockInfoLUKSSlot:
+# @QCryptoBlockInfoLUKSSlot:
 #
 # Information about the LUKS block encryption key
 # slot options
@@ -266,7 +266,7 @@
 
 
 ##
-# QCryptoBlockInfoLUKS:
+# @QCryptoBlockInfoLUKS:
 #
 # Information about the LUKS block encryption options
 #
@@ -294,7 +294,7 @@
            'slots': [ 'QCryptoBlockInfoLUKSSlot' ] }}
 
 ##
-# QCryptoBlockInfoQCow:
+# @QCryptoBlockInfoQCow:
 #
 # Information about the QCow block encryption options
 #
@@ -305,7 +305,7 @@
 
 
 ##
-# QCryptoBlockInfo:
+# @QCryptoBlockInfo:
 #
 # Information about the block encryption options
 #
Signature · 1 line
2.10.0
Reviewed-by on v3 5/14
#11 lore raw

Re: [Qemu-devel] [PATCH v3 05/14] qapi: fix missing symbol @prefix

Quoted 6 lines · Marc-André Lureau
---
 qapi-schema.json     |  4 ++--
 qapi/block-core.json |  4 ++--
 qapi/crypto.json     | 36 ++++++++++++++++++------------------
 3 files changed, 22 insertions(+), 22 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw

PATCH v3 6/14 qapi: fix various symbols mismatch in documentation

In reply to Marc-André Lureau

There are various mismatch:
- invalid symbols
- section and member symbols mismatch
- enum or union values vs 'type'

The documentation parser catches all these cases.

---
 qapi-schema.json     | 20 +++++++++-----------
 qapi/block-core.json |  4 ----
 qapi/common.json     |  6 +++---
 qapi/rocker.json     |  2 +-
 qga/qapi-schema.json |  6 +++---
 5 files changed, 16 insertions(+), 22 deletions(-)
qapi-schema.json +9 -11
index 5f377fa..0c9a293 100644
@@ -693,8 +693,6 @@
 #
 # Set various migration parameters.  See MigrationParameters for details.
 #
-# @x-checkpoint-delay: the delay time between two checkpoints. (Since 2.8)
-#
 # Since: 2.4
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
@@ -1171,7 +1169,7 @@
            '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} }
 
 ##
-# @VncPriAuth:
+# @VncPrimaryAuth:
 #
 # vnc primary authentication method.
 #
@@ -3174,7 +3172,7 @@
 #
 # @alias: #optional an alias for the machine name
 #
-# @default: #optional whether the machine is default
+# @is-default: #optional whether the machine is default
 #
 # @cpu-max: maximum number of CPUs supported by the machine type
 #           (since 1.5.0)
@@ -3727,7 +3725,6 @@
 #
 # @device: The name of the special file for the device,
 #          i.e. /dev/ttyS0 on Unix or COM1: on Windows
-# @type: What kind of device this is.
 #
 # Since: 1.4
 ##
@@ -3992,7 +3989,7 @@
 #
 # A union referencing different TPM backend types' configuration options
 #
-# @passthrough: The configuration options for the TPM passthrough type
+# @type: 'passthrough' The configuration options for the TPM passthrough type
 #
 # Since: 1.5
 ##
@@ -4000,7 +3997,7 @@
    'data': { 'passthrough' : 'TPMPassthroughOptions' } }
 
 ##
-# @TpmInfo:
+# @TPMInfo:
 #
 # Information about the TPM
 #
@@ -4344,10 +4341,11 @@
 #
 # Input event union.
 #
-# @key: Input event of Keyboard
-# @btn: Input event of pointer buttons
-# @rel: Input event of relative pointer motion
-# @abs: Input event of absolute pointer motion
+# @type: the input type, one of:
+#  - 'key': Input event of Keyboard
+#  - 'btn': Input event of pointer buttons
+#  - 'rel': Input event of relative pointer motion
+#  - 'abs': Input event of absolute pointer motion
 #
 # Since: 2.0
 ##
qapi/block-core.json +0 -4
index 372889c..c64a48c 100644
@@ -2160,10 +2160,6 @@
 #
 # @type:       Transport type used for gluster connection
 #
-# @unix:       socket file
-#
-# @tcp:        host address and port number
-#
 # This is similar to SocketAddress, only distinction:
 #
 # 1. GlusterServer is a flat union, SocketAddress is a simple union.
qapi/common.json +3 -3
index 9353a7b..6987100 100644
@@ -34,11 +34,11 @@
 #
 # A three-part version number.
 #
-# @qemu.major:  The major version number.
+# @major:  The major version number.
 #
-# @qemu.minor:  The minor version number.
+# @minor:  The minor version number.
 #
-# @qemu.micro:  The micro version number.
+# @micro:  The micro version number.
 #
 # Since: 2.4
 ##
qapi/rocker.json +1 -1
index 2fe7fdf..ace2776 100644
@@ -1,5 +1,5 @@
 ##
-# @Rocker:
+# @RockerSwitch:
 #
 # Rocker switch information.
 #
qga/qapi-schema.json +3 -3
index 5173c4a..2e6cc91 100644
@@ -203,7 +203,7 @@
 #
 # Open a file in the guest and retrieve a file handle for it
 #
-# @filepath: Full path to the file in the guest to open.
+# @path: Full path to the file in the guest to open.
 #
 # @mode: #optional open mode, as per fopen(), "r" is the default.
 #
@@ -378,7 +378,7 @@
   'data': { 'handle': 'int' } }
 
 ##
-# @GuestFsFreezeStatus
+# @GuestFsfreezeStatus
 #
 # An enumeration of filesystem freeze states
 #
@@ -766,7 +766,7 @@
 # @GuestDiskAddress:
 #
 # @pci-controller: controller's PCI address
-# @type: bus type
+# @bus-type: bus type
 # @bus: bus id
 # @target: target id
 # @unit: unit id
Signature · 1 line
2.10.0
#13 lore raw

Re: [Qemu-devel] [PATCH v3 06/14] qapi: fix various symbols mismatch in documentation

Quoted 79 lines · Marc-André Lureau

There are various mismatch:
- invalid symbols
- section and member symbols mismatch
- enum or union values vs 'type'

The documentation parser catches all these cases.

---
 qapi-schema.json     | 20 +++++++++-----------
 qapi/block-core.json |  4 ----
 qapi/common.json     |  6 +++---
 qapi/rocker.json     |  2 +-
 qga/qapi-schema.json |  6 +++---
 5 files changed, 16 insertions(+), 22 deletions(-)
qapi-schema.json +4 -9
index 5f377fa..0c9a293 100644
@@ -693,8 +693,6 @@
 #
 # Set various migration parameters.  See MigrationParameters for details.
 #
-# @x-checkpoint-delay: the delay time between two checkpoints. (Since 2.8)
-#
 # Since: 2.4
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
@@ -1171,7 +1169,7 @@
            '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} }
 
 ##
-# @VncPriAuth:
+# @VncPrimaryAuth:
 #
 # vnc primary authentication method.
 #
@@ -3174,7 +3172,7 @@
 #
 # @alias: #optional an alias for the machine name
 #
-# @default: #optional whether the machine is default
+# @is-default: #optional whether the machine is default
 #
 # @cpu-max: maximum number of CPUs supported by the machine type
 #           (since 1.5.0)
@@ -3727,7 +3725,6 @@
 #
 # @device: The name of the special file for the device,
 #          i.e. /dev/ttyS0 on Unix or COM1: on Windows
-# @type: What kind of device this is.
 #
 # Since: 1.4
 ##
@@ -3992,7 +3989,7 @@
 #
 # A union referencing different TPM backend types' configuration options
 #
-# @passthrough: The configuration options for the TPM passthrough type
+# @type: 'passthrough' The configuration options for the TPM passthrough type
 #
 # Since: 1.5
 ##
@@ -4000,7 +3997,7 @@
    'data': { 'passthrough' : 'TPMPassthroughOptions' } }
 
 ##
-# @TpmInfo:
+# @TPMInfo:
 #
 # Information about the TPM
 #
@@ -4344,10 +4341,11 @@
 #
 # Input event union.
 #
-# @key: Input event of Keyboard
-# @btn: Input event of pointer buttons

qapi-schema.json line 4351

Quoted 10 lines
qapi-schema.json +5 -2
-# @rel: Input event of relative pointer motion
-# @abs: Input event of absolute pointer motion
+# @type: the input type, one of:
+#  - 'key': Input event of Keyboard
+#  - 'btn': Input event of pointer buttons
+#  - 'rel': Input event of relative pointer motion
+#  - 'abs': Input event of absolute pointer motion
 #
 # Since: 2.0
 ##

This will do for now, but we need to figure out how to document unions properly.

Quoted 5 lines
qapi/block-core.json +0 -0
index 372889c..c64a48c 100644

qapi/block-core.json line 2165

Quoted 10 lines
qapi/block-core.json +0 -4
@@ -2160,10 +2160,6 @@
 #
 # @type:       Transport type used for gluster connection
 #
-# @unix:       socket file
-#
-# @tcp:        host address and port number
-#
 # This is similar to SocketAddress, only distinction:
 #
 # 1. GlusterServer is a flat union, SocketAddress is a simple union.

Unions again. We lose a bit of information here, but it's almost worthless information.

Quoted 53 lines
qapi/common.json +3 -3
index 9353a7b..6987100 100644
@@ -34,11 +34,11 @@
 #
 # A three-part version number.
 #
-# @qemu.major:  The major version number.
+# @major:  The major version number.
 #
-# @qemu.minor:  The minor version number.
+# @minor:  The minor version number.
 #
-# @qemu.micro:  The micro version number.
+# @micro:  The micro version number.
 #
 # Since: 2.4
 ##
qapi/rocker.json +1 -1
index 2fe7fdf..ace2776 100644
@@ -1,5 +1,5 @@
 ##
-# @Rocker:
+# @RockerSwitch:
 #
 # Rocker switch information.
 #
qga/qapi-schema.json +2 -2
index 5173c4a..2e6cc91 100644
@@ -203,7 +203,7 @@
 #
 # Open a file in the guest and retrieve a file handle for it
 #
-# @filepath: Full path to the file in the guest to open.
+# @path: Full path to the file in the guest to open.
 #
 # @mode: #optional open mode, as per fopen(), "r" is the default.
 #
@@ -378,7 +378,7 @@
   'data': { 'handle': 'int' } }
 
 ##
-# @GuestFsFreezeStatus
+# @GuestFsfreezeStatus
 #
 # An enumeration of filesystem freeze states
 #

qga/qapi-schema.json line 772

Quoted 8 lines
qga/qapi-schema.json +1 -1
@@ -766,7 +766,7 @@
 # @GuestDiskAddress:
 #
 # @pci-controller: controller's PCI address
-# @type: bus type
+# @bus-type: bus type
 # @bus: bus id
 # @target: target id
 # @unit: unit id

Lovely doc fixes :)

#14 lore raw

PATCH v3 7/14 qapi: use one symbol per line

In reply to Marc-André Lureau

The documentation parser only handles a single symbol per line.

---
 qapi/block-core.json | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
qapi/block-core.json +6 -2
index c64a48c..e1cc94a 100644
@@ -1712,9 +1712,13 @@
 #
 # Drivers that are supported in block device operations.
 #
-# @host_device, @host_cdrom: Since 2.1
+# @host_device: Since 2.1
+# @host_cdrom: Since 2.1
 # @gluster: Since 2.7
-# @nbd, @nfs, @replication, @ssh: Since 2.8
+# @nbd: Since 2.8
+# @nfs: Since 2.8
+# @replication: Since 2.8
+# @ssh: Since 2.8
 #
 # Since: 2.0
 ##
Signature · 1 line
2.10.0
#15 lore raw

Re: [Qemu-devel] [PATCH v3 07/14] qapi: use one symbol per line

Quoted 1 line · Marc-André Lureau

The documentation parser only handles a single symbol per line.

Suggest "The documentation parser we're going to add".

Quoted 15 lines
---
 qapi/block-core.json | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
qapi/block-core.json +1 -1
index c64a48c..e1cc94a 100644
@@ -1712,9 +1712,13 @@
 #
 # Drivers that are supported in block device operations.
 #
-# @host_device, @host_cdrom: Since 2.1
+# @host_device: Since 2.1

qapi/block-core.json line 1724

Quoted 10 lines
qapi/block-core.json +5 -1
+# @host_cdrom: Since 2.1
 # @gluster: Since 2.7
-# @nbd, @nfs, @replication, @ssh: Since 2.8
+# @nbd: Since 2.8
+# @nfs: Since 2.8
+# @replication: Since 2.8
+# @ssh: Since 2.8
 #
 # Since: 2.0
 ##

If we had more, I'd consider making the doc parser smarter, but it's not worth the bother just for this one.

#16 lore raw

PATCH v3 8/14 qapi: add missing colon-ending for section name

In reply to Marc-André Lureau

The documentation parser expects a section name to end with ':', otherwise the comment is treated as free-form text body.

---
 qapi-schema.json     | 300 +++++++++++++++++++++++++--------------------------
 qapi/block-core.json | 196 ++++++++++++++++-----------------
 qapi/block.json      |  16 +--
 qapi/common.json     |   8 +-
 qapi/event.json      |  58 +++++-----
 qapi/introspect.json |  28 ++---
 qapi/trace.json      |   8 +-
 qga/qapi-schema.json |  44 ++++----
 8 files changed, 329 insertions(+), 329 deletions(-)
qapi-schema.json +150 -150
index 0c9a293..e9605b0 100644
@@ -66,7 +66,7 @@
   'data': ['discard', 'delay', 'merge', 'slew' ] }
 
 ##
-# @add_client
+# @add_client:
 #
 # Allow client connections for VNC, Spice and socket based
 # character devices to be passed in to QEMU via SCM_RIGHTS.
@@ -97,7 +97,7 @@
 #
 # @name: #optional The name of the guest
 #
-# Since 0.14.0
+# Since: 0.14.0
 ##
 { 'struct': 'NameInfo', 'data': {'*name': 'str'} }
 
@@ -108,7 +108,7 @@
 #
 # Returns: @NameInfo of the guest
 #
-# Since 0.14.0
+# Since: 0.14.0
 ##
 { 'command': 'query-name', 'returns': 'NameInfo' }
 
@@ -137,7 +137,7 @@
 { 'command': 'query-kvm', 'returns': 'KvmInfo' }
 
 ##
-# @RunState
+# @RunState:
 #
 # An enumeration of VM run states.
 #
@@ -235,7 +235,7 @@
 #
 # Returns: The @UuidInfo for the guest
 #
-# Since 0.14.0
+# Since: 0.14.0
 ##
 { 'command': 'query-uuid', 'returns': 'UuidInfo' }
 
@@ -382,7 +382,7 @@
 { 'command': 'query-events', 'returns': ['EventInfo'] }
 
 ##
-# @MigrationStats
+# @MigrationStats:
 #
 # Detailed migration status.
 #
@@ -396,7 +396,7 @@
 #
 # @skipped: number of skipped zero pages (since 1.5)
 #
-# @normal : number of normal pages (since 1.2)
+# @normal: number of normal pages (since 1.2)
 #
 # @normal-bytes: number of normal bytes sent (since 1.2)
 #
@@ -420,7 +420,7 @@
            'postcopy-requests' : 'int' } }
 
 ##
-# @XBZRLECacheStats
+# @XBZRLECacheStats:
 #
 # Detailed XBZRLE migration cache statistics
 #
@@ -474,7 +474,7 @@
             'active', 'postcopy-active', 'completed', 'failed', 'colo' ] }
 
 ##
-# @MigrationInfo
+# @MigrationInfo:
 #
 # Information about current migration process.
 #
@@ -534,7 +534,7 @@
            '*error-desc': 'str'} }
 
 ##
-# @query-migrate
+# @query-migrate:
 #
 # Returns information about current migration process.
 #
@@ -545,7 +545,7 @@
 { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
 
 ##
-# @MigrationCapability
+# @MigrationCapability:
 #
 # Migration capabilities enumeration
 #
@@ -593,7 +593,7 @@
            'compress', 'events', 'postcopy-ram', 'x-colo'] }
 
 ##
-# @MigrationCapabilityStatus
+# @MigrationCapabilityStatus:
 #
 # Migration capability information
 #
@@ -607,7 +607,7 @@
   'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } }
 
 ##
-# @migrate-set-capabilities
+# @migrate-set-capabilities:
 #
 # Enable/Disable the following migration capabilities (like xbzrle)
 #
@@ -619,7 +619,7 @@
   'data': { 'capabilities': ['MigrationCapabilityStatus'] } }
 
 ##
-# @query-migrate-capabilities
+# @query-migrate-capabilities:
 #
 # Returns information about the current migration capabilities status
 #
@@ -630,7 +630,7 @@
 { 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
 
 ##
-# @MigrationParameter
+# @MigrationParameter:
 #
 # Migration parameters enumeration
 #
@@ -689,7 +689,7 @@
            'downtime-limit', 'x-checkpoint-delay' ] }
 
 ##
-# @migrate-set-parameters
+# @migrate-set-parameters:
 #
 # Set various migration parameters.  See MigrationParameters for details.
 #
@@ -699,7 +699,7 @@
   'data': 'MigrationParameters' }
 
 ##
-# @MigrationParameters
+# @MigrationParameters:
 #
 # Optional members can be omitted on input ('migrate-set-parameters')
 # but most members will always be present on output
@@ -758,7 +758,7 @@
             '*x-checkpoint-delay': 'int'} }
 
 ##
-# @query-migrate-parameters
+# @query-migrate-parameters:
 #
 # Returns information about the current migration parameters
 #
@@ -770,7 +770,7 @@
   'returns': 'MigrationParameters' }
 
 ##
-# @client_migrate_info
+# @client_migrate_info:
 #
 # Set migration information for remote display.  This makes the server
 # ask the client to automatically reconnect using the new parameters
@@ -789,7 +789,7 @@
             '*tls-port': 'int', '*cert-subject': 'str' } }
 
 ##
-# @migrate-start-postcopy
+# @migrate-start-postcopy:
 #
 # Followup to a migration command to switch the migration to postcopy mode.
 # The postcopy-ram capability must be set before the original migration
@@ -800,7 +800,7 @@
 { 'command': 'migrate-start-postcopy' }
 
 ##
-# @COLOMessage
+# @COLOMessage:
 #
 # The message transmission between Primary side and Secondary side.
 #
@@ -826,7 +826,7 @@
             'vmstate-loaded' ] }
 
 ##
-# @COLOMode
+# @COLOMode:
 #
 # The colo mode
 #
@@ -842,7 +842,7 @@
   'data': [ 'unknown', 'primary', 'secondary'] }
 
 ##
-# @FailoverStatus
+# @FailoverStatus:
 #
 # An enumeration of COLO failover status
 #
@@ -860,7 +860,7 @@
   'data': [ 'none', 'require', 'active', 'completed'] }
 
 ##
-# @x-colo-lost-heartbeat
+# @x-colo-lost-heartbeat:
 #
 # Tell qemu that heartbeat is lost, request it to do takeover procedures.
 # If this command is sent to the PVM, the Primary side will exit COLO mode.
@@ -954,7 +954,7 @@
 #
 # @pc: the 64-bit instruction pointer
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'CpuInfoX86', 'data': { 'pc': 'int' } }
 
@@ -967,7 +967,7 @@
 #
 # @npc: the NPC component of the instruction pointer
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'CpuInfoSPARC', 'data': { 'pc': 'int', 'npc': 'int' } }
 
@@ -978,7 +978,7 @@
 #
 # @nip: the instruction pointer
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'CpuInfoPPC', 'data': { 'nip': 'int' } }
 
@@ -989,7 +989,7 @@
 #
 # @PC: the instruction pointer
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'CpuInfoMIPS', 'data': { 'PC': 'int' } }
 
@@ -1000,7 +1000,7 @@
 #
 # @PC: the instruction pointer
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'CpuInfoTricore', 'data': { 'PC': 'int' } }
 
@@ -1009,7 +1009,7 @@
 #
 # No additional information is available about the virtual CPU
 #
-# Since 2.6
+# Since: 2.6
 #
 ##
 { 'struct': 'CpuInfoOther', 'data': { } }
@@ -1044,7 +1044,7 @@
 #
 # Returns a list of information about each iothread.
 #
-# Note this list excludes the QEMU main loop thread, which is not declared
+# Note: this list excludes the QEMU main loop thread, which is not declared
 # using the -object iothread command-line option.  It is always the main thread
 # of the process.
 #
@@ -1055,7 +1055,7 @@
 { 'command': 'query-iothreads', 'returns': ['IOThreadInfo'] }
 
 ##
-# @NetworkAddressFamily
+# @NetworkAddressFamily:
 #
 # The network address family
 #
@@ -1075,7 +1075,7 @@
   'data': [ 'ipv4', 'ipv6', 'unix', 'vsock', 'unknown' ] }
 
 ##
-# @VncBasicInfo
+# @VncBasicInfo:
 #
 # The basic information for vnc network connection
 #
@@ -1098,7 +1098,7 @@
             'websocket': 'bool' } }
 
 ##
-# @VncServerInfo
+# @VncServerInfo:
 #
 # The network connection information for server
 #
@@ -1248,7 +1248,7 @@
 { 'command': 'query-vnc-servers', 'returns': ['VncInfo2'] }
 
 ##
-# @SpiceBasicInfo
+# @SpiceBasicInfo:
 #
 # The basic information for SPICE network connection
 #
@@ -1266,7 +1266,7 @@
             'family': 'NetworkAddressFamily' } }
 
 ##
-# @SpiceServerInfo
+# @SpiceServerInfo:
 #
 # Information about a SPICE server
 #
@@ -1279,7 +1279,7 @@
   'data': { '*auth': 'str' } }
 
 ##
-# @SpiceChannel
+# @SpiceChannel:
 #
 # Information about a SPICE client channel.
 #
@@ -1304,7 +1304,7 @@
            'tls': 'bool'} }
 
 ##
-# @SpiceQueryMouseMode
+# @SpiceQueryMouseMode:
 #
 # An enumeration of Spice mouse states.
 #
@@ -1323,7 +1323,7 @@
   'data': [ 'client', 'server', 'unknown' ] }
 
 ##
-# @SpiceInfo
+# @SpiceInfo:
 #
 # Information about the SPICE session.
 #
@@ -1362,7 +1362,7 @@
            'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']} }
 
 ##
-# @query-spice
+# @query-spice:
 #
 # Returns information about the current SPICE server
 #
@@ -1412,7 +1412,7 @@
 { 'struct': 'PciMemoryRange', 'data': {'base': 'int', 'limit': 'int'} }
 
 ##
-# @PciMemoryRegion
+# @PciMemoryRegion:
 #
 # Information about a PCI device I/O region.
 #
@@ -1621,7 +1621,7 @@
 { 'command': 'cpu', 'data': {'index': 'int'} }
 
 ##
-# @cpu-add
+# @cpu-add:
 #
 # Adds CPU with specified ID
 #
@@ -1629,7 +1629,7 @@
 #
 # Returns: Nothing on success
 #
-# Since 1.5
+# Since: 1.5
 ##
 { 'command': 'cpu-add', 'data': {'id': 'int'} }
 
@@ -1760,17 +1760,17 @@
 { 'command': 'balloon', 'data': {'value': 'int'} }
 
 ##
-# @Abort
+# @Abort:
 #
 # This action can be used to test transaction failure.
 #
 # Since: 1.6
-###
+##
 { 'struct': 'Abort',
   'data': { } }
 
 ##
-# @ActionCompletionMode
+# @ActionCompletionMode:
 #
 # An enumeration of Transactional completion modes.
 #
@@ -1790,12 +1790,12 @@
   'data': [ 'individual', 'grouped' ] }
 
 ##
-# @TransactionAction
+# @TransactionAction:
 #
 # A discriminated record of operations that can be performed with
 # @transaction.
 #
-# Since 1.1
+# Since: 1.1
 #
 # drive-backup since 1.6
 # abort since 1.6
@@ -1818,7 +1818,7 @@
    } }
 
 ##
-# @TransactionProperties
+# @TransactionProperties:
 #
 # Optional arguments to modify the behavior of a Transaction.
 #
@@ -1835,7 +1835,7 @@
 }
 
 ##
-# @transaction
+# @transaction:
 #
 # Executes a number of transactionable QMP commands atomically. If any
 # operation fails, then the entire set of actions will be abandoned and the
@@ -1855,7 +1855,7 @@
 # information on only one failed operation returned in an error condition, and
 # subsequent actions will not have been attempted.
 #
-# Since 1.1
+# Since: 1.1
 ##
 { 'command': 'transaction',
   'data': { 'actions': [ 'TransactionAction' ],
@@ -1892,7 +1892,7 @@
   'returns': 'str' }
 
 ##
-# @migrate_cancel
+# @migrate_cancel:
 #
 # Cancel the current executing migration process.
 #
@@ -1905,7 +1905,7 @@
 { 'command': 'migrate_cancel' }
 
 ##
-# @migrate_set_downtime
+# @migrate_set_downtime:
 #
 # Set maximum tolerated downtime for migration.
 #
@@ -1920,7 +1920,7 @@
 { 'command': 'migrate_set_downtime', 'data': {'value': 'number'} }
 
 ##
-# @migrate_set_speed
+# @migrate_set_speed:
 #
 # Set maximum speed for migration.
 #
@@ -1935,7 +1935,7 @@
 { 'command': 'migrate_set_speed', 'data': {'value': 'int'} }
 
 ##
-# @migrate-set-cache-size
+# @migrate-set-cache-size:
 #
 # Set XBZRLE cache size
 #
@@ -1951,7 +1951,7 @@
 { 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} }
 
 ##
-# @query-migrate-cache-size
+# @query-migrate-cache-size:
 #
 # query XBZRLE cache size
 #
@@ -2216,7 +2216,7 @@
   'returns': [ 'DevicePropertyInfo' ] }
 
 ##
-# @migrate
+# @migrate:
 #
 # Migrates the current running guest to another Virtual Machine.
 #
@@ -2237,7 +2237,7 @@
   'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
 
 ##
-# @migrate-incoming
+# @migrate-incoming:
 #
 # Start an incoming migration, the qemu must have been started
 # with -incoming defer
@@ -2271,7 +2271,7 @@
 { 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} }
 
 ##
-# @xen-set-global-dirty-log
+# @xen-set-global-dirty-log:
 #
 # Enable or disable the global dirty log mode.
 #
@@ -2363,7 +2363,7 @@
   'data': [ 'elf', 'kdump-zlib', 'kdump-lzo', 'kdump-snappy' ] }
 
 ##
-# @dump-guest-memory
+# @dump-guest-memory:
 #
 # Dump guest's memory to vmcore. It is a synchronous operation that can take
 # very long depending on the amount of guest memory.
@@ -2417,7 +2417,7 @@
             '*format': 'DumpGuestMemoryFormat'} }
 
 ##
-# @DumpStatus
+# @DumpStatus:
 #
 # Describe the status of a long-running background guest memory dump.
 #
@@ -2429,13 +2429,13 @@
 #
 # @failed: the last dump has failed.
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'enum': 'DumpStatus',
   'data': [ 'none', 'active', 'completed', 'failed' ] }
 
 ##
-# @DumpQueryResult
+# @DumpQueryResult:
 #
 # The result format for 'query-dump'.
 #
@@ -2445,7 +2445,7 @@
 #
 # @total: total bytes to be written in latest dump (uncompressed)
 #
-# Since 2.6
+# Since: 2.6
 ##
 { 'struct': 'DumpQueryResult',
   'data': { 'status': 'DumpStatus',
@@ -2453,7 +2453,7 @@
             'total': 'int' } }
 
 ##
-# @query-dump
+# @query-dump:
 #
 # Query latest dump status.
 #
@@ -2488,7 +2488,7 @@
   'returns': 'DumpGuestMemoryCapability' }
 
 ##
-# @dump-skeys
+# @dump-skeys:
 #
 # Dump guest's storage keys
 #
@@ -2575,17 +2575,17 @@
 { 'command': 'object-del', 'data': {'id': 'str'} }
 
 ##
-# @NetdevNoneOptions
+# @NetdevNoneOptions:
 #
 # Use it alone to have zero network devices.
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevNoneOptions',
   'data': { } }
 
 ##
-# @NetLegacyNicOptions
+# @NetLegacyNicOptions:
 #
 # Create a new Network Interface Card.
 #
@@ -2599,7 +2599,7 @@
 #
 # @vectors: #optional number of MSI-x vectors, 0 to disable MSI-X
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetLegacyNicOptions',
   'data': {
@@ -2610,18 +2610,18 @@
     '*vectors': 'uint32' } }
 
 ##
-# @String
+# @String:
 #
 # A fat type wrapping 'str', to be embedded in lists.
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'String',
   'data': {
     'str': 'str' } }
 
 ##
-# @NetdevUserOptions
+# @NetdevUserOptions:
 #
 # Use the user mode network stack which requires no administrator privilege to
 # run.
@@ -2678,7 +2678,7 @@
 #
 # @guestfwd: #optional forward guest TCP connections
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevUserOptions',
   'data': {
@@ -2704,7 +2704,7 @@
     '*guestfwd':  ['String'] } }
 
 ##
-# @NetdevTapOptions
+# @NetdevTapOptions:
 #
 # Connect the host TAP network interface name to the VLAN.
 #
@@ -2741,7 +2741,7 @@
 # @poll-us: #optional maximum number of microseconds that could
 # be spent on busy polling for tap (since 2.7)
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevTapOptions',
   'data': {
@@ -2762,7 +2762,7 @@
     '*poll-us':    'uint32'} }
 
 ##
-# @NetdevSocketOptions
+# @NetdevSocketOptions:
 #
 # Connect the VLAN to a remote VLAN in another QEMU virtual machine using a TCP
 # socket connection.
@@ -2779,7 +2779,7 @@
 #
 # @udp: #optional UDP unicast address and port number
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevSocketOptions',
   'data': {
@@ -2791,7 +2791,7 @@
     '*udp':       'str' } }
 
 ##
-# @NetdevL2TPv3Options
+# @NetdevL2TPv3Options:
 #
 # Connect the VLAN to Ethernet over L2TPv3 Static tunnel
 #
@@ -2827,7 +2827,7 @@
 # @offset: #optional additional offset - allows the insertion of
 #          additional application-specific data before the packet payload
 #
-# Since 2.1
+# Since: 2.1
 ##
 { 'struct': 'NetdevL2TPv3Options',
   'data': {
@@ -2847,7 +2847,7 @@
     '*offset':      'uint32' } }
 
 ##
-# @NetdevVdeOptions
+# @NetdevVdeOptions:
 #
 # Connect the VLAN to a vde switch running on the host.
 #
@@ -2859,7 +2859,7 @@
 #
 # @mode: #optional permissions for socket
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevVdeOptions',
   'data': {
@@ -2869,7 +2869,7 @@
     '*mode':  'uint16' } }
 
 ##
-# @NetdevDumpOptions
+# @NetdevDumpOptions:
 #
 # Dump VLAN network traffic to a file.
 #
@@ -2878,7 +2878,7 @@
 #
 # @file: #optional dump file path (default is qemu-vlan0.pcap)
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevDumpOptions',
   'data': {
@@ -2886,7 +2886,7 @@
     '*file': 'str' } }
 
 ##
-# @NetdevBridgeOptions
+# @NetdevBridgeOptions:
 #
 # Connect a host TAP network interface to a host bridge device.
 #
@@ -2894,7 +2894,7 @@
 #
 # @helper: #optional command to execute to configure bridge
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevBridgeOptions',
   'data': {
@@ -2902,20 +2902,20 @@
     '*helper': 'str' } }
 
 ##
-# @NetdevHubPortOptions
+# @NetdevHubPortOptions:
 #
 # Connect two or more net clients through a software hub.
 #
 # @hubid: hub identifier number
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetdevHubPortOptions',
   'data': {
     'hubid':     'int32' } }
 
 ##
-# @NetdevNetmapOptions
+# @NetdevNetmapOptions:
 #
 # Connect a client to a netmap-enabled NIC or to a VALE switch port
 #
@@ -2928,7 +2928,7 @@
 #
 # @devname: #optional path of the netmap device (default: '/dev/netmap').
 #
-# Since 2.0
+# Since: 2.0
 ##
 { 'struct': 'NetdevNetmapOptions',
   'data': {
@@ -2936,7 +2936,7 @@
     '*devname':    'str' } }
 
 ##
-# @NetdevVhostUserOptions
+# @NetdevVhostUserOptions:
 #
 # Vhost-user network backend
 #
@@ -2947,7 +2947,7 @@
 # @queues: #optional number of queues to be created for multiqueue vhost-user
 #          (default: 1) (Since 2.5)
 #
-# Since 2.1
+# Since: 2.1
 ##
 { 'struct': 'NetdevVhostUserOptions',
   'data': {
@@ -2956,18 +2956,18 @@
     '*queues':        'int' } }
 
 ##
-# @NetClientDriver
+# @NetClientDriver:
 #
 # Available netdev drivers.
 #
-# Since 2.7
+# Since: 2.7
 ##
 { 'enum': 'NetClientDriver',
   'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'dump',
             'bridge', 'hubport', 'netmap', 'vhost-user' ] }
 
 ##
-# @Netdev
+# @Netdev:
 #
 # Captures the configuration of a network device.
 #
@@ -2975,7 +2975,7 @@
 #
 # @type: Specify the driver used for interpreting remaining arguments.
 #
-# Since 1.2
+# Since: 1.2
 #
 # 'l2tpv3' - since 2.1
 ##
@@ -2997,7 +2997,7 @@
     'vhost-user': 'NetdevVhostUserOptions' } }
 
 ##
-# @NetLegacy
+# @NetLegacy:
 #
 # Captures the configuration of a network device; legacy.
 #
@@ -3009,7 +3009,7 @@
 #
 # @opts: device type specific properties (legacy)
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'struct': 'NetLegacy',
   'data': {
@@ -3019,11 +3019,11 @@
     'opts':  'NetLegacyOptions' } }
 
 ##
-# @NetLegacyOptions
+# @NetLegacyOptions:
 #
 # Like Netdev, but for use only by the legacy command line options
 #
-# Since 1.2
+# Since: 1.2
 ##
 { 'union': 'NetLegacyOptions',
   'data': {
@@ -3040,7 +3040,7 @@
     'vhost-user': 'NetdevVhostUserOptions' } }
 
 ##
-# @NetFilterDirection
+# @NetFilterDirection:
 #
 # Indicates whether a netfilter is attached to a netdev's transmit queue or
 # receive queue or both.
@@ -3054,13 +3054,13 @@
 # @tx: the filter is attached to the transmit queue of the netdev,
 #      where it will receive packets sent by the netdev.
 #
-# Since 2.5
+# Since: 2.5
 ##
 { 'enum': 'NetFilterDirection',
   'data': [ 'all', 'rx', 'tx' ] }
 
 ##
-# @InetSocketAddress
+# @InetSocketAddress:
 #
 # Captures a socket address or address range in the Internet namespace.
 #
@@ -3076,7 +3076,7 @@
 # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6
 #        #optional
 #
-# Since 1.3
+# Since: 1.3
 ##
 { 'struct': 'InetSocketAddress',
   'data': {
@@ -3087,30 +3087,30 @@
     '*ipv6': 'bool' } }
 
 ##
-# @UnixSocketAddress
+# @UnixSocketAddress:
 #
 # Captures a socket address in the local ("Unix socket") namespace.
 #
 # @path: filesystem path to use
 #
-# Since 1.3
+# Since: 1.3
 ##
 { 'struct': 'UnixSocketAddress',
   'data': {
     'path': 'str' } }
 
 ##
-# @VsockSocketAddress
+# @VsockSocketAddress:
 #
 # Captures a socket address in the vsock namespace.
 #
 # @cid: unique host identifier
 # @port: port
 #
-# Note that string types are used to allow for possible future hostname or
+# Note: string types are used to allow for possible future hostname or
 # service resolution support.
 #
-# Since 2.8
+# Since: 2.8
 ##
 { 'struct': 'VsockSocketAddress',
   'data': {
@@ -3118,11 +3118,11 @@
     'port': 'str' } }
 
 ##
-# @SocketAddress
+# @SocketAddress:
 #
 # Captures the address of a socket, which could also be a named file descriptor
 #
-# Since 1.3
+# Since: 1.3
 ##
 { 'union': 'SocketAddress',
   'data': {
@@ -3273,7 +3273,7 @@
             '*props': 'any' } }
 
 ##
-# @CpuModelExpansionType
+# @CpuModelExpansionType:
 #
 # An enumeration of CPU model expansion types.
 #
@@ -3296,7 +3296,7 @@
 
 
 ##
-# @CpuModelExpansionInfo
+# @CpuModelExpansionInfo:
 #
 # The result of a cpu model expansion.
 #
@@ -3370,7 +3370,7 @@
   'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }
 
 ##
-# @CpuModelCompareInfo
+# @CpuModelCompareInfo:
 #
 # The result of a CPU model comparison.
 #
@@ -3434,7 +3434,7 @@
   'returns': 'CpuModelCompareInfo' }
 
 ##
-# @CpuModelBaselineInfo
+# @CpuModelBaselineInfo:
 #
 # The result of a CPU model baseline.
 #
@@ -3640,7 +3640,7 @@
             'kp_comma', 'kp_equals', 'power' ] }
 
 ##
-# @KeyValue
+# @KeyValue:
 #
 # Represents a keyboard key.
 #
@@ -4026,7 +4026,7 @@
 { 'command': 'query-tpm', 'returns': ['TPMInfo'] }
 
 ##
-# @AcpiTableOptions
+# @AcpiTableOptions:
 #
 # Specify an ACPI table on the command line to load.
 #
@@ -4069,7 +4069,7 @@
 #        ACPI table header. At least one file is required. This field excludes
 #        @file.
 #
-# Since 1.5
+# Since: 1.5
 ##
 { 'struct': 'AcpiTableOptions',
   'data': {
@@ -4097,7 +4097,7 @@
 # @size: accepts a number followed by an optional suffix (K)ilo,
 #        (M)ega, (G)iga, (T)era
 #
-# Since 1.5
+# Since: 1.5
 ##
 { 'enum': 'CommandLineParameterType',
   'data': ['string', 'boolean', 'number', 'size'] }
@@ -4115,7 +4115,7 @@
 #
 # @default: #optional default value string (since 2.1)
 #
-# Since 1.5
+# Since: 1.5
 ##
 { 'struct': 'CommandLineParameterInfo',
   'data': { 'name': 'str',
@@ -4132,7 +4132,7 @@
 #
 # @parameters: an array of @CommandLineParameterInfo
 #
-# Since 1.5
+# Since: 1.5
 ##
 { 'struct': 'CommandLineOptionInfo',
   'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } }
@@ -4147,13 +4147,13 @@
 # Returns: list of @CommandLineOptionInfo for all options (or for the given
 #          @option).  Returns an error if the given @option doesn't exist.
 #
-# Since 1.5
+# Since: 1.5
 ##
 {'command': 'query-command-line-options', 'data': { '*option': 'str' },
  'returns': ['CommandLineOptionInfo'] }
 
 ##
-# @X86CPURegister32
+# @X86CPURegister32:
 #
 # A X86 32-bit register
 #
@@ -4163,7 +4163,7 @@
   'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] }
 
 ##
-# @X86CPUFeatureWordInfo
+# @X86CPUFeatureWordInfo:
 #
 # Information about a X86 CPU feature word
 #
@@ -4185,11 +4185,11 @@
             'features': 'int' } }
 
 ##
-# @DummyForceArrays
+# @DummyForceArrays:
 #
 # Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally
 #
-# Since 2.5
+# Since: 2.5
 ##
 { 'struct': 'DummyForceArrays',
   'data': { 'unused': ['X86CPUFeatureWordInfo'] } }
@@ -4239,7 +4239,7 @@
 #
 # @multicast-table: a list of multicast macaddr string
 #
-# Since 1.6
+# Since: 1.6
 ##
 { 'struct': 'RxFilterInfo',
   'data': {
@@ -4274,7 +4274,7 @@
   'returns': ['RxFilterInfo'] }
 
 ##
-# @InputButton
+# @InputButton:
 #
 # Button of a pointer input device (mouse, tablet).
 #
@@ -4284,7 +4284,7 @@
   'data'  : [ 'left', 'middle', 'right', 'wheel-up', 'wheel-down' ] }
 
 ##
-# @InputAxis
+# @InputAxis:
 #
 # Position axis of a pointer input device (mouse, tablet).
 #
@@ -4294,7 +4294,7 @@
   'data'  : [ 'x', 'y' ] }
 
 ##
-# @InputKeyEvent
+# @InputKeyEvent:
 #
 # Keyboard input event.
 #
@@ -4308,7 +4308,7 @@
               'down'    : 'bool' } }
 
 ##
-# @InputBtnEvent
+# @InputBtnEvent:
 #
 # Pointer button input event.
 #
@@ -4322,7 +4322,7 @@
               'down'    : 'bool' } }
 
 ##
-# @InputMoveEvent
+# @InputMoveEvent:
 #
 # Pointer motion input event.
 #
@@ -4337,7 +4337,7 @@
               'value'   : 'int' } }
 
 ##
-# @InputEvent
+# @InputEvent:
 #
 # Input event union.
 #
@@ -4356,7 +4356,7 @@
               'abs'     : 'InputMoveEvent' } }
 
 ##
-# @input-send-event
+# @input-send-event:
 #
 # Send input event(s) to guest.
 #
@@ -4386,18 +4386,18 @@
             'events' : [ 'InputEvent' ] } }
 
 ##
-# @NumaOptions
+# @NumaOptions:
 #
 # A discriminated record of NUMA options. (for OptsVisitor)
 #
-# Since 2.1
+# Since: 2.1
 ##
 { 'union': 'NumaOptions',
   'data': {
     'node': 'NumaNodeOptions' }}
 
 ##
-# @NumaNodeOptions
+# @NumaNodeOptions:
 #
 # Create a guest NUMA node. (for OptsVisitor)
 #
@@ -4423,7 +4423,7 @@
    '*memdev': 'str' }}
 
 ##
-# @HostMemPolicy
+# @HostMemPolicy:
 #
 # Host memory policy types
 #
@@ -4437,7 +4437,7 @@
 # @interleave: memory allocations are interleaved across the set
 #              of host nodes specified
 #
-# Since 2.1
+# Since: 2.1
 ##
 { 'enum': 'HostMemPolicy',
   'data': [ 'default', 'preferred', 'bind', 'interleave' ] }
@@ -4526,7 +4526,7 @@
 { 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} }
 
 ##
-# @query-memory-devices
+# @query-memory-devices:
 #
 # Lists available memory devices and their state
 #
@@ -4535,7 +4535,7 @@
 { 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] }
 
 ##
-# @ACPISlotType
+# @ACPISlotType:
 #
 # @DIMM: memory slot
 # @CPU: logical CPU slot (since 2.7)
@@ -4543,7 +4543,7 @@
 { 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }
 
 ##
-# @ACPIOSTInfo
+# @ACPIOSTInfo:
 #
 # OSPM Status Indication for a device
 # For description of possible values of @source and @status fields
@@ -4569,7 +4569,7 @@
               'status': 'int' } }
 
 ##
-# @query-acpi-ospm-status
+# @query-acpi-ospm-status:
 #
 # Lists ACPI OSPM status of ACPI device objects,
 # which might be reported via _OST method
@@ -4579,7 +4579,7 @@
 { 'command': 'query-acpi-ospm-status', 'returns': ['ACPIOSTInfo'] }
 
 ##
-# @WatchdogExpirationAction
+# @WatchdogExpirationAction:
 #
 # An enumeration of the actions taken when the watchdog device's timer is
 # expired
@@ -4607,7 +4607,7 @@
             'inject-nmi' ] }
 
 ##
-# @IoOperationType
+# @IoOperationType:
 #
 # An enumeration of the I/O operation types
 #
@@ -4621,7 +4621,7 @@
   'data': [ 'read', 'write' ] }
 
 ##
-# @GuestPanicAction
+# @GuestPanicAction:
 #
 # An enumeration of the actions taken when guest OS panic is detected
 #
@@ -4633,7 +4633,7 @@
   'data': [ 'pause', 'poweroff' ] }
 
 ##
-# @rtc-reset-reinjection
+# @rtc-reset-reinjection:
 #
 # This command will reset the RTC interrupt reinjection backlog.
 # Can be used if another mechanism to synchronize guest time
@@ -4716,7 +4716,7 @@
 { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
 
 ##
-# @CpuInstanceProperties
+# @CpuInstanceProperties:
 #
 # List of properties to be used for hotplugging a CPU instance,
 # it should be passed by management with device_add command when
@@ -4744,7 +4744,7 @@
 }
 
 ##
-# @HotpluggableCPU
+# @HotpluggableCPU:
 #
 # @type: CPU object type for usage with device_add command
 # @props: list of properties to be used for hotplugging CPU
@@ -4763,7 +4763,7 @@
 }
 
 ##
-# @query-hotpluggable-cpus
+# @query-hotpluggable-cpus:
 #
 # Returns: a list of HotpluggableCPU objects.
 #
qapi/block-core.json +98 -98

743 lines not on this page · raw message

qapi/block.json +8 -8
index 4661fc9..937df05 100644
@@ -40,7 +40,7 @@
   'data': ['auto', 'none', 'lba', 'large', 'rechs']}
 
 ##
-# @FloppyDriveType
+# @FloppyDriveType:
 #
 # Type of Floppy drive to be emulated by the Floppy Disk Controller.
 #
@@ -56,7 +56,7 @@
   'data': ['144', '288', '120', 'none', 'auto']}
 
 ##
-# @BlockdevSnapshotInternal
+# @BlockdevSnapshotInternal:
 #
 # @device: the device name or node-name of a root node to generate the snapshot
 #          from
@@ -73,7 +73,7 @@
   'data': { 'device': 'str', 'name': 'str' } }
 
 ##
-# @blockdev-snapshot-internal-sync
+# @blockdev-snapshot-internal-sync:
 #
 # Synchronously take an internal snapshot of a block device, when the format
 # of the image used supports it.
@@ -87,13 +87,13 @@
 #          If the format of the image used does not support it,
 #          BlockFormatFeatureNotSupported
 #
-# Since 1.7
+# Since: 1.7
 ##
 { 'command': 'blockdev-snapshot-internal-sync',
   'data': 'BlockdevSnapshotInternal' }
 
 ##
-# @blockdev-snapshot-delete-internal-sync
+# @blockdev-snapshot-delete-internal-sync:
 #
 # Synchronously delete an internal snapshot of a block device, when the format
 # of the image used support it. The snapshot is identified by name or id or
@@ -114,7 +114,7 @@
 #          BlockFormatFeatureNotSupported
 #          If @id and @name are both not specified, GenericError
 #
-# Since 1.7
+# Since: 1.7
 ##
 { 'command': 'blockdev-snapshot-delete-internal-sync',
   'data': { 'device': 'str', '*id': 'str', '*name': 'str'},
@@ -190,7 +190,7 @@
 { 'command': 'nbd-server-stop' }
 
 ##
-# @DEVICE_TRAY_MOVED
+# @DEVICE_TRAY_MOVED:
 #
 # Emitted whenever the tray of a removable device is moved by the guest or by
 # HMP/QMP commands
@@ -209,7 +209,7 @@
   'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } }
 
 ##
-# @QuorumOpType
+# @QuorumOpType:
 #
 # An enumeration of the quorum operation types
 #
qapi/common.json +4 -4
index 6987100..624a861 100644
@@ -3,7 +3,7 @@
 # QAPI common definitions
 
 ##
-# @QapiErrorClass
+# @QapiErrorClass:
 #
 # QEMU error classes
 #
@@ -30,7 +30,7 @@
             'DeviceNotActive', 'DeviceNotFound', 'KVMMissingCap' ] }
 
 ##
-# @VersionTriple
+# @VersionTriple:
 #
 # A three-part version number.
 #
@@ -101,7 +101,7 @@
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
 ##
-# @OnOffAuto
+# @OnOffAuto:
 #
 # An enumeration of three options: on, off, and auto
 #
@@ -117,7 +117,7 @@
   'data': [ 'auto', 'on', 'off' ] }
 
 ##
-# @OnOffSplit
+# @OnOffSplit:
 #
 # An enumeration of three values: on, off, and split
 #
qapi/event.json +29 -29

230 lines not on this page · raw message

qapi/introspect.json +14 -14
index 3fd81fb..fd4dc84 100644
@@ -11,7 +11,7 @@
 # See the COPYING file in the top-level directory.
 
 ##
-# @query-qmp-schema
+# @query-qmp-schema:
 #
 # Command query-qmp-schema exposes the QMP wire ABI as an array of
 # SchemaInfo.  This lets QMP clients figure out what commands and
@@ -49,7 +49,7 @@
   'gen': false }                # just to simplify qmp_query_json()
 
 ##
-# @SchemaMetaType
+# @SchemaMetaType:
 #
 # This is a @SchemaInfo's meta type, i.e. the kind of entity it
 # describes.
@@ -75,7 +75,7 @@
             'command', 'event' ] }
 
 ##
-# @SchemaInfo
+# @SchemaInfo:
 #
 # @name: the entity's name, inherited from @base.
 #        Commands and events have the name defined in the QAPI schema.
@@ -105,7 +105,7 @@
       'event': 'SchemaInfoEvent' } }
 
 ##
-# @SchemaInfoBuiltin
+# @SchemaInfoBuiltin:
 #
 # Additional SchemaInfo members for meta-type 'builtin'.
 #
@@ -117,7 +117,7 @@
   'data': { 'json-type': 'JSONType' } }
 
 ##
-# @JSONType
+# @JSONType:
 #
 # The four primitive and two structured types according to RFC 7159
 # section 1, plus 'int' (split off 'number'), plus the obvious top
@@ -130,7 +130,7 @@
             'object', 'array', 'value' ] }
 
 ##
-# @SchemaInfoEnum
+# @SchemaInfoEnum:
 #
 # Additional SchemaInfo members for meta-type 'enum'.
 #
@@ -144,7 +144,7 @@
   'data': { 'values': ['str'] } }
 
 ##
-# @SchemaInfoArray
+# @SchemaInfoArray:
 #
 # Additional SchemaInfo members for meta-type 'array'.
 #
@@ -158,7 +158,7 @@
   'data': { 'element-type': 'str' } }
 
 ##
-# @SchemaInfoObject
+# @SchemaInfoObject:
 #
 # Additional SchemaInfo members for meta-type 'object'.
 #
@@ -183,7 +183,7 @@
             '*variants': [ 'SchemaInfoObjectVariant' ] } }
 
 ##
-# @SchemaInfoObjectMember
+# @SchemaInfoObjectMember:
 #
 # An object member.
 #
@@ -206,7 +206,7 @@
 # @default's type must be null or match @type
 
 ##
-# @SchemaInfoObjectVariant
+# @SchemaInfoObjectVariant:
 #
 # The variant members for a value of the type tag.
 #
@@ -221,7 +221,7 @@
   'data': { 'case': 'str', 'type': 'str' } }
 
 ##
-# @SchemaInfoAlternate
+# @SchemaInfoAlternate:
 #
 # Additional SchemaInfo members for meta-type 'alternate'.
 #
@@ -237,7 +237,7 @@
   'data': { 'members': [ 'SchemaInfoAlternateMember' ] } }
 
 ##
-# @SchemaInfoAlternateMember
+# @SchemaInfoAlternateMember:
 #
 # An alternate member.
 #
@@ -249,7 +249,7 @@
   'data': { 'type': 'str' } }
 
 ##
-# @SchemaInfoCommand
+# @SchemaInfoCommand:
 #
 # Additional SchemaInfo members for meta-type 'command'.
 #
@@ -266,7 +266,7 @@
   'data': { 'arg-type': 'str', 'ret-type': 'str' } }
 
 ##
-# @SchemaInfoEvent
+# @SchemaInfoEvent:
 #
 # Additional SchemaInfo members for meta-type 'event'.
 #
qapi/trace.json +4 -4
index e872146..4fd39b7 100644
@@ -17,7 +17,7 @@
 #
 # @enabled: The event is dynamically enabled.
 #
-# Since 2.2
+# Since: 2.2
 ##
 { 'enum': 'TraceEventState',
   'data': ['unavailable', 'disabled', 'enabled'] }
@@ -34,7 +34,7 @@
 # An event is per-vCPU if it has the "vcpu" property in the "trace-events"
 # files.
 #
-# Since 2.2
+# Since: 2.2
 ##
 { 'struct': 'TraceEventInfo',
   'data': {'name': 'str', 'state': 'TraceEventState', 'vcpu': 'bool'} }
@@ -58,7 +58,7 @@
 # exact match, @vcpu is given and the event does not have the "vcpu" property,
 # an error is returned.
 #
-# Since 2.2
+# Since: 2.2
 ##
 { 'command': 'trace-event-get-state',
   'data': {'name': 'str', '*vcpu': 'int'},
@@ -83,7 +83,7 @@
 # match, @vcpu is given and the event does not have the "vcpu" property, an
 # error is returned.
 #
-# Since 2.2
+# Since: 2.2
 ##
 { 'command': 'trace-event-set-state',
   'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool',
qga/qapi-schema.json +22 -22

175 lines not on this page · raw message

Signature · 1 line
2.10.0
#17 lore raw

Re: [Qemu-devel] [PATCH v3 08/14] qapi: add missing colon-ending for section name

Quoted 1 line · Marc-André Lureau

The documentation parser expects a section name to end with ':',

Suggest "The documentation parser we're going to add".

Quoted 13 lines

otherwise the comment is treated as free-form text body.

---
 qapi-schema.json     | 300 +++++++++++++++++++++++++--------------------------
 qapi/block-core.json | 196 ++++++++++++++++-----------------
 qapi/block.json      |  16 +--
 qapi/common.json     |   8 +-
 qapi/event.json      |  58 +++++-----
 qapi/introspect.json |  28 ++---
 qapi/trace.json      |   8 +-
 qga/qapi-schema.json |  44 ++++----
 8 files changed, 329 insertions(+), 329 deletions(-)

That's a lot of colons :)

#18 lore raw

PATCH v3 9/14 qapi: add some sections in docs

In reply to Marc-André Lureau

Add some more section title, and misc fixes.

---
 qapi-schema.json     |  4 ++++
 qapi/block-core.json |  6 ++++--
 qapi/block.json      | 10 ++++++++--
 qapi/common.json     |  6 ++++--
 qapi/crypto.json     |  5 ++++-
 qapi/event.json      |  6 ++++++
 qapi/rocker.json     |  4 ++++
 qapi/trace.json      |  3 +++
 8 files changed, 37 insertions(+), 7 deletions(-)
qapi-schema.json +4 -0
index e9605b0..b7dff19 100644
@@ -20,6 +20,10 @@
 # QAPI introspection
 { 'include': 'qapi/introspect.json' }
 
+##
+# = QMP commands
+##
+
 ##
 # @qmp_capabilities:
 #
qapi/block-core.json +4 -2
index bc78042..91febed 100644
@@ -1,6 +1,8 @@
 # -*- Mode: Python -*-
-#
-# QAPI block core definitions (vm unrelated)
+
+##
+# == QAPI block core definitions (vm unrelated)
+##
 
 # QAPI common definitions
 { 'include': 'common.json' }
qapi/block.json +8 -2
index 937df05..e4ad74b 100644
@@ -1,10 +1,16 @@
 # -*- Mode: Python -*-
-#
-# QAPI block definitions (vm related)
+
+##
+# = QAPI block definitions
+##
 
 # QAPI block core definitions
 { 'include': 'block-core.json' }
 
+##
+# == QAPI block definitions (vm unrelated)
+##
+
 ##
 # @BiosAtaTranslation:
 #
qapi/common.json +4 -2
index 624a861..d93f159 100644
@@ -1,6 +1,8 @@
 # -*- Mode: Python -*-
-#
-# QAPI common definitions
+
+##
+# = QAPI common definitions
+##
 
 ##
 # @QapiErrorClass:
qapi/crypto.json +4 -1
index 15d296e..1e517b0 100644
@@ -1,6 +1,9 @@
 # -*- Mode: Python -*-
 #
-# QAPI crypto definitions
+
+##
+# = QAPI crypto definitions
+##
 
 ##
 # @QCryptoTLSCredsEndpoint:
qapi/event.json +6 -0
index 37bf34e..59942b0 100644
@@ -1,3 +1,9 @@
+# -*- Mode: Python -*-
+
+##
+# = Events
+##
+
 ##
 # @SHUTDOWN:
 #
qapi/rocker.json +4 -0
index ace2776..dd72e02 100644
@@ -1,4 +1,8 @@
 ##
+# = Rocker API
+##
+
+##
 # @RockerSwitch:
 #
 # Rocker switch information.
qapi/trace.json +3 -0
index 4fd39b7..3ad7df7 100644
@@ -5,6 +5,9 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
 # See the COPYING file in the top-level directory.
 
+##
+# = Tracing commands
+##
 
 ##
 # @TraceEventState:
Signature · 1 line
2.10.0
#19 lore raw

Re: [Qemu-devel] [PATCH v3 09/14] qapi: add some sections in docs

Quoted 1 line · Marc-André Lureau

Add some more section title, and misc fixes.

Are there any "misc fixes" left? I can see only section titles.

Quoted 136 lines
---
 qapi-schema.json     |  4 ++++
 qapi/block-core.json |  6 ++++--
 qapi/block.json      | 10 ++++++++--
 qapi/common.json     |  6 ++++--
 qapi/crypto.json     |  5 ++++-
 qapi/event.json      |  6 ++++++
 qapi/rocker.json     |  4 ++++
 qapi/trace.json      |  3 +++
 8 files changed, 37 insertions(+), 7 deletions(-)
qapi-schema.json +4 -0
index e9605b0..b7dff19 100644
@@ -20,6 +20,10 @@
 # QAPI introspection
 { 'include': 'qapi/introspect.json' }
 
+##
+# = QMP commands
+##
+
 ##
 # @qmp_capabilities:
 #
qapi/block-core.json +4 -2
index bc78042..91febed 100644
@@ -1,6 +1,8 @@
 # -*- Mode: Python -*-
-#
-# QAPI block core definitions (vm unrelated)
+
+##
+# == QAPI block core definitions (vm unrelated)
+##
 
 # QAPI common definitions
 { 'include': 'common.json' }
qapi/block.json +8 -2
index 937df05..e4ad74b 100644
@@ -1,10 +1,16 @@
 # -*- Mode: Python -*-
-#
-# QAPI block definitions (vm related)
+
+##
+# = QAPI block definitions
+##
 
 # QAPI block core definitions
 { 'include': 'block-core.json' }
 
+##
+# == QAPI block definitions (vm unrelated)
+##
+
 ##
 # @BiosAtaTranslation:
 #
qapi/common.json +4 -2
index 624a861..d93f159 100644
@@ -1,6 +1,8 @@
 # -*- Mode: Python -*-
-#
-# QAPI common definitions
+
+##
+# = QAPI common definitions
+##
 
 ##
 # @QapiErrorClass:
qapi/crypto.json +4 -1
index 15d296e..1e517b0 100644
@@ -1,6 +1,9 @@
 # -*- Mode: Python -*-
 #
-# QAPI crypto definitions
+
+##
+# = QAPI crypto definitions
+##
 
 ##
 # @QCryptoTLSCredsEndpoint:
qapi/event.json +6 -0
index 37bf34e..59942b0 100644
@@ -1,3 +1,9 @@
+# -*- Mode: Python -*-
+
+##
+# = Events
+##
+
 ##
 # @SHUTDOWN:
 #
qapi/rocker.json +4 -0
index ace2776..dd72e02 100644
@@ -1,4 +1,8 @@
 ##
+# = Rocker API
+##
+
+##
 # @RockerSwitch:
 #
 # Rocker switch information.
qapi/trace.json +3 -0
index 4fd39b7..3ad7df7 100644
@@ -5,6 +5,9 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
 # See the COPYING file in the top-level directory.
 
+##
+# = Tracing commands
+##
 
 ##
 # @TraceEventState:
#20 lore raw

PATCH v3 10/14 docs: add master qapi texi files

In reply to Marc-André Lureau

The qapi2texi scripts generates a file to be included in a texi file. Add "QEMU QMP Reference Manual" and "QEMU Guest Agent Protocol Reference" master texi files. Move qmp-intro.txt into qemu-qmp-ref.texi, to widen its content on various installed target
formats (man/txt/html/pdf/info..)

---
 docs/qemu-ga-ref.texi         |  65 ++++++++++++++++++
 docs/qemu-qmp-ref.texi        | 156 ++++++++++++++++++++++++++++++++++++++++++
 docs/qmp-intro.txt            |  87 -----------------------
 docs/writing-qmp-commands.txt |   2 +-
 4 files changed, 222 insertions(+), 88 deletions(-)
 create mode 100644 docs/qemu-ga-ref.texi
 create mode 100644 docs/qemu-qmp-ref.texi
 delete mode 100644 docs/qmp-intro.txt
docs/qemu-ga-ref.texi new file +65 -0
new file mode 100644
index 0000000..ad90712
@@ -0,0 +1,65 @@
+\input texinfo
+@setfilename qemu-ga-ref.info
+
+@exampleindent 0
+@paragraphindent 0
+
+@settitle QEMU Guest Agent Protocol Reference
+
+@copying
+This is the QEMU Guest Agent Protocol reference manual.
+
+Copyright @copyright{} 2016 The QEMU Project developers
+@end copying
+
+@ifinfo
+@dircategory QEMU
+@direntry
+* QEMU-GA-Ref: (qemu-ga-ref).   QEMU Guest Agent Protocol Reference
+@end direntry
+@end ifinfo
+
+@titlepage
+@title Guest Agent Protocol Reference Manual
+@subtitle QEMU version @value{VERSION}
+@page
+@vskip 0pt plus 1filll
+@insertcopying
+@end titlepage
+
+@contents
+
+@ifnottex
+@node Top
+@top QEMU Guest Agent protocol reference
+@end ifnottex
+
+@menu
+* API Reference::
+* Commands and Events Index::
+* Data Types Index::
+@end menu
+
+@node API Reference
+@chapter API Reference
+
+@c for texi2pod:
+@c man begin DESCRIPTION
+
+@include qemu-ga-qapi.texi
+
+@c man end
+
+@c man begin SEEALSO
+The HTML documentation of QEMU for more information.
+@c man end
+
+@node Commands and Events Index
+@unnumbered Commands and Events Index
+@printindex fn
+
+@node Data Types Index
+@unnumbered Data Types Index
+@printindex tp
+
+@bye
docs/qemu-qmp-ref.texi new file +156 -0

156 lines not on this page · raw message

docs/qmp-intro.txt deleted +0 -87

87 lines not on this page · raw message

docs/writing-qmp-commands.txt +1 -1
index 44c14db..de54977 100644
@@ -8,7 +8,7 @@ into the QAPI framework implementation.
 
 For an in-depth introduction to the QAPI framework, please refer to
 docs/qapi-code-gen.txt. For documentation about the QMP protocol,
-start with docs/qmp-intro.txt.
+start with docs/qemu-qmp-ref.texi.
 
 == Overview ==
 
Signature · 1 line
2.10.0
#21 lore raw

Re: [Qemu-devel] [PATCH v3 10/14] docs: add master qapi texi files

I see you managed to turn the templates into master files. A welcome simplification of the build process.

Quoted 1 line · Marc-André Lureau

The qapi2texi scripts generates a file to be included in a texi

script (singular)

Quoted 4 lines

file. Add "QEMU QMP Reference Manual" and "QEMU Guest Agent Protocol Reference" master texi files. Move qmp-intro.txt into qemu-qmp-ref.texi, to widen its content on various installed target
formats (man/txt/html/pdf/info..)

I feel replacing qmp-intro.txt in this patch as well is one step too many. Let's do exactly the same both for QGA and QMP in this patch. Actually, in this series, because I want to commit it sooner rather than later, and the way to do that is to factor out and postpone inessential parts that are eating precious review bandwidth.

Quoted 19 lines
---
 docs/qemu-ga-ref.texi         |  65 ++++++++++++++++++
 docs/qemu-qmp-ref.texi        | 156 ++++++++++++++++++++++++++++++++++++++++++
 docs/qmp-intro.txt            |  87 -----------------------
 docs/writing-qmp-commands.txt |   2 +-
 4 files changed, 222 insertions(+), 88 deletions(-)
 create mode 100644 docs/qemu-ga-ref.texi
 create mode 100644 docs/qemu-qmp-ref.texi
 delete mode 100644 docs/qmp-intro.txt
docs/qemu-ga-ref.texi new file +2 -0
new file mode 100644
index 0000000..ad90712
@@ -0,0 +1,65 @@
+\input texinfo
+@setfilename qemu-ga-ref.info

docs/qemu-ga-ref.texi line 12

Quoted 10 lines
docs/qemu-ga-ref.texi new file +10 -0
+
+@exampleindent 0
+@paragraphindent 0
+
+@settitle QEMU Guest Agent Protocol Reference
+
+@copying
+This is the QEMU Guest Agent Protocol reference manual.
+
+Copyright @copyright{} 2016 The QEMU Project developers

Need something on permissions, because without, we don't grant any. Since much of the contents comes from existing files without an explicit license notice, I guess we need to stick to GPLv2+. Here's my try, patterned after the notice carried by "The Debian Administrator's Handbook"[*]:

@quotation

This manual is free documentation: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This manual is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this manual. If not, see http://www.gnu.org/licenses/.
@end quotation

docs/qemu-ga-ref.texi line 20

Quoted 8 lines
docs/qemu-ga-ref.texi new file +8 -0
+@end copying
+
+@ifinfo
+@dircategory QEMU
+@direntry
+* QEMU-GA-Ref: (qemu-ga-ref).   QEMU Guest Agent Protocol Reference
+@end direntry
+@end ifinfo

I don't think the redundant @ifinfo buys us anything.

docs/qemu-qmp-ref.texi

Quoted 51 lines
docs/qemu-ga-ref.texi new file +45 -0
+
+@titlepage
+@title Guest Agent Protocol Reference Manual
+@subtitle QEMU version @value{VERSION}
+@page
+@vskip 0pt plus 1filll
+@insertcopying
+@end titlepage
+
+@contents
+
+@ifnottex
+@node Top
+@top QEMU Guest Agent protocol reference
+@end ifnottex
+
+@menu
+* API Reference::
+* Commands and Events Index::
+* Data Types Index::
+@end menu
+
+@node API Reference
+@chapter API Reference
+
+@c for texi2pod:
+@c man begin DESCRIPTION
+
+@include qemu-ga-qapi.texi
+
+@c man end
+
+@c man begin SEEALSO
+The HTML documentation of QEMU for more information.
+@c man end
+
+@node Commands and Events Index
+@unnumbered Commands and Events Index
+@printindex fn
+
+@node Data Types Index
+@unnumbered Data Types Index
+@printindex tp
+
+@bye
docs/qemu-qmp-ref.texi new file +0 -0
new file mode 100644
index 0000000..c1740ae
@@ -0,0 +1,156 @@

Comments on the previous file apply.

Quoted 32 lines
docs/qemu-qmp-ref.texi new file +32 -0
+\input texinfo
+@setfilename qemu-qmp-ref.info
+
+@exampleindent 0
+@paragraphindent 0
+
+@settitle QEMU QMP Reference Manual
+
+@copying
+This is the QEMU QMP reference manual.
+
+Copyright @copyright{} 2016 The QEMU Project developers
+@end copying
+
+@ifinfo
+@dircategory QEMU
+@direntry
+* QEMU-QMP-Ref: (qemu-qmp-ref). QEMU QMP Reference Manual
+@end direntry
+@end ifinfo
+
+@titlepage
+@title QMP Reference Manual
+@subtitle QEMU version @value{VERSION}
+@page
+@vskip 0pt plus 1filll
+@insertcopying
+@end titlepage
+
+@contents
+
+@ifnottex

docs/qemu-qmp-ref.texi line 42

Quoted 10 lines
docs/qemu-qmp-ref.texi new file +10 -0
+@node Top
+@top QEMU QMP reference
+@end ifnottex
+
+@menu
+* Introduction::
+* API Reference::
+* Commands and Events Index::
+* Data Types Index::
+@end menu

[Skipping chapter Introduction...]

docs/qmp-intro.txt

Quoted 28 lines
docs/qemu-qmp-ref.texi new file +23 -0
+@node API Reference
+@chapter API Reference
+
+@c for texi2pod:
+@c man begin DESCRIPTION
+
+@include qemu-qapi.texi
+
+@c man end
+
+@c man begin SEEALSO
+The HTML documentation of QEMU for more precise information.
+@c man end
+
+@node Commands and Events Index
+@unnumbered Commands and Events Index
+@printindex fn
+
+@node Data Types Index
+@unnumbered Data Types Index
+@printindex tp
+
+@bye
docs/qmp-intro.txt deleted +0 -0
deleted file mode 100644
index f6a3a03..0000000

[Skipping...]

docs/writing-qmp-commands.txt

Quoted 4 lines
docs/writing-qmp-commands.txt +0 -0
index 44c14db..de54977 100644

[Skipping...]

[*] https://www.debian.org/doc/manuals/debian-handbook/

#22 lore raw

PATCH v3 11/14 qapi: add qapi2texi script

In reply to Marc-André Lureau

As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).

It parses the following kind of blocks:

Free-form:

##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:

  # | $ echo foo
  # | -> do this
  # | <- get that

#
##

Symbol:

##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar

  # baz ding.
  #
  # @arg: foo
  # @arg: #optional foo
  #
  # Returns: returns bla bla
  #          Or bla blah
  #
  # Since: version
  # Notes: notes, comments can have
  #        - itemized list
  #        - like this
  #
  # Example:
  #
  # -> { "execute": "quit" }
  # <- { "return": {} }
  #
  ##

That's roughly following the following BNF grammar:

api_comment = "##\n" comment "##\n"
comment = freeform_comment | symbol_comment
freeform_comment = { "#" text "\n" }
symbol_comment = "#" "@" name ":\n" { freeform | member | meta }
member = "#" '@' name ':' [ text ] freeform_comment
meta = "#" ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] freeform_comment text = free-text markdown-like, "#optional" for members

Thanks to the following json expressions, the documentation is enhanced with extra information about the type of arguments and return value expected.

---
 scripts/qapi.py        | 175 ++++++++++++++++++++++++++-
 scripts/qapi2texi.py   | 316 +++++++++++++++++++++++++++++++++++++++++++++++++
 docs/qapi-code-gen.txt |  44 +++++--
 3 files changed, 524 insertions(+), 11 deletions(-)
 create mode 100755 scripts/qapi2texi.py
scripts/qapi.py +174 -1
index 21bc32f..ed52ee4 100644
@@ -122,6 +122,103 @@ class QAPIExprError(Exception):
             "%s:%d: %s" % (self.info['file'], self.info['line'], self.msg)
 
 
+class QAPIDoc(object):
+    def __init__(self, parser):
+        self.parser = parser
+        self.symbol = None
+        self.body = []
+        # args is {'arg': 'doc', ...}
+        self.args = OrderedDict()
+        # meta is [(Since/Notes/Examples/Returns:, 'doc'), ...]
+        self.meta = []
+        # the current section to populate, array of [dict, key, comment...]
+        self.section = None
+        self.expr_elem = None
+
+    def get_body(self):
+        return "\n".join(self.body)
+
+    def has_meta(self, name):
+        """Returns True if the doc has a meta section 'name'"""
+        return next((True for i in self.meta if i[0] == name), False)
+
+    def append(self, line):
+        """Adds a # comment line, to be parsed and added in a section"""
+        line = line[1:]
+        if len(line) == 0:
+            self._append_section(line)
+            return
+
+        if line[0] != ' ':
+            raise QAPISchemaError(self.parser, "missing space after #")
+
+        line = line[1:]
+        # take the first word out
+        name = line.split(' ', 1)[0]
+        if name.startswith("@") and name.endswith(":"):
+            line = line[len(name):]
+            name = name[1:-1]
+            if self.symbol is None:
+                # the first is the symbol this APIDoc object documents
+                if len(self.body):
+                    raise QAPISchemaError(self.parser, "symbol must come first")
+                self.symbol = name
+            else:
+                # else an arg
+                self._start_args_section(name)
+        elif self.symbol and name in (
+                "Returns:", "Since:",
+                # those are often singular or plural
+                "Note:", "Notes:",
+                "Example:", "Examples:"):
+            # new "meta" section
+            line = line[len(name):]
+            self._start_meta_section(name[:-1])
+
+        self._append_section(line)
+
+    def _start_args_section(self, name):
+        self.end_section()
+        if self.args.has_key(name):
+            raise QAPISchemaError(self.parser, "'%s' arg duplicated" % name)
+        self.section = [self.args, name]
+
+    def _start_meta_section(self, name):
+        self.end_section()
+        if name in ("Returns", "Since") and self.has_meta(name):
+            raise QAPISchemaError(self.parser, "'%s' section duplicated" % name)
+        self.section = [self.meta, name]
+
+    def _append_section(self, line):
+        """Add a comment to the current section, or the comment body"""
+        if self.section:
+            name = self.section[1]
+            if not name.startswith("Example"):
+                # an empty line ends the section, except with Example
+                if len(self.section) > 2 and len(line) == 0:
+                    self.end_section()
+                    return
+                # Example is verbatim
+                line = line.strip()
+            if len(line) > 0:
+                self.section.append(line)
+        else:
+            self.body.append(line.strip())
+
+    def end_section(self):
+        if self.section is not None:
+            target = self.section[0]
+            name = self.section[1]
+            if len(self.section) < 3:
+                raise QAPISchemaError(self.parser, "Empty doc section")
+            doc = "\n".join(self.section[2:])
+            if isinstance(target, dict):
+                target[name] = doc
+            else:
+                target.append((name, doc))
+            self.section = None
+
+
 class QAPISchemaParser(object):
 
     def __init__(self, fp, previously_included=[], incl_info=None):
@@ -137,9 +234,15 @@ class QAPISchemaParser(object):
         self.line = 1
         self.line_pos = 0
         self.exprs = []
+        self.docs = []
         self.accept()
 
         while self.tok is not None:
+            if self.tok == '#' and self.val.startswith('##'):
+                doc = self.get_doc()
+                self.docs.append(doc)
+                continue
+
             expr_info = {'file': fname, 'line': self.line,
                          'parent': self.incl_info}
             expr = self.get_expr(False)
@@ -160,6 +263,7 @@ class QAPISchemaParser(object):
                         raise QAPIExprError(expr_info, "Inclusion loop for %s"
                                             % include)
                     inf = inf['parent']
+
                 # skip multiple include of the same file
                 if incl_abs_fname in previously_included:
                     continue
@@ -171,12 +275,40 @@ class QAPISchemaParser(object):
                 exprs_include = QAPISchemaParser(fobj, previously_included,
                                                  expr_info)
                 self.exprs.extend(exprs_include.exprs)
+                self.docs.extend(exprs_include.docs)
             else:
                 expr_elem = {'expr': expr,
                              'info': expr_info}
+                if len(self.docs) > 0:
+                    self.docs[-1].expr_elem = expr_elem
                 self.exprs.append(expr_elem)
 
-    def accept(self):
+    def get_doc(self):
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not starting with '##'")
+
+        doc = QAPIDoc(self)
+        self.accept(False)
+        while self.tok == '#':
+            if self.val.startswith('##'):
+                # ## ends doc
+                if self.val != '##':
+                    raise QAPISchemaError(self, "non-empty '##' line %s"
+                                          % self.val)
+                self.accept()
+                doc.end_section()
+                return doc
+            else:
+                doc.append(self.val)
+            self.accept(False)
+
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not finishing with '##'")
+
+        doc.end_section()
+        return doc
+
+    def accept(self, skip_comment=True):
         while True:
             self.tok = self.src[self.cursor]
             self.pos = self.cursor
@@ -184,7 +316,13 @@ class QAPISchemaParser(object):
             self.val = None
 
             if self.tok == '#':
+                if self.src[self.cursor] == '#':
+                    # ## starts a doc comment
+                    skip_comment = False
                 self.cursor = self.src.find('\n', self.cursor)
+                self.val = self.src[self.pos:self.cursor]
+                if not skip_comment:
+                    return
             elif self.tok in "{}:,[]":
                 return
             elif self.tok == "'":
@@ -779,6 +917,41 @@ def check_exprs(exprs):
 
     return exprs
 
+def check_docs(docs):
+    for doc in docs:
+        expr_elem = doc.expr_elem
+        if not expr_elem:
+            continue
+
+        expr = expr_elem['expr']
+        for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'):
+            if i in expr:
+                meta = i
+                break
+
+        info = expr_elem['info']
+        name = expr[meta]
+        if doc.symbol != name:
+            raise QAPIExprError(info,
+                                "Documentation symbol mismatch '%s' != '%s'"
+                                % (doc.symbol, name))
+        if not 'command' in expr and doc.has_meta('Returns'):
+            raise QAPIExprError(info, "Invalid return documentation")
+
+        doc_args = set(doc.args.keys())
+        if meta == 'union':
+            data = expr.get('base', [])
+        else:
+            data = expr.get('data', [])
+        if isinstance(data, dict):
+            data = data.keys()
+        args = set([k.strip('*') for k in data])
+        if meta == 'alternate' or \
+           (meta == 'union' and not expr.get('discriminator')):
+            args.add('type')
+        if not doc_args.issubset(args):
+            raise QAPIExprError(info, "Members documentation is not a subset of"
+                                " API %r > %r" % (list(doc_args), list(args)))
 
 #
 # Schema compiler frontend
scripts/qapi2texi.py new file +316 -0

316 lines not on this page · raw message

docs/qapi-code-gen.txt +34 -10

62 lines not on this page · raw message

Signature · 1 line
2.10.0
#23 lore raw

Re: [Qemu-devel] [PATCH v3 11/14] qapi: add qapi2texi script

Quoted 40 lines · Marc-André Lureau

As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).

It parses the following kind of blocks:

Free-form:

##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:

  # | $ echo foo
  # | -> do this
  # | <- get that

#
##

Symbol:

##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar

  # baz ding.
  #
  # @arg: foo
  # @arg: #optional foo
  #
  # Returns: returns bla bla
  #          Or bla blah
  #
  # Since: version
  # Notes: notes, comments can have
  #        - itemized list
Quoted 8 lines
  #        - like this
  #
  # Example:
  #
  # -> { "execute": "quit" }
  # <- { "return": {} }
  #
  ##

The following discussion belongs to review of qapi-code-gen.txt, but the example here is more abstract and nicely visible, so let me use it.

The "Symbol" kind of block as shown above is for QMP commands with arguments defined inline.

It also serves for QMP events: just omit the return value.

For struct types, the terminology is a bit off ("argument" instead of "member"), but the basic structure less the return value still works. No surprise, because a command is essentially a triple (name, arguments type, return value type), where the arguments type is a struct type (but see below for non-struct arguments).

Quoted 1 line

From there, it's a small step to using it for enum types.

But how to do union types is non-obvious. In their general form, they have common members, one of them the tag, and variant members depending on the tag value. How do we want such types be documented?

Alternate types can be documented like structs, I think.

What about QMP commands with arguments of the form 'data': 'TypeName'? We typically replace the whole @arg: part by something like

# For the arguments, see the documentation of BlockdevSnapshotSync.

Note that with 'boxed': true, TypeName could even be union or alternate.

My point is: the documentation needs work. Whether we should do the within this series or on top is debatable.

Quoted 1 line

That's roughly following the following BNF grammar:

EBNF, actually.

Quoted 4 lines

api_comment = "##\n" comment "##\n"
comment = freeform_comment | symbol_comment
freeform_comment = { "#" text "\n" }

As we'll see below, your code actually requires at least one space after "#" unless text is empty.

Quoted 1 line

symbol_comment = "#" "@" name ":\n" { freeform | member | meta }

Your code actually requires exactly one space between "#" and "@". It happily accepts additional text between : and newline.

freeform is undefined. I guess you mean freeform_comment.

With that corrected, the grammar is ambiguous. Your intent is obvious enough, though. Just not to a computer.

Quoted 1 line

member = "#" '@' name ':' [ text ] freeform_comment

Again, your code requires exactly one space after "#".

Quoted 1 line

meta = "#" ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] freeform_comment

Likewise.

Quoted 1 line

text = free-text markdown-like, "#optional" for members

Here, the grammar switches from EBNF to prose.

As is, the grammar can serve as semi-formal user documentation. It can't quite serve as specification for the parser. As we'll see below, the code processing doc strings is not a parser constructed from this grammar.

Why am I so hung up on constructing parsers systematically from grammars? When you do that, you can derive the accepted language from the *grammar*. Generally *much* easier than from ad hoc parser code. Moreover, a (sufficiently simple) grammar leads to a natural internal representation, namely an abstract syntax tree.

But let's continue.

Quoted 3 lines

Thanks to the following json expressions, the documentation is enhanced with extra information about the type of arguments and return value expected.

What exactly do you want to convey with this sentence?

scripts/qapi.py

Quoted 12 lines
---
 scripts/qapi.py        | 175 ++++++++++++++++++++++++++-
 scripts/qapi2texi.py   | 316 +++++++++++++++++++++++++++++++++++++++++++++++++
 docs/qapi-code-gen.txt |  44 +++++--
 3 files changed, 524 insertions(+), 11 deletions(-)
 create mode 100755 scripts/qapi2texi.py
scripts/qapi.py +0 -0
index 21bc32f..ed52ee4 100644

Warning: loads of comments ahead. Doesn't mean there are loads of problems! I need to write to think clearly, and I'm sharing my thinking to hopefully help us converge.

scripts/qapi.py class QAPIExprError(Exception): · line 130

Quoted 10 lines
scripts/qapi.py +6 -0
@@ -122,6 +122,103 @@ class QAPIExprError(Exception):
             "%s:%d: %s" % (self.info['file'], self.info['line'], self.msg)
 
 
+class QAPIDoc(object):
+    def __init__(self, parser):
+        self.parser = parser
+        self.symbol = None
+        self.body = []
+        # args is {'arg': 'doc', ...}

Rather terse, but I think I get what you mean.

scripts/qapi.py class QAPIExprError(Exception): · line 132

Quoted 2 lines
scripts/qapi.py +2 -0
+        self.args = OrderedDict()
+        # meta is [(Since/Notes/Examples/Returns:, 'doc'), ...]

More so.

scripts/qapi.py class QAPIExprError(Exception): · line 134

Quoted 2 lines
scripts/qapi.py +2 -0
+        self.meta = []
+        # the current section to populate, array of [dict, key, comment...]

Now you've reached my limit :)

"array of [...]" sounds like a list of lists. But you probably mean just a list.

We'll see below that dict is either self.args or self.meta, and key is a key in dict.

scripts/qapi.py class QAPIExprError(Exception): · line 139

Quoted 5 lines
scripts/qapi.py +5 -0
+        self.section = None
+        self.expr_elem = None
+
+    def get_body(self):
+        return "\n".join(self.body)

Not worth a doc string? The existing code doesn't have any, but since you provide them for other public methods of this class...

scripts/qapi.py class QAPIExprError(Exception): · line 143

Quoted 4 lines
scripts/qapi.py +4 -0
+
+    def has_meta(self, name):
+        """Returns True if the doc has a meta section 'name'"""
+        return next((True for i in self.meta if i[0] == name), False)

Less clever, but probably more obvious to readers lacking a degree in Python generators:

for i in self.meta:
if i[0] == name:
return True
return False

I'm not against using more advanced language features, but when the "advanced" code needs more tokens than the "retarded" one...

scripts/qapi.py class QAPIExprError(Exception): · line 147

Quoted 4 lines
scripts/qapi.py +4 -0
+
+    def append(self, line):
+        """Adds a # comment line, to be parsed and added in a section"""
+        line = line[1:]

As we'll see below, @line is the full comment token text including the initial '#', but not including the final '\n'. First thing we do with it is strip the initial '#'. Makes me wonder why we pass it in. It's not wrong, of course.

Note that comments don't need to be full lines, they just happen to be used that way most of the time. Admittedly contrived counter-example:

    { 'enum': 'Empty', 'data': [] } ##
                                    # @XY:
                                    ##
    { 'enum': 'XY', 'data': ['x', 'y'] }

This makes the parser call doc.append("# @XY:"). The argument "# @XY:" isn't a full line in the source. It becomes a line in the documentation text QAPIDoc wraps.

scripts/qapi.py class QAPIExprError(Exception): · line 150

Quoted 3 lines
scripts/qapi.py +3 -0
+        if len(line) == 0:
+            self._append_section(line)
+            return

Special case for comment '#'. Note that '# ' is processed as a normal case.

scripts/qapi.py class QAPIExprError(Exception): · line 157

Quoted 7 lines
scripts/qapi.py +7 -0
+
+        if line[0] != ' ':
+            raise QAPISchemaError(self.parser, "missing space after #")
+
+        line = line[1:]
+        # take the first word out
+        name = line.split(' ', 1)[0]

For a comment '# ', @name becomes '', because ''.split(' ', 1) returns ['']. Works.

For a comment '# Since:' (note two spaces), name becomes '', because .split() returns ['', 'Since:']. Thus, the keywords are only recognized exactly after '# '. Is this a good idea?

scripts/qapi.py class QAPIExprError(Exception): · line 162

Quoted 5 lines
scripts/qapi.py +5 -0
+        if name.startswith("@") and name.endswith(":"):
+            line = line[len(name):]
+            name = name[1:-1]
+            if self.symbol is None:
+                # the first is the symbol this APIDoc object documents

Suggest

# The first @NAME: is the symbol being documented

scripts/qapi.py class QAPIExprError(Exception): · line 164

Quoted 2 lines
scripts/qapi.py +2 -0
+                if len(self.body):
+                    raise QAPISchemaError(self.parser, "symbol must come first")

You and I know what 'symbol' means here, but the user should not need to know. Suggest something like "'@%s:' must come first". I'm not entirely happy with that either, but I don't have better ideas right now.

If the parser was constructed from your grammar, we'd deal with the first @NAME: not coming first differently. According to the grammar, a doc comment block either starts with '##\n# @' (a symbol block), or it doesn't (a free-form block). If the first line isn't a @NAME: line, but later lines are, the parser decides it's a free-from block right there. Any @NAME: lines it finds later would be parsed as free-form line. If we want to reject such lines in free-form blocks, the easiest way would be a semantic check.

scripts/qapi.py class QAPIExprError(Exception): · line 165

Quoted 1 line
scripts/qapi.py +1 -0
+                self.symbol = name

Here's how we can tell what kind of block we're working on:

if .symbol is not None:
this is a symbol block
elif .body is not None:
this is a free-form block
else
we don't know, yet

scripts/qapi.py class QAPIExprError(Exception): · line 167

Quoted 2 lines
scripts/qapi.py +2 -0
+            else:
+                # else an arg

Suggest
# Subsequent @NAME: are arguments and such

scripts/qapi.py class QAPIExprError(Exception): · line 168

Quoted 1 line
scripts/qapi.py +1 -0
+                self._start_args_section(name)

The remainder of the line after @NAME: is left in @line, and will be stuffed into the current section or else the body after the conditional. That's what the grammar specifies for argument NAME, in rule member. It's not what it specifies for symbol NAME, in rule symbol_comment.

In particular, when nothing follows symbol NAME, we still stuff '' into the body. For instance,

    ##
    # @symbol:
    # 
    # lorem ipsum
    ##

produces self.body = ['', '', 'lorem ipsum'], which .get_body() transforms into '\n\nlorem ipsum'. Extra newline. I guess it's all the same to Texinfo in the end.

Quoted 5 lines
scripts/qapi.py +5 -0
+        elif self.symbol and name in (
+                "Returns:", "Since:",
+                # those are often singular or plural
+                "Note:", "Notes:",
+                "Example:", "Examples:"):

scripts/qapi.py class QAPIExprError(Exception): · line 183

Quoted 10 lines
scripts/qapi.py +10 -0
+            # new "meta" section
+            line = line[len(name):]
+            self._start_meta_section(name[:-1])
+
+        self._append_section(line)
+
+    def _start_args_section(self, name):
+        self.end_section()
+        if self.args.has_key(name):
+            raise QAPISchemaError(self.parser, "'%s' arg duplicated" % name)

Where's self.args[name] added? Oh, I see, it's hidden in end_section(). Could it be added here instead?

scripts/qapi.py class QAPIExprError(Exception): · line 189

Quoted 6 lines
scripts/qapi.py +6 -0
+        self.section = [self.args, name]
+
+    def _start_meta_section(self, name):
+        self.end_section()
+        if name in ("Returns", "Since") and self.has_meta(name):
+            raise QAPISchemaError(self.parser, "'%s' section duplicated" % name)

For the implementation, it's a section, but for the user, it's a line. Suggest "Duplicate '%s'".

Comment on _start_args_section() applies.

scripts/qapi.py class QAPIExprError(Exception): · line 193

Quoted 4 lines
scripts/qapi.py +4 -0
+        self.section = [self.meta, name]
+
+    def _append_section(self, line):
+        """Add a comment to the current section, or the comment body"""

_append_to_section() or _section_append() would be clearer. We're not appending a section, we're appending *to* a section. Or to the body, which isn't a section. Hmm.

scripts/qapi.py class QAPIExprError(Exception): · line 202

Quoted 9 lines
scripts/qapi.py +9 -0
+        if self.section:
+            name = self.section[1]
+            if not name.startswith("Example"):
+                # an empty line ends the section, except with Example
+                if len(self.section) > 2 and len(line) == 0:
+                    self.end_section()
+                    return
+                # Example is verbatim
+                line = line.strip()

The comment is confusing, because it explains what we're not doing elsewhere. Comments should explain what we're doing here.

scripts/qapi.py class QAPIExprError(Exception): · line 209

Quoted 7 lines
scripts/qapi.py +7 -0
+            if len(line) > 0:
+                self.section.append(line)
+        else:
+            self.body.append(line.strip())
+
+    def end_section(self):
+        if self.section is not None:

I prefer the more laconic "if self.section:", especially when self.section can't have a false value other than None anyway. Even more I prefer making the fact that this does nothing when we don't have a section immediately obvious:

if not self.section:
return
do the work...

scripts/qapi.py class QAPIExprError(Exception): · line 219

Quoted 10 lines
scripts/qapi.py +10 -0
+            target = self.section[0]
+            name = self.section[1]
+            if len(self.section) < 3:
+                raise QAPISchemaError(self.parser, "Empty doc section")
+            doc = "\n".join(self.section[2:])
+            if isinstance(target, dict):
+                target[name] = doc
+            else:
+                target.append((name, doc))
+            self.section = None

Until the next _start_FOO_section(), self.section remains None. Therefore, any text between here and the next section will be appended to self.body. This is going to mangle input that doesn't quite match expectations. Example:

    ##
    # @frobnicate:
    #
    # Frobnicate some frobs.
    #
    # @frobs: bla, bla, explain @frobs,
    #         bla.
    #
    #         Beware of the tiger!
    #
    #         Explain @frobs some more, bla, bla.
    #
    # @harder: frobnicate harder.
    ##
    { 'command': 'frobnicate',
      'data': { 'frobs': 'any', '*harder': 'bool' } }

Results in a QAPIDoc with

    .symbol = 'frobnicate'
    .args = { 'frobs': 'frobs bla, bla, explain,\nbla',
              'harder': 'frobnicate harder.' }
    .body = ['', '', 'Frobnicate some frobs.', '',
             'Beware of the tiger!', '',
             'Explain some more, bla, bla.', '']

and the following .texi:

@deftypefn Command {} frobnicate @ {('frobs': @var{any}, ['harder': @var{bool}])}

@table @var
@item frobs
bla, bla, explain @var{frobs},
bla.
@item harder
frobnicate harder.
@end table

Frobnicate some frobs.

Beware of the tiger!

Explain @var{frobs} some more, bla, bla.

The only way to detect the mistake is to read the generated documentation attentively. We can't rely on everybody doing that during development. Even when you do, the mangled output gives you no clue on the mistake you made, unless you know how the doc generator works.

The generator could detect the mistake at the syntactical or at the semantic level.

More general question: can you think of a legitimate reason for the generator emitting documentation in a different order than it was written?

If no, we should pick an internal representation that can represent the input we have / envisage to have faithfully, then reject input it can't represent faithfully.

scripts/qapi.py class QAPISchemaParser(object):

Quoted 6 lines
scripts/qapi.py +2 -0
+
+
 class QAPISchemaParser(object):
 
     def __init__(self, fp, previously_included=[], incl_info=None):
@@ -137,9 +234,15 @@ class QAPISchemaParser(object):

Let's see how parsing works.

scripts/qapi.py class QAPISchemaParser(object): · line 245

Quoted 12 lines
scripts/qapi.py +6 -0
         self.line = 1
         self.line_pos = 0
         self.exprs = []
+        self.docs = []
         self.accept()
 
         while self.tok is not None:
+            if self.tok == '#' and self.val.startswith('##'):
+                doc = self.get_doc()
+                self.docs.append(doc)
+                continue
+

Top-level doc comments get accumulated in list self.docs.

Quoted 12 lines
scripts/qapi.py +1 -0
             expr_info = {'file': fname, 'line': self.line,
                          'parent': self.incl_info}
             expr = self.get_expr(False)
@@ -160,6 +263,7 @@ class QAPISchemaParser(object):
                         raise QAPIExprError(expr_info, "Inclusion loop for %s"
                                             % include)
                     inf = inf['parent']
+
                 # skip multiple include of the same file
                 if incl_abs_fname in previously_included:
                     continue

scripts/qapi.py class QAPISchemaParser(object): · line 278

Quoted 4 lines
scripts/qapi.py +1 -0
@@ -171,12 +275,40 @@ class QAPISchemaParser(object):
                 exprs_include = QAPISchemaParser(fobj, previously_included,
                                                  expr_info)
                 self.exprs.extend(exprs_include.exprs)
+                self.docs.extend(exprs_include.docs)

The include's list of docs are spliced in.

scripts/qapi.py class QAPISchemaParser(object): · line 284

Quoted 6 lines
scripts/qapi.py +2 -0
             else:
                 expr_elem = {'expr': expr,
                              'info': expr_info}
+                if len(self.docs) > 0:
+                    self.docs[-1].expr_elem = expr_elem
                 self.exprs.append(expr_elem)

A non-include expression gets tied to the last doc comment. This isn't quite right. Example:

    ##
    # @Empty:
    ##
    { 'enum': 'Empty', 'data': [] }

    { 'enum': 'XY', 'data': ['x', 'y'] }

The doc comment's expr_elem gets first set to the first enum expression, then overwritten with the second one.

Less serious, but still somewhat weird:

    ##
    # Lorem ipsum
    ##

    # @Empty:
    { 'enum': 'Empty', 'data': [] }

The first comment block is a doc comment. The second one isn't, and gets ignored. The first one's expr_elem gets set to the enum expression.

The quick fix is to set .expr_elem only when it's still None.

The thorough fix is to integrate doc comments deeper into the syntax.

scripts/qapi.py class QAPISchemaParser(object): · line 285

Quoted 3 lines
scripts/qapi.py +1 -1
-    def accept(self):
+    def get_doc(self):

Here, we know self.tok == '#', and self.val is thus the comment line less the newline (see accept()).

scripts/qapi.py class QAPISchemaParser(object): · line 287

Quoted 2 lines
scripts/qapi.py +2 -0
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not starting with '##'")

It starts with '##' alright, it just happens not to end there. What about "Junk after '##'"? Or, if that's too laconic, perhaps "Junk after '##' at start of documentation comment".

scripts/qapi.py class QAPISchemaParser(object): · line 293

Quoted 6 lines
scripts/qapi.py +6 -0
+
+        doc = QAPIDoc(self)
+        self.accept(False)
+        while self.tok == '#':
+            if self.val.startswith('##'):
+                # ## ends doc

"# ##" looks awkward. Suggest

# End of doc comment

scripts/qapi.py class QAPISchemaParser(object): · line 296

Quoted 3 lines
scripts/qapi.py +3 -0
+                if self.val != '##':
+                    raise QAPISchemaError(self, "non-empty '##' line %s"
+                                          % self.val)

Let's make the message similar to whatever message we emit for junk after the initial ##.

scripts/qapi.py class QAPISchemaParser(object): · line 303

Quoted 7 lines
scripts/qapi.py +7 -0
+                self.accept()
+                doc.end_section()
+                return doc
+            else:
+                doc.append(self.val)
+            self.accept(False)
+

Here, self.tok is whatever follows the doc comment.

scripts/qapi.py class QAPISchemaParser(object): · line 305

Quoted 2 lines
scripts/qapi.py +2 -0
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not finishing with '##'")

This check is incorrect. For instance, input

    ##
    '## gotcha'

yields

/dev/stdin:2:1: Doc comment not finishing with '##'

because self.tok == "'" and self.val == "## gotcha".

Either fail unconditionally here (then the final ## is required), or do nothing (then it's optional). Your commit message suggests the former.

Quoted 9 lines
scripts/qapi.py +5 -0
+
+        doc.end_section()
+        return doc
+
+    def accept(self, skip_comment=True):
         while True:
             self.tok = self.src[self.cursor]
             self.pos = self.cursor

scripts/qapi.py class QAPISchemaParser(object): · line 320

Quoted 5 lines
scripts/qapi.py +2 -0
@@ -184,7 +316,13 @@ class QAPISchemaParser(object):
             self.val = None
 
             if self.tok == '#':
+                if self.src[self.cursor] == '#':
+                    # ## starts a doc comment

Suggest

# Start of doc comment

scripts/qapi.py class QAPISchemaParser(object): · line 323

Quoted 3 lines
scripts/qapi.py +2 -0
+                    skip_comment = False
                 self.cursor = self.src.find('\n', self.cursor)
+                self.val = self.src[self.pos:self.cursor]

Puts the complete line less the newline into self.val. I wonder whether we should strip the initial '#' as well.

scripts/qapi.py class QAPISchemaParser(object): · line 325

Quoted 2 lines
scripts/qapi.py +2 -0
+                if not skip_comment:
+                    return

Make that

if not skip_comment:
self.val = self.src[self.pos:self.cursor] return

scripts/qapi.py class QAPISchemaParser(object): · line 328

Quoted 3 lines
scripts/qapi.py +0 -0
             elif self.tok in "{}:,[]":
                 return
             elif self.tok == "'":

Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in get_doc().

This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.

A comment starting with ## inside an expression is now a syntax error. For instance, input

    {
    ##

yields

    /dev/stdin:2:1: Expected string or "}"

Rather unfriendly error message, but we can fix that on top.

scripts/qapi.py def check_exprs(exprs): · line 924

Quoted 9 lines
scripts/qapi.py +5 -0
@@ -779,6 +917,41 @@ def check_exprs(exprs):
 
     return exprs
 
+def check_docs(docs):
+    for doc in docs:
+        expr_elem = doc.expr_elem
+        if not expr_elem:
+            continue

A symbol block without an expr_elem should be an error, shouldn't it?

scripts/qapi.py def check_exprs(exprs): · line 930

Quoted 6 lines
scripts/qapi.py +6 -0
+
+        expr = expr_elem['expr']
+        for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'):
+            if i in expr:
+                meta = i
+                break

We're working with expression trees here, not the QAPISchemaEntity objects. Okay as long as the work is sufficiently trivial.

scripts/qapi.py def check_exprs(exprs): · line 937

Quoted 7 lines
scripts/qapi.py +7 -0
+
+        info = expr_elem['info']
+        name = expr[meta]
+        if doc.symbol != name:
+            raise QAPIExprError(info,
+                                "Documentation symbol mismatch '%s' != '%s'"
+                                % (doc.symbol, name))

Cryptic. Suggest "Definition of '%s' follows documentation for '%s'" % (name, doc.symbol).

scripts/qapi.py def check_exprs(exprs): · line 941

Quoted 4 lines
scripts/qapi.py +4 -0
+        if not 'command' in expr and doc.has_meta('Returns'):
+            raise QAPIExprError(info, "Invalid return documentation")
+
+        doc_args = set(doc.args.keys())

doc_args is the set of documented argument names. Actually member names when expr defines a type, but let's ignore that for now.

scripts/qapi.py def check_exprs(exprs): · line 948

Quoted 7 lines
scripts/qapi.py +7 -0
+        if meta == 'union':
+            data = expr.get('base', [])
+        else:
+            data = expr.get('data', [])
+        if isinstance(data, dict):
+            data = data.keys()
+        args = set([k.strip('*') for k in data])

Suggest to rename k to name.

To see what args is, we first need to figure out what data is.

If expr defines an enum, expr['data'] is the list of of member names. args is the set of member names.

If expr defines a struct type, expr['data'] is the OrderedDict mapping local member names with optional '*' prefix to types. args is the set of local member names. "Local", because additional members may be inherited from a base type.

If expr defines an alternate type, likewise, except there should be no '*' prefixes and no base type.

If expr defines a simple union type, expr['data'] is the OrderedDict mapping tag value names to types. The tag member is implicit. expr['base'] should not exist. args is therefore the empty set.

If expr defines a flat union type, data is the OrderedDict mapping tag value names to types. expr['base'] must exist, and is either a dictionary or the name of a struct type. If it's a dictionary, args is the set of common members defined inline. If it's a struct type name, args is the set of characters in the type name. Oops. Test case: union UserDefFlatUnion in qapi-schema-test.json.

Aside: covering all cases correctly is not trivial enough for expression trees, I'm afraid. Class QAPISchema has to do it. Can we avoid duplicating its logic here? I'm not sure; the QAPISchemaEntity might turn out to be just differently inconvenient.

If expr defines a command, data is either the OrderedDict mapping argument names to types, or the name of the arguments type. If it's a dictionary, args is the set of argument names. If it's a type name, args is the set of characters in the type name. Oops again. Test case:
command user_def_cmd0 in qapi-schema-test.json.

If expr defines an event, likewise. No test case in qapi-schema-test.json. Hole in the test coverage.

Conclusion: args is meant to be the set of arguments / members actually defined. For unions, that does *not* include variant members.

scripts/qapi.py def check_exprs(exprs): · line 951

Quoted 3 lines
scripts/qapi.py +3 -0
+        if meta == 'alternate' or \
+           (meta == 'union' and not expr.get('discriminator')):
+            args.add('type')

For alternate and simple union types, add 'type' to the set of arguments actually defined.

Recall that the set contains the member names for alternates, and nothing for simple unions.

scripts/qapi.py def check_exprs(exprs): · line 952

Quoted 1 line
scripts/qapi.py +1 -0
+        if not doc_args.issubset(args):

Could use the <= operator: if not doc_args <= args. Matter of taste.

scripts/qapi.py def check_exprs(exprs): · line 954

Quoted 2 lines
scripts/qapi.py +2 -0
+            raise QAPIExprError(info, "Members documentation is not a subset of"
+                                " API %r > %r" % (list(doc_args), list(args)))

Errors out if the doc string documents arguments that aren't actually defined as far as we know.

"As far as we know", because we second-guess what's actually defined based on the expression tree, and don't get all the cases right. The actual actual definitions are determined by class QAPISchema, and can be found in its internal representation. Hmm.

Failing to document an argument is not an error. It probably should be, at least in the longer run.

scripts/qapi2texi.py

Quoted 8 lines
scripts/qapi.py +0 -0
 #
 # Schema compiler frontend
scripts/qapi2texi.py new file +0 -0
new file mode 100755
index 0000000..7e2440c

Considering the length of this review so far, I'm only skimming generator part for now.

Quoted 275 lines
scripts/qapi2texi.py new file +274 -0
@@ -0,0 +1,316 @@
+#!/usr/bin/env python
+# QAPI texi generator
+#
+# This work is licensed under the terms of the GNU LGPL, version 2+.
+# See the COPYING file in the top-level directory.
+"""This script produces the documentation of a qapi schema in texinfo format"""
+import re
+import sys
+
+from qapi import *
+
+COMMAND_FMT = """
+@deftypefn {type} {{{ret}}} {name} @
+{{{args}}}
+
+{body}
+
+@end deftypefn
+
+""".format
+
+ENUM_FMT = """
+@deftp Enum {name}
+
+{body}
+
+@end deftp
+
+""".format
+
+STRUCT_FMT = """
+@deftp {type} {name} @
+{{{attrs}}}
+
+{body}
+
+@end deftp
+
+""".format
+
+EXAMPLE_FMT = """@example
+{code}
+@end example
+""".format
+
+
+def subst_strong(doc):
+    """Replaces *foo* by @strong{foo}"""
+    return re.sub(r'\*([^_\n]+)\*', r'@emph{\1}', doc)
+
+
+def subst_emph(doc):
+    """Replaces _foo_ by @emph{foo}"""
+    return re.sub(r'\s_([^_\n]+)_\s', r' @emph{\1} ', doc)
+
+
+def subst_vars(doc):
+    """Replaces @var by @var{var}"""
+    return re.sub(r'@([\w-]+)', r'@var{\1}', doc)
+
+
+def subst_braces(doc):
+    """Replaces {} with @{ @}"""
+    return doc.replace("{", "@{").replace("}", "@}")
+
+
+def texi_example(doc):
+    """Format @example"""
+    doc = subst_braces(doc).strip('\n')
+    return EXAMPLE_FMT(code=doc)
+
+
+def texi_comment(doc):
+    """
+    Format a comment
+
+    Lines starting with:
+    - |: generates an @example
+    - =: generates @section
+    - ==: generates @subsection
+    - 1. or 1): generates an @enumerate @item
+    - o/*/-: generates an @itemize list
+    """
+    lines = []
+    doc = subst_braces(doc)
+    doc = subst_vars(doc)
+    doc = subst_emph(doc)
+    doc = subst_strong(doc)
+    inlist = ""
+    lastempty = False
+    for line in doc.split('\n'):
+        empty = line == ""
+
+        if line.startswith("| "):
+            line = EXAMPLE_FMT(code=line[1:])
+        elif line.startswith("= "):
+            line = "@section " + line[1:]
+        elif line.startswith("== "):
+            line = "@subsection " + line[2:]
+        elif re.match("^([0-9]*[.)]) ", line):
+            if not inlist:
+                lines.append("@enumerate")
+                inlist = "enumerate"
+            line = line[line.find(" ")+1:]
+            lines.append("@item")
+        elif re.match("^[o*-] ", line):
+            if not inlist:
+                lines.append("@itemize %s" % {'o': "@bullet",
+                                              '*': "@minus",
+                                              '-': ""}[line[0]])
+                inlist = "itemize"
+            lines.append("@item")
+            line = line[2:]
+        elif lastempty and inlist:
+            lines.append("@end %s\n" % inlist)
+            inlist = ""
+
+        lastempty = empty
+        lines.append(line)
+
+    if inlist:
+        lines.append("@end %s\n" % inlist)
+    return "\n".join(lines)
+
+
+def texi_args(expr):
+    """
+    Format the functions/structure/events.. arguments/members
+    """
+    data = expr["data"] if "data" in expr else {}
+    if isinstance(data, str):
+        args = data
+    else:
+        arg_list = []
+        for name, typ in data.iteritems():
+            # optional arg
+            if name.startswith("*"):
+                name = name[1:]
+                arg_list.append("['%s': @var{%s}]" % (name, typ))
+            # regular arg
+            else:
+                arg_list.append("'%s': @var{%s}" % (name, typ))
+        args = ", ".join(arg_list)
+    return args
+
+def section_order(section):
+    return {"Returns": 0,
+            "Note": 1,
+            "Notes": 1,
+            "Since": 2,
+            "Example": 3,
+            "Examples": 3}[section]
+
+def texi_body(doc, arg="@var"):
+    """
+    Format the body of a symbol documentation:
+    - a table of arguments
+    - followed by "Returns/Notes/Since/Example" sections
+    """
+    body = "@table %s\n" % arg
+    for arg, desc in doc.args.iteritems():
+        if desc.startswith("#optional"):
+            desc = desc[10:]
+            arg += "*"
+        elif desc.endswith("#optional"):
+            desc = desc[:-10]
+            arg += "*"
+        body += "@item %s\n%s\n" % (arg, texi_comment(desc))
+    body += "@end table\n"
+    body += texi_comment(doc.get_body())
+
+    meta = sorted(doc.meta, key=lambda i: section_order(i[0]))
+    for m in meta:
+        key, doc = m
+        func = texi_comment
+        if key.startswith("Example"):
+            func = texi_example
+
+        body += "\n@quotation %s\n%s\n@end quotation" % \
+                (key, func(doc))
+    return body
+
+
+def texi_alternate(expr, doc):
+    """
+    Format an alternate to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Alternate",
+                      name=doc.symbol,
+                      attrs="[ " + args + " ]",
+                      body=body)
+
+
+def texi_union(expr, doc):
+    """
+    Format an union to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Union",
+                      name=doc.symbol,
+                      attrs="[ " + args + " ]",
+                      body=body)
+
+
+def texi_enum(_, doc):
+    """
+    Format an enum to texi
+    """
+    body = texi_body(doc, "@samp")
+    return ENUM_FMT(name=doc.symbol,
+                    body=body)
+
+
+def texi_struct(expr, doc):
+    """
+    Format a struct to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Struct",
+                      name=doc.symbol,
+                      attrs="@{ " + args + " @}",
+                      body=body)
+
+
+def texi_command(expr, doc):
+    """
+    Format a command to texi
+    """
+    args = texi_args(expr)
+    ret = expr["returns"] if "returns" in expr else ""
+    body = texi_body(doc)
+    return COMMAND_FMT(type="Command",
+                       name=doc.symbol,
+                       ret=ret,
+                       args="(" + args + ")",
+                       body=body)
+
+
+def texi_event(expr, doc):
+    """
+    Format an event to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return COMMAND_FMT(type="Event",
+                       name=doc.symbol,
+                       ret="",
+                       args="(" + args + ")",
+                       body=body)
+
+
+def texi(docs):
+    """
+    Convert QAPI schema expressions to texi documentation
+    """
+    res = []
+    for doc in docs:
+        try:
+            expr_elem = doc.expr_elem
+            if expr_elem is None:
+                res.append(texi_body(doc))
+                continue
+
+            expr = expr_elem['expr']
+            (kind, _) = expr.items()[0]
+
+            fmt = {"command": texi_command,
+                   "struct": texi_struct,
+                   "enum": texi_enum,
+                   "union": texi_union,

scripts/qapi2texi.py line 284

Quoted 10 lines
scripts/qapi2texi.py new file +10 -0
+                   "alternate": texi_alternate,
+                   "event": texi_event}
+            try:
+                fmt = fmt[kind]
+            except KeyError:
+                raise ValueError("Unknown expression kind '%s'" % kind)
+            res.append(fmt(expr, doc))
+        except:
+            print >>sys.stderr, "error at @%s" % qapi
+            raise

What errors do you expect here? I'm asking because catching exceptions indiscrimatingly feels problematic.

scripts/qapi2texi.py line 297

Quoted 13 lines
scripts/qapi2texi.py new file +13 -0
+
+    return '\n'.join(res)
+
+
+def parse_schema(fname):
+    """
+    Parse the given schema file and return the exprs
+    """
+    try:
+        schema = QAPISchemaParser(open(fname, "r"))
+        check_exprs(schema.exprs)
+        check_docs(schema.docs)
+        return schema.docs

You don't actually "return the exprs", you return a list of QAPIDoc.

Either return schema and let the caller retrieve its .docs, or rename the function to parse_docs(). In either case, fix up the doc string.

scripts/qapi2texi.py line 300

Quoted 3 lines
scripts/qapi2texi.py new file +3 -0
+    except (QAPISchemaError, QAPIExprError), err:
+        print >>sys.stderr, err
+        exit(1)

The function duplicates parts of QAPISchema.__init__(). The parts it doesn't duplicate would be useful here, because without them, you might be working on a broken schema.

Recommend to drop the function, and ...

scripts/qapi2texi.py line 311

Quoted 11 lines
scripts/qapi2texi.py new file +11 -0
+
+
+def main(argv):
+    """
+    Takes schema argument, prints result to stdout
+    """
+    if len(argv) != 2:
+        print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" % argv[0]
+        sys.exit(1)
+
+    docs = parse_schema(argv[1])

... instead do

schema = QAPISchema(argv[1])
docs = schema.docs

with the obvious patch to make docs an attribute of schema:

scripts/qapi.py +3 -1
index ed52ee4..b17e7de 100644
@@ -1424,7 +1424,9 @@ class QAPISchemaEvent(QAPISchemaEntity):
 class QAPISchema(object):
     def __init__(self, fname):
         try:
-            self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs)
+            parser = QAPISchemaParser(open(fname, "r"))
+            self.exprs = check_exprs(parser.exprs)
+            self.docs = parser.docs
             self._entity_dict = {}
             self._predefining = True
             self._def_predefineds()

You don't use the common parse_command_line(). Probably the right choice right now, as reusing it would require modifications (we have no use for -c and -h at least), and wouldn't buy us much.

scripts/qapi2texi.py line 316

Quoted 5 lines
scripts/qapi2texi.py new file +5 -0
+    print texi(docs)
+
+
+if __name__ == "__main__":
+    main(sys.argv)

Ignorant question: why is this __name__ == "__main__" raindance better than the stupid way the qapi-{commands,event,introspect,types,visit}.py work?

Quoted 31 lines
docs/qapi-code-gen.txt +7 -10
index 2841c51..d82e251 100644
@@ -45,16 +45,13 @@ QAPI parser does not).  At present, there is no place where a QAPI
 schema requires the use of JSON numbers or null.
 
 Comments are allowed; anything between an unquoted # and the following
-newline is ignored.  Although there is not yet a documentation
-generator, a form of stylized comments has developed for consistently
-documenting details about an expression and when it was added to the
-schema.  The documentation is delimited between two lines of ##, then
-the first line names the expression, an optional overview is provided,
-then individual documentation about each member of 'data' is provided,
-and finally, a 'Since: x.y.z' tag lists the release that introduced
-the expression.  Optional members are tagged with the phrase
-'#optional', often with their default value; and extensions added
-after the expression was first released are also given a '(since
+newline is ignored.  The documentation is delimited between two lines
+of ##, then the first line names the expression, an optional overview
+is provided, then individual documentation about each member of 'data'
+is provided, and finally, a 'Since: x.y.z' tag lists the release that
+introduced the expression.  Optional members are tagged with the
+phrase '#optional', often with their default value; and extensions
+added after the expression was first released are also given a '(since
 x.y.z)' comment.  For example:
 
     ##
@@ -73,12 +70,39 @@ x.y.z)' comment.  For example:
     #           (Since 2.0)
     #

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 81

Quoted 10 lines
docs/qapi-code-gen.txt +9 -0
     # Since: 0.14.0
+    #
+    # Notes: You can also make a list:
+    #        - with items
+    #        - like this
+    #
+    # Example:
+    #
+    # -> { "execute": ... }
+    # <- { "return": ... }

Err, 'BlockStats' is a *type*, not a command.

Quoted 14 lines
docs/qapi-code-gen.txt +8 -0
+    #
     ##
     { 'struct': 'BlockStats',
       'data': {'*device': 'str', 'stats': 'BlockDeviceStats',
                '*parent': 'BlockStats',
                '*backing': 'BlockStats'} }
 
+It's also possible to create documentation sections, such as:
+
+    ##
+    # = Section
+    # == Subsection
+    #
+    # Some text foo with *emphasis*

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 105

Quoted 10 lines
docs/qapi-code-gen.txt +10 -0
+    # 1. with a list
+    # 2. like that
+    #
+    # And some code:
+    # | $ echo foo
+    # | -> do this
+    # | <- get that
+    #
+    ##
+

This suggests various kinds of markup, including section headers, emphasis, numbered lists. But what exactly is recognized?

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 108

Quoted 3 lines
docs/qapi-code-gen.txt +0 -0
 The schema sets up a series of types, as well as commands and events
 that will use those types.  Forward references are allowed: the parser
 scans in two passes, where the first pass learns all type names, and

As discussed in my review of the cover letter, we have some additional documentation work to do.

Also missing: tests. A first cut should have a negative test for each error qapi2texi.py can report, plus a modest suite of positive tests. A negative test consists of tests/qapi-schema/NAME.{json,out,err,exit}. Positive tests can be added to tests/qapi-schema/qapi-schema-test.json, or to a separate test schema, in case that's more convenient.

To get the most mileage out of positive tests, test-qapi.py should be extended to show the resulting QAPIDoc. Sketch appended.

tests/qapi-schema/test-qapi.py +10 -0
index ef74e2c..93cc709 100644
@@ -55,3 +55,13 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
 
 schema = QAPISchema(sys.argv[1])
 schema.visit(QAPISchemaTestVisitor())
+
+for doc in schema.docs:
+    expr_elem = doc.expr_elem
+    expr_info = expr_elem and expr_elem['info']
+    print 'doc %s %s' % (doc.symbol, expr_info)
+    for arg, text in doc.args.iteritems():
+        print '    arg=%s %s' % (arg, text)
+    for key, text in doc.meta:
+        print '    meta %s %s' % (key, text)
+    print '    body=%s' % doc.body
#24 lore raw

Re: [Qemu-devel] [PATCH v3 11/14] qapi: add qapi2texi script

Hi

Quoted 57 lines · Markus Armbruster
Quoted 40 lines · Marc-André Lureau

As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).

It parses the following kind of blocks:

Free-form:

##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:

  # | $ echo foo
  # | -> do this
  # | <- get that

#
##

Symbol:

##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar

  # baz ding.
  #
  # @arg: foo
  # @arg: #optional foo
  #
  # Returns: returns bla bla
  #          Or bla blah
  #
  # Since: version
  # Notes: notes, comments can have
  #        - itemized list
Quoted 8 lines
  #        - like this
  #
  # Example:
  #
  # -> { "execute": "quit" }
  # <- { "return": {} }
  #
  ##

The following discussion belongs to review of qapi-code-gen.txt, but the example here is more abstract and nicely visible, so let me use it.

The "Symbol" kind of block as shown above is for QMP commands with arguments defined inline.

Quoted 8 lines

It also serves for QMP events: just omit the return value.

For struct types, the terminology is a bit off ("argument" instead of "member"), but the basic structure less the return value still works. No surprise, because a command is essentially a triple (name, arguments type, return value type), where the arguments type is a struct type (but see below for non-struct arguments).

Yeah, I stick with args for now, but we may want to rename it to member/fields. Other suggestions?

Quoted 3 lines

From there, it's a small step to using it for enum types.

Right, I realize it may be nice to enumerate the values, even if they are not documented. I have made some changes in this direction in the generator.

Quoted 4 lines

But how to do union types is non-obvious. In their general form, they have common members, one of them the tag, and variant members depending on the tag value. How do we want such types be documented?

Fair enough, union types are quite badly documented by current version of generator. I have made some changes, so 'base' arguments and 'data' alternative are shown that way:

BlockdevOptions (Union)

{ 'driver': BlockdevDriver, ['node-name': str], ['discard':
BlockdevDiscardOptions], ['cache': BlockdevCacheOptions], ['read-only':
bool], ['detect-zeroes': BlockdevDetectZeroesOptions] } + 'driver' = [ 'archipelago': BlockdevOptionsArchipelago, 'blkdebug':
BlockdevOptionsBlkdebug,....

Quoted 2 lines

Alternate types can be documented like structs, I think.

mostly, I have used the [] syntax to represent union & alternatives (instead of {}). I hope that helps.

Quoted 11 lines

What about QMP commands with arguments of the form 'data': 'TypeName'? We typically replace the whole @arg: part by something like

# For the arguments, see the documentation of BlockdevSnapshotSync.

Note that with 'boxed': true, TypeName could even be union or alternate.

My point is: the documentation needs work. Whether we should do the within this series or on top is debatable.

I'd rather fix it on top, that series is already pretty large and dense, and hopefully is a good starting point.

Quoted 6 lines
Quoted 2 lines

That's roughly following the following BNF grammar:

EBNF, actually.

ok

Quoted 8 lines
Quoted 4 lines

api_comment = "##\n" comment "##\n"
comment = freeform_comment | symbol_comment
freeform_comment = { "#" text "\n" }

As we'll see below, your code actually requires at least one space after "#" unless text is empty.

ok

Quoted 7 lines
Quoted 1 line

symbol_comment = "#" "@" name ":\n" { freeform | member | meta }

Your code actually requires exactly one space between "#" and "@". It happily accepts additional text between : and newline.

freeform is undefined. I guess you mean freeform_comment.

ok

Quoted 12 lines

With that corrected, the grammar is ambiguous. Your intent is obvious enough, though. Just not to a computer.

Quoted 1 line

member = "#" '@' name ':' [ text ] freeform_comment

Again, your code requires exactly one space after "#".

Quoted 1 line

meta = "#" ( "Returns:", "Since:", "Note:", "Notes:", "Example:",

"Examples:" ) [ text ] freeform_comment

Likewise.

ok

Quoted 15 lines
Quoted 1 line

text = free-text markdown-like, "#optional" for members

Here, the grammar switches from EBNF to prose.

As is, the grammar can serve as semi-formal user documentation. It can't quite serve as specification for the parser. As we'll see below, the code processing doc strings is not a parser constructed from this grammar.

Why am I so hung up on constructing parsers systematically from grammars? When you do that, you can derive the accepted language from the *grammar*. Generally *much* easier than from ad hoc parser code. Moreover, a (sufficiently simple) grammar leads to a natural internal representation, namely an abstract syntax tree.

Quoted 8 lines

But let's continue.

Quoted 3 lines

Thanks to the following json expressions, the documentation is enhanced with extra information about the type of arguments and return value expected.

What exactly do you want to convey with this sentence?

Not much, that we use the json expressions to enhance the written doc.

Quoted 10 lines
Quoted 5 lines
---
 scripts/qapi.py        | 175 ++++++++++++++++++++++++++-
 scripts/qapi2texi.py   | 316

+++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 4 lines
 docs/qapi-code-gen.txt |  44 +++++--
 3 files changed, 524 insertions(+), 11 deletions(-)
 create mode 100755 scripts/qapi2texi.py
Quoted 10 lines

scripts/qapi.py

Quoted 4 lines
scripts/qapi.py +0 -0
index 21bc32f..ed52ee4 100644

Warning: loads of comments ahead. Doesn't mean there are loads of problems! I need to write to think clearly, and I'm sharing my thinking to hopefully help us converge.

ok :)

Quoted 23 lines

scripts/qapi.py class QAPIExprError(Exception): · line 122

Quoted 2 lines
scripts/qapi.py +0 -0
@@ -122,6 +122,103 @@ class QAPIExprError(Exception):
             "%s:%d: %s" % (self.info['file'], self.info['line'],

self.msg)

scripts/qapi.py class QAPIExprError(Exception): · line 128

Quoted 8 lines
scripts/qapi.py +6 -0
+class QAPIDoc(object):
+    def __init__(self, parser):
+        self.parser = parser
+        self.symbol = None
+        self.body = []
+        # args is {'arg': 'doc', ...}

Rather terse, but I think I get what you mean.

scripts/qapi.py class QAPIExprError(Exception): · line 130

Quoted 2 lines
scripts/qapi.py +2 -0
+        self.args = OrderedDict()
+        # meta is [(Since/Notes/Examples/Returns:, 'doc'), ...]

More so.

scripts/qapi.py class QAPIExprError(Exception): · line 132

Quoted 2 lines
scripts/qapi.py +2 -0
+        self.meta = []
+        # the current section to populate, array of [dict, key,

comment...]

Quoted 8 lines

Now you've reached my limit :)

"array of [...]" sounds like a list of lists. But you probably mean just a list.

We'll see below that dict is either self.args or self.meta, and key is a key in dict.

I have introduced a nested Section class, hopefull that helps a bit

Quoted 10 lines

scripts/qapi.py class QAPIExprError(Exception): · line 137

Quoted 5 lines
scripts/qapi.py +5 -0
+        self.section = None
+        self.expr_elem = None
+
+    def get_body(self):
+        return "\n".join(self.body)

Not worth a doc string? The existing code doesn't have any, but since you provide them for other public methods of this class...

Not all of them, get_body() and end_section() seem rather obvious to me, doc string could be redundant.

Quoted 8 lines

+

scripts/qapi.py class QAPIExprError(Exception): · line 140

Quoted 3 lines
scripts/qapi.py +3 -0
+    def has_meta(self, name):
+        """Returns True if the doc has a meta section 'name'"""
+        return next((True for i in self.meta if i[0] == name), False)

Less clever, but probably more obvious to readers lacking a degree in Python generators:

Quoted 8 lines

for i in self.meta:
if i[0] == name:
return True
return False

I'm not against using more advanced language features, but when the "advanced" code needs more tokens than the "retarded" one...

agree (I think I had something else in mind when I started writing that line)

Quoted 6 lines

scripts/qapi.py class QAPIExprError(Exception): · line 144

Quoted 5 lines
scripts/qapi.py +4 -0
+
+    def append(self, line):
+        """Adds a # comment line, to be parsed and added in a section"""
+        line = line[1:]
Quoted 6 lines

As we'll see below, @line is the full comment token text including the initial '#', but not including the final '\n'. First thing we do with it is strip the initial '#'. Makes me wonder why we pass it in. It's not wrong, of course.

I don't see much point in changing this either

Quoted 30 lines

Note that comments don't need to be full lines, they just happen to be used that way most of the time. Admittedly contrived counter-example:

    { 'enum': 'Empty', 'data': [] } ##
                                    # @XY:
                                    ##
    { 'enum': 'XY', 'data': ['x', 'y'] }

This makes the parser call doc.append("# @XY:"). The argument "# @XY:" isn't a full line in the source. It becomes a line in the documentation text QAPIDoc wraps.

scripts/qapi.py class QAPIExprError(Exception): · line 147

Quoted 3 lines
scripts/qapi.py +3 -0
+        if len(line) == 0:
+            self._append_section(line)
+            return

Special case for comment '#'. Note that '# ' is processed as a normal case.

scripts/qapi.py class QAPIExprError(Exception): · line 154

Quoted 7 lines
scripts/qapi.py +7 -0
+
+        if line[0] != ' ':
+            raise QAPISchemaError(self.parser, "missing space after #")
+
+        line = line[1:]
+        # take the first word out
+        name = line.split(' ', 1)[0]

For a comment '# ', @name becomes '', because ''.split(' ', 1) returns ['']. Works.

Quoted 4 lines

For a comment '# Since:' (note two spaces), name becomes '', because .split() returns ['', 'Since:']. Thus, the keywords are only recognized exactly after '# '. Is this a good idea?

Good for consistency, and there might be cases where arg version/note documentation could legitimately (for now) look like:

##
# @foo:
# @arg: bla blah
# Since: 2.8
##

Quoted 10 lines

+ if name.startswith("@") and name.endswith(":"):

scripts/qapi.py class QAPIExprError(Exception): · line 158

Quoted 4 lines
scripts/qapi.py +4 -0
+            line = line[len(name):]
+            name = name[1:-1]
+            if self.symbol is None:
+                # the first is the symbol this APIDoc object documents

Suggest

# The first @NAME: is the symbol being documented

ok

Quoted 10 lines

scripts/qapi.py class QAPIExprError(Exception): · line 160

Quoted 3 lines
scripts/qapi.py +2 -0
+                if len(self.body):
+                    raise QAPISchemaError(self.parser, "symbol must

come first")

You and I know what 'symbol' means here, but the user should not need to know. Suggest something like "'@%s:' must come first". I'm not entirely happy with that either, but I don't have better ideas right now.

ok

Quoted 10 lines

If the parser was constructed from your grammar, we'd deal with the first @NAME: not coming first differently. According to the grammar, a doc comment block either starts with '##\n# @' (a symbol block), or it doesn't (a free-form block). If the first line isn't a @NAME: line, but later lines are, the parser decides it's a free-from block right there. Any @NAME: lines it finds later would be parsed as free-form line. If we want to reject such lines in free-form blocks, the easiest way would be a semantic check.

Ok, I'll move it do check_docs()

Quoted 11 lines

+ self.symbol = name

Here's how we can tell what kind of block we're working on:

if .symbol is not None:
this is a symbol block
elif .body is not None:
this is a free-form block
else
we don't know, yet

ok, I have adapted it slightly to avoid some redundancy in the "we don't know" and "free-form" cases

Quoted 6 lines

scripts/qapi.py class QAPIExprError(Exception): · line 162

Quoted 2 lines
scripts/qapi.py +2 -0
+            else:
+                # else an arg

Suggest
# Subsequent @NAME: are arguments and such

This goes away with above refactoring, since we know we are parsing args

Quoted 17 lines

scripts/qapi.py class QAPIExprError(Exception): · line 163

Quoted 2 lines
scripts/qapi.py +1 -0
+                self._start_args_section(name)

The remainder of the line after @NAME: is left in @line, and will be stuffed into the current section or else the body after the conditional. That's what the grammar specifies for argument NAME, in rule member. It's not what it specifies for symbol NAME, in rule symbol_comment.

In particular, when nothing follows symbol NAME, we still stuff '' into the body. For instance,

    ##
    # @symbol:
    #
    # lorem ipsum
    ##
Quoted 4 lines

produces self.body = ['', '', 'lorem ipsum'], which .get_body() transforms into '\n\nlorem ipsum'. Extra newline. I guess it's all the same to Texinfo in the end.

Ok, let's make sure the first @symbol: doesn't contain extra characters.

Quoted 18 lines
Quoted 6 lines
scripts/qapi.py +5 -0
+        elif self.symbol and name in (
+                "Returns:", "Since:",
+                # those are often singular or plural
+                "Note:", "Notes:",
+                "Example:", "Examples:"):

scripts/qapi.py class QAPIExprError(Exception): · line 178

Quoted 10 lines
scripts/qapi.py +10 -0
+            # new "meta" section
+            line = line[len(name):]
+            self._start_meta_section(name[:-1])
+
+        self._append_section(line)
+
+    def _start_args_section(self, name):
+        self.end_section()
+        if self.args.has_key(name):
+            raise QAPISchemaError(self.parser, "'%s' arg duplicated" %

name)

Quoted 3 lines

Where's self.args[name] added? Oh, I see, it's hidden in end_section(). Could it be added here instead?

How? self.args[name] = "" which will be overwritten in end_section? ok

Quoted 7 lines

scripts/qapi.py class QAPIExprError(Exception): · line 184

Quoted 7 lines
scripts/qapi.py +6 -0
+        self.section = [self.args, name]
+
+    def _start_meta_section(self, name):
+        self.end_section()
+        if name in ("Returns", "Since") and self.has_meta(name):
+            raise QAPISchemaError(self.parser, "'%s' section
Quoted 7 lines

duplicated" % name)

For the implementation, it's a section, but for the user, it's a line. Suggest "Duplicate '%s'".

Comment on _start_args_section() applies.

ok

Quoted 9 lines

scripts/qapi.py class QAPIExprError(Exception): · line 188

Quoted 4 lines
scripts/qapi.py +4 -0
+        self.section = [self.meta, name]
+
+    def _append_section(self, line):
+        """Add a comment to the current section, or the comment body"""

_append_to_section() or _section_append() would be clearer. We're not appending a section, we're appending *to* a section. Or to the body, which isn't a section. Hmm.

ok, what about _append_freeform() ?

Quoted 11 lines

scripts/qapi.py class QAPIExprError(Exception): · line 197

Quoted 10 lines
scripts/qapi.py +9 -0
+        if self.section:
+            name = self.section[1]
+            if not name.startswith("Example"):
+                # an empty line ends the section, except with Example
+                if len(self.section) > 2 and len(line) == 0:
+                    self.end_section()
+                    return
+                # Example is verbatim
+                line = line.strip()
Quoted 4 lines

The comment is confusing, because it explains what we're not doing elsewhere. Comments should explain what we're doing here.

ok, I'll remove it

Quoted 8 lines

scripts/qapi.py class QAPIExprError(Exception): · line 204

Quoted 7 lines
scripts/qapi.py +7 -0
+            if len(line) > 0:
+                self.section.append(line)
+        else:
+            self.body.append(line.strip())
+
+    def end_section(self):
+        if self.section is not None:
Quoted 10 lines

I prefer the more laconic "if self.section:", especially when self.section can't have a false value other than None anyway. Even more I prefer making the fact that this does nothing when we don't have a section immediately obvious:

if not self.section:
return
do the work...

ok

Quoted 62 lines

scripts/qapi.py class QAPIExprError(Exception): · line 214

Quoted 10 lines
scripts/qapi.py +10 -0
+            target = self.section[0]
+            name = self.section[1]
+            if len(self.section) < 3:
+                raise QAPISchemaError(self.parser, "Empty doc section")
+            doc = "\n".join(self.section[2:])
+            if isinstance(target, dict):
+                target[name] = doc
+            else:
+                target.append((name, doc))
+            self.section = None

Until the next _start_FOO_section(), self.section remains None. Therefore, any text between here and the next section will be appended to self.body. This is going to mangle input that doesn't quite match expectations. Example:

    ##
    # @frobnicate:
    #
    # Frobnicate some frobs.
    #
    # @frobs: bla, bla, explain @frobs,
    #         bla.
    #
    #         Beware of the tiger!
    #
    #         Explain @frobs some more, bla, bla.
    #
    # @harder: frobnicate harder.
    ##
    { 'command': 'frobnicate',
      'data': { 'frobs': 'any', '*harder': 'bool' } }

Results in a QAPIDoc with

    .symbol = 'frobnicate'
    .args = { 'frobs': 'frobs bla, bla, explain,\nbla',
              'harder': 'frobnicate harder.' }
    .body = ['', '', 'Frobnicate some frobs.', '',
             'Beware of the tiger!', '',
             'Explain some more, bla, bla.', '']

and the following .texi:

@deftypefn Command {} frobnicate @ {('frobs': @var{any}, ['harder': @var{bool}])}

@table @var
@item frobs
bla, bla, explain @var{frobs},
bla.
@item harder
frobnicate harder.
@end table

Frobnicate some frobs.

Beware of the tiger!

Explain @var{frobs} some more, bla, bla.

Quoted 8 lines

The only way to detect the mistake is to read the generated documentation attentively. We can't rely on everybody doing that during development. Even when you do, the mangled output gives you no clue on the mistake you made, unless you know how the doc generator works.

The generator could detect the mistake at the syntactical or at the semantic level.

I have changed the logic there, since in general paragraphs are indented with @arg sections like your example above. So an empty line will no longer break the current section, only an empty line followed by a non-indented paragraph after an argument documentation will. That is

@foo: arg doc

Blah

Will break the argument section on "Blah", and append it to the documentation body.

This fixes real doc issues from previous iterations, see @block-commit for example.

More general question: can you think of a legitimate reason for the

Quoted 3 lines

generator emitting documentation in a different order than it was written?

It would be nicer if the generator can freely reorder/display the documentation, for consistency and style (different blocks could use different style etc).

Quoted 67 lines

If no, we should pick an internal representation that can represent the input we have / envisage to have faithfully, then reject input it can't represent faithfully.

scripts/qapi.py class QAPISchemaParser(object):

Quoted 6 lines
scripts/qapi.py +2 -0
+
+
 class QAPISchemaParser(object):
 
     def __init__(self, fp, previously_included=[], incl_info=None):
@@ -137,9 +234,15 @@ class QAPISchemaParser(object):

Let's see how parsing works.

scripts/qapi.py class QAPISchemaParser(object): · line 245

Quoted 12 lines
scripts/qapi.py +6 -0
         self.line = 1
         self.line_pos = 0
         self.exprs = []
+        self.docs = []
         self.accept()
 
         while self.tok is not None:
+            if self.tok == '#' and self.val.startswith('##'):
+                doc = self.get_doc()
+                self.docs.append(doc)
+                continue
+

Top-level doc comments get accumulated in list self.docs.

scripts/qapi.py class QAPISchemaParser(object): · line 263

Quoted 5 lines
scripts/qapi.py +0 -0
             expr_info = {'file': fname, 'line': self.line,
                          'parent': self.incl_info}
             expr = self.get_expr(False)
@@ -160,6 +263,7 @@ class QAPISchemaParser(object):
                         raise QAPIExprError(expr_info, "Inclusion loop

for %s"

scripts/qapi.py class QAPISchemaParser(object): · line 275

Quoted 8 lines
scripts/qapi.py +1 -0
                                             % include)
                     inf = inf['parent']
+
                 # skip multiple include of the same file
                 if incl_abs_fname in previously_included:
                     continue
@@ -171,12 +275,40 @@ class QAPISchemaParser(object):
                 exprs_include = QAPISchemaParser(fobj,

previously_included,

scripts/qapi.py class QAPISchemaParser(object): · line 278

Quoted 3 lines
scripts/qapi.py +1 -0
                                                  expr_info)
                 self.exprs.extend(exprs_include.exprs)
+                self.docs.extend(exprs_include.docs)

The include's list of docs are spliced in.

scripts/qapi.py class QAPISchemaParser(object): · line 284

Quoted 6 lines
scripts/qapi.py +2 -0
             else:
                 expr_elem = {'expr': expr,
                              'info': expr_info}
+                if len(self.docs) > 0:
+                    self.docs[-1].expr_elem = expr_elem
                 self.exprs.append(expr_elem)

A non-include expression gets tied to the last doc comment. This isn't quite right. Example:

    ##
    # @Empty:
    ##
    { 'enum': 'Empty', 'data': [] }

    { 'enum': 'XY', 'data': ['x', 'y'] }
Quoted 3 lines

The doc comment's expr_elem gets first set to the first enum expression, then overwritten with the second one.

good catch, regression from last iteration

Quoted 13 lines

Less serious, but still somewhat weird:

    ##
    # Lorem ipsum
    ##

    # @Empty:
    { 'enum': 'Empty', 'data': [] }

The first comment block is a doc comment. The second one isn't, and gets ignored. The first one's expr_elem gets set to the enum expression.

Quoted 8 lines

The quick fix is to set .expr_elem only when it's still None.

I'll take the quick fix

The thorough fix is to integrate doc comments deeper into the syntax.

as you know, my initial goal was not to bring a strict doc parser (many doc parser are not that strict and work well enough), rather to just generate something good enough out of the json to get rid of txt duplication. Further improvements can be made after this series hopefully.

Quoted 7 lines

scripts/qapi.py class QAPISchemaParser(object): · line 285

Quoted 3 lines
scripts/qapi.py +1 -1
-    def accept(self):
+    def get_doc(self):

Here, we know self.tok == '#', and self.val is thus the comment line less the newline (see accept()).

Quoted 8 lines

scripts/qapi.py class QAPISchemaParser(object): · line 287

Quoted 2 lines
scripts/qapi.py +2 -0
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not starting with

'##'")

It starts with '##' alright, it just happens not to end there. What about "Junk after '##'"? Or, if that's too laconic, perhaps "Junk after '##' at start of documentation comment".

ok

Quoted 7 lines

scripts/qapi.py class QAPISchemaParser(object): · line 293

Quoted 6 lines
scripts/qapi.py +6 -0
+
+        doc = QAPIDoc(self)
+        self.accept(False)
+        while self.tok == '#':
+            if self.val.startswith('##'):
+                # ## ends doc
Quoted 5 lines

"# ##" looks awkward. Suggest

# End of doc comment

ok

Quoted 7 lines

scripts/qapi.py class QAPISchemaParser(object): · line 296

Quoted 3 lines
scripts/qapi.py +3 -0
+                if self.val != '##':
+                    raise QAPISchemaError(self, "non-empty '##' line %s"
+                                          % self.val)

Let's make the message similar to whatever message we emit for junk after the initial ##.

ok

Quoted 43 lines

scripts/qapi.py class QAPISchemaParser(object): · line 303

Quoted 8 lines
scripts/qapi.py +7 -0
+                self.accept()
+                doc.end_section()
+                return doc
+            else:
+                doc.append(self.val)
+            self.accept(False)
+

Here, self.tok is whatever follows the doc comment.

scripts/qapi.py class QAPISchemaParser(object): · line 305

Quoted 2 lines
scripts/qapi.py +2 -0
+        if self.val != '##':
+            raise QAPISchemaError(self, "Doc comment not finishing with

'##'")

This check is incorrect. For instance, input

    ##
    '## gotcha'

yields

/dev/stdin:2:1: Doc comment not finishing with '##'

because self.tok == "'" and self.val == "## gotcha".

Either fail unconditionally here (then the final ## is required), or do nothing (then it's optional). Your commit message suggests the former.

ok

Quoted 11 lines
scripts/qapi.py +5 -0
+
+        doc.end_section()
+        return doc
+
+    def accept(self, skip_comment=True):
         while True:
             self.tok = self.src[self.cursor]
             self.pos = self.cursor
@@ -184,7 +316,13 @@ class QAPISchemaParser(object):
             self.val = None
 
Quoted 9 lines

scripts/qapi.py class QAPISchemaParser(object): · line 320

Quoted 3 lines
scripts/qapi.py +2 -0
             if self.tok == '#':
+                if self.src[self.cursor] == '#':
+                    # ## starts a doc comment

Suggest

# Start of doc comment

ok

Quoted 23 lines

scripts/qapi.py class QAPISchemaParser(object): · line 323

Quoted 3 lines
scripts/qapi.py +2 -0
+                    skip_comment = False
                 self.cursor = self.src.find('\n', self.cursor)
+                self.val = self.src[self.pos:self.cursor]

Puts the complete line less the newline into self.val. I wonder whether we should strip the initial '#' as well.

scripts/qapi.py class QAPISchemaParser(object): · line 325

Quoted 2 lines
scripts/qapi.py +2 -0
+                if not skip_comment:
+                    return

Make that

if not skip_comment:
self.val = self.src[self.pos:self.cursor] return

ok

scripts/qapi.py class QAPISchemaParser(object): · line 328

Quoted 3 lines
scripts/qapi.py +0 -0
             elif self.tok in "{}:,[]":
                 return
             elif self.tok == "'":
Quoted 8 lines

Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in get_doc().

This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.

Alternative I imagine is to return comments from the lexer, I don't mind if you prefer it that way, let me know

A comment starting with ## inside an expression is now a syntax error.

Quoted 15 lines

For instance, input

    {
    ##

yields

    /dev/stdin:2:1: Expected string or "}"

Rather unfriendly error message, but we can fix that on top.

Quoted 4 lines
scripts/qapi.py +0 -0
@@ -779,6 +917,41 @@ def check_exprs(exprs):
 
     return exprs
 
Quoted 9 lines

scripts/qapi.py def check_exprs(exprs): · line 924

Quoted 5 lines
scripts/qapi.py +5 -0
+def check_docs(docs):
+    for doc in docs:
+        expr_elem = doc.expr_elem
+        if not expr_elem:
+            continue

A symbol block without an expr_elem should be an error, shouldn't it?

I don't think we want to make comments mandatory, for tests at least. I have move the check to check_exprs() and added a 'strict_doc' argument only set when generating doc.

Quoted 17 lines

+

scripts/qapi.py def check_exprs(exprs): · line 926

Quoted 2 lines
scripts/qapi.py +2 -0
+        expr = expr_elem['expr']
+        for i in ('enum', 'union', 'alternate', 'struct', 'command',

'event'):

scripts/qapi.py def check_exprs(exprs): · line 929

Quoted 3 lines
scripts/qapi.py +3 -0
+            if i in expr:
+                meta = i
+                break

We're working with expression trees here, not the QAPISchemaEntity objects. Okay as long as the work is sufficiently trivial.

scripts/qapi.py def check_exprs(exprs): · line 935

Quoted 6 lines
scripts/qapi.py +6 -0
+
+        info = expr_elem['info']
+        name = expr[meta]
+        if doc.symbol != name:
+            raise QAPIExprError(info,
+                                "Documentation symbol mismatch '%s' !=
Quoted 6 lines

'%s'"

scripts/qapi.py def check_exprs(exprs): · line 936

Quoted 1 line
scripts/qapi.py +1 -0
+                                % (doc.symbol, name))

Cryptic. Suggest "Definition of '%s' follows documentation for '%s'" % (name, doc.symbol).

ok

Quoted 51 lines

scripts/qapi.py def check_exprs(exprs): · line 940

Quoted 5 lines
scripts/qapi.py +4 -0
+        if not 'command' in expr and doc.has_meta('Returns'):
+            raise QAPIExprError(info, "Invalid return documentation")
+
+        doc_args = set(doc.args.keys())

doc_args is the set of documented argument names. Actually member names when expr defines a type, but let's ignore that for now.

scripts/qapi.py def check_exprs(exprs): · line 947

Quoted 7 lines
scripts/qapi.py +7 -0
+        if meta == 'union':
+            data = expr.get('base', [])
+        else:
+            data = expr.get('data', [])
+        if isinstance(data, dict):
+            data = data.keys()
+        args = set([k.strip('*') for k in data])

Suggest to rename k to name.

ok

To see what args is, we first need to figure out what data is.

If expr defines an enum, expr['data'] is the list of of member names. args is the set of member names.

If expr defines a struct type, expr['data'] is the OrderedDict mapping local member names with optional '*' prefix to types. args is the set of local member names. "Local", because additional members may be inherited from a base type.

If expr defines an alternate type, likewise, except there should be no '*' prefixes and no base type.

If expr defines a simple union type, expr['data'] is the OrderedDict mapping tag value names to types. The tag member is implicit. expr['base'] should not exist. args is therefore the empty set.

If expr defines a flat union type, data is the OrderedDict mapping tag value names to types. expr['base'] must exist, and is either a dictionary or the name of a struct type. If it's a dictionary, args is the set of common members defined inline. If it's a struct type name, args is the set of characters in the type name. Oops. Test case: union UserDefFlatUnion in qapi-schema-test.json.

Aside: covering all cases correctly is not trivial enough for expression trees, I'm afraid. Class QAPISchema has to do it. Can we avoid duplicating its logic here? I'm not sure; the QAPISchemaEntity might turn out to be just differently inconvenient.

Quoted 6 lines

If expr defines a command, data is either the OrderedDict mapping argument names to types, or the name of the arguments type. If it's a dictionary, args is the set of argument names. If it's a type name, args is the set of characters in the type name. Oops again. Test case:
command user_def_cmd0 in qapi-schema-test.json.

Do those have real use cases in the schema? If not, could we ignore or not support them?

Quoted 7 lines

If expr defines an event, likewise. No test case in qapi-schema-test.json. Hole in the test coverage.

Conclusion: args is meant to be the set of arguments / members actually defined. For unions, that does *not* include variant members.

I understand there is a lot of missing cases, but since they don't seem to be reached, can we leave this for a future improvement? Someone more familiar with QAPI details could help me here :)

Quoted 19 lines

scripts/qapi.py def check_exprs(exprs): · line 950

Quoted 3 lines
scripts/qapi.py +3 -0
+        if meta == 'alternate' or \
+           (meta == 'union' and not expr.get('discriminator')):
+            args.add('type')

For alternate and simple union types, add 'type' to the set of arguments actually defined.

Recall that the set contains the member names for alternates, and nothing for simple unions.

scripts/qapi.py def check_exprs(exprs): · line 951

Quoted 1 line
scripts/qapi.py +1 -0
+        if not doc_args.issubset(args):

Could use the <= operator: if not doc_args <= args. Matter of taste.

scripts/qapi.py def check_exprs(exprs): · line 952

Quoted 1 line
scripts/qapi.py +1 -0
+            raise QAPIExprError(info, "Members documentation is not a

subset of"

scripts/qapi.py def check_exprs(exprs): · line 953

Quoted 1 line
scripts/qapi.py +1 -0
+                                " API %r > %r" % (list(doc_args),

list(args)))

Quoted 8 lines

Errors out if the doc string documents arguments that aren't actually defined as far as we know.

"As far as we know", because we second-guess what's actually defined based on the expression tree, and don't get all the cases right. The actual actual definitions are determined by class QAPISchema, and can be found in its internal representation. Hmm.

I guess this can be later improved by using lookup_entity()?

Quoted 3 lines

Failing to document an argument is not an error. It probably should be, at least in the longer run.

Eventually, since we have total control of the documentation. But in practice, arguments can be quite obvious and people tend to not document them, I wouldn't be so strict.

Quoted 13 lines

scripts/qapi2texi.py

Quoted 8 lines
scripts/qapi.py +0 -0
 #
 # Schema compiler frontend
scripts/qapi2texi.py new file +0 -0
new file mode 100755
index 0000000..7e2440c

Considering the length of this review so far, I'm only skimming generator part for now.

thanks ;)

Quoted 281 lines

scripts/qapi2texi.py line 6

Quoted 7 lines
scripts/qapi2texi.py new file +6 -0
@@ -0,0 +1,316 @@
+#!/usr/bin/env python
+# QAPI texi generator
+#
+# This work is licensed under the terms of the GNU LGPL, version 2+.
+# See the COPYING file in the top-level directory.
+"""This script produces the documentation of a qapi schema in texinfo

format"""

Quoted 273 lines
scripts/qapi2texi.py new file +273 -0
+import re
+import sys
+
+from qapi import *
+
+COMMAND_FMT = """
+@deftypefn {type} {{{ret}}} {name} @
+{{{args}}}
+
+{body}
+
+@end deftypefn
+
+""".format
+
+ENUM_FMT = """
+@deftp Enum {name}
+
+{body}
+
+@end deftp
+
+""".format
+
+STRUCT_FMT = """
+@deftp {type} {name} @
+{{{attrs}}}
+
+{body}
+
+@end deftp
+
+""".format
+
+EXAMPLE_FMT = """@example
+{code}
+@end example
+""".format
+
+
+def subst_strong(doc):
+    """Replaces *foo* by @strong{foo}"""
+    return re.sub(r'\*([^_\n]+)\*', r'@emph{\1}', doc)
+
+
+def subst_emph(doc):
+    """Replaces _foo_ by @emph{foo}"""
+    return re.sub(r'\s_([^_\n]+)_\s', r' @emph{\1} ', doc)
+
+
+def subst_vars(doc):
+    """Replaces @var by @var{var}"""
+    return re.sub(r'@([\w-]+)', r'@var{\1}', doc)
+
+
+def subst_braces(doc):
+    """Replaces {} with @{ @}"""
+    return doc.replace("{", "@{").replace("}", "@}")
+
+
+def texi_example(doc):
+    """Format @example"""
+    doc = subst_braces(doc).strip('\n')
+    return EXAMPLE_FMT(code=doc)
+
+
+def texi_comment(doc):
+    """
+    Format a comment
+
+    Lines starting with:
+    - |: generates an @example
+    - =: generates @section
+    - ==: generates @subsection
+    - 1. or 1): generates an @enumerate @item
+    - o/*/-: generates an @itemize list
+    """
+    lines = []
+    doc = subst_braces(doc)
+    doc = subst_vars(doc)
+    doc = subst_emph(doc)
+    doc = subst_strong(doc)
+    inlist = ""
+    lastempty = False
+    for line in doc.split('\n'):
+        empty = line == ""
+
+        if line.startswith("| "):
+            line = EXAMPLE_FMT(code=line[1:])
+        elif line.startswith("= "):
+            line = "@section " + line[1:]
+        elif line.startswith("== "):
+            line = "@subsection " + line[2:]
+        elif re.match("^([0-9]*[.)]) ", line):
+            if not inlist:
+                lines.append("@enumerate")
+                inlist = "enumerate"
+            line = line[line.find(" ")+1:]
+            lines.append("@item")
+        elif re.match("^[o*-] ", line):
+            if not inlist:
+                lines.append("@itemize %s" % {'o': "@bullet",
+                                              '*': "@minus",
+                                              '-': ""}[line[0]])
+                inlist = "itemize"
+            lines.append("@item")
+            line = line[2:]
+        elif lastempty and inlist:
+            lines.append("@end %s\n" % inlist)
+            inlist = ""
+
+        lastempty = empty
+        lines.append(line)
+
+    if inlist:
+        lines.append("@end %s\n" % inlist)
+    return "\n".join(lines)
+
+
+def texi_args(expr):
+    """
+    Format the functions/structure/events.. arguments/members
+    """
+    data = expr["data"] if "data" in expr else {}
+    if isinstance(data, str):
+        args = data
+    else:
+        arg_list = []
+        for name, typ in data.iteritems():
+            # optional arg
+            if name.startswith("*"):
+                name = name[1:]
+                arg_list.append("['%s': @var{%s}]" % (name, typ))
+            # regular arg
+            else:
+                arg_list.append("'%s': @var{%s}" % (name, typ))
+        args = ", ".join(arg_list)
+    return args
+
+def section_order(section):
+    return {"Returns": 0,
+            "Note": 1,
+            "Notes": 1,
+            "Since": 2,
+            "Example": 3,
+            "Examples": 3}[section]
+
+def texi_body(doc, arg="@var"):
+    """
+    Format the body of a symbol documentation:
+    - a table of arguments
+    - followed by "Returns/Notes/Since/Example" sections
+    """
+    body = "@table %s\n" % arg
+    for arg, desc in doc.args.iteritems():
+        if desc.startswith("#optional"):
+            desc = desc[10:]
+            arg += "*"
+        elif desc.endswith("#optional"):
+            desc = desc[:-10]
+            arg += "*"
+        body += "@item %s\n%s\n" % (arg, texi_comment(desc))
+    body += "@end table\n"
+    body += texi_comment(doc.get_body())
+
+    meta = sorted(doc.meta, key=lambda i: section_order(i[0]))
+    for m in meta:
+        key, doc = m
+        func = texi_comment
+        if key.startswith("Example"):
+            func = texi_example
+
+        body += "\n@quotation %s\n%s\n@end quotation" % \
+                (key, func(doc))
+    return body
+
+
+def texi_alternate(expr, doc):
+    """
+    Format an alternate to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Alternate",
+                      name=doc.symbol,
+                      attrs="[ " + args + " ]",
+                      body=body)
+
+
+def texi_union(expr, doc):
+    """
+    Format an union to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Union",
+                      name=doc.symbol,
+                      attrs="[ " + args + " ]",
+                      body=body)
+
+
+def texi_enum(_, doc):
+    """
+    Format an enum to texi
+    """
+    body = texi_body(doc, "@samp")
+    return ENUM_FMT(name=doc.symbol,
+                    body=body)
+
+
+def texi_struct(expr, doc):
+    """
+    Format a struct to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return STRUCT_FMT(type="Struct",
+                      name=doc.symbol,
+                      attrs="@{ " + args + " @}",
+                      body=body)
+
+
+def texi_command(expr, doc):
+    """
+    Format a command to texi
+    """
+    args = texi_args(expr)
+    ret = expr["returns"] if "returns" in expr else ""
+    body = texi_body(doc)
+    return COMMAND_FMT(type="Command",
+                       name=doc.symbol,
+                       ret=ret,
+                       args="(" + args + ")",
+                       body=body)
+
+
+def texi_event(expr, doc):
+    """
+    Format an event to texi
+    """
+    args = texi_args(expr)
+    body = texi_body(doc)
+    return COMMAND_FMT(type="Event",
+                       name=doc.symbol,
+                       ret="",
+                       args="(" + args + ")",
+                       body=body)
+
+
+def texi(docs):
+    """
+    Convert QAPI schema expressions to texi documentation
+    """
+    res = []
+    for doc in docs:
+        try:
+            expr_elem = doc.expr_elem
+            if expr_elem is None:
+                res.append(texi_body(doc))
+                continue
+
+            expr = expr_elem['expr']
+            (kind, _) = expr.items()[0]
+
+            fmt = {"command": texi_command,
+                   "struct": texi_struct,
+                   "enum": texi_enum,
+                   "union": texi_union,
+                   "alternate": texi_alternate,
+                   "event": texi_event}
+            try:
+                fmt = fmt[kind]
+            except KeyError:
Quoted 9 lines

scripts/qapi2texi.py line 284

Quoted 5 lines
scripts/qapi2texi.py new file +5 -0
+                raise ValueError("Unknown expression kind '%s'" % kind)
+            res.append(fmt(expr, doc))
+        except:
+            print >>sys.stderr, "error at @%s" % qapi
+            raise

What errors do you expect here? I'm asking because catching exceptions indiscrimatingly feels problematic.

yeah, I think it's mostly KeyError or ValueError, I can restrict it, but at the same time, since we re-raise, I don't think it's problematic, it's a top-level function.

Quoted 7 lines
Quoted 7 lines
scripts/qapi2texi.py new file +7 -0
+
+    return '\n'.join(res)
+
+
+def parse_schema(fname):
+    """
+    Parse the given schema file and return the exprs
Quoted 10 lines

scripts/qapi2texi.py line 297

Quoted 6 lines
scripts/qapi2texi.py new file +6 -0
+    """
+    try:
+        schema = QAPISchemaParser(open(fname, "r"))
+        check_exprs(schema.exprs)
+        check_docs(schema.docs)
+        return schema.docs

You don't actually "return the exprs", you return a list of QAPIDoc.

Yeah, last iteration change,

Quoted 22 lines

Either return schema and let the caller retrieve its .docs, or rename the function to parse_docs(). In either case, fix up the doc string.

scripts/qapi2texi.py line 300

Quoted 3 lines
scripts/qapi2texi.py new file +3 -0
+    except (QAPISchemaError, QAPIExprError), err:
+        print >>sys.stderr, err
+        exit(1)

The function duplicates parts of QAPISchema.__init__(). The parts it doesn't duplicate would be useful here, because without them, you might be working on a broken schema.

Recommend to drop the function, and ...

scripts/qapi2texi.py line 308

Quoted 8 lines
scripts/qapi2texi.py new file +8 -0
+
+
+def main(argv):
+    """
+    Takes schema argument, prints result to stdout
+    """
+    if len(argv) != 2:
+        print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" %

argv[0]

Quoted 9 lines

scripts/qapi2texi.py line 311

Quoted 3 lines
scripts/qapi2texi.py new file +3 -0
+        sys.exit(1)
+
+    docs = parse_schema(argv[1])

... instead do

schema = QAPISchema(argv[1])
docs = schema.docs

done

Quoted 18 lines

with the obvious patch to make docs an attribute of schema:

scripts/qapi.py +3 -1
index ed52ee4..b17e7de 100644
@@ -1424,7 +1424,9 @@ class QAPISchemaEvent(QAPISchemaEntity):
 class QAPISchema(object):
     def __init__(self, fname):
         try:
-            self.exprs = check_exprs(QAPISchemaParser(open(fname,
 "r")).exprs)
+            parser = QAPISchemaParser(open(fname, "r"))
+            self.exprs = check_exprs(parser.exprs)
+            self.docs = parser.docs
             self._entity_dict = {}
             self._predefining = True
Quoted 3 lines

self._def_predefineds()

ok

Quoted 4 lines

You don't use the common parse_command_line(). Probably the right choice right now, as reusing it would require modifications (we have no use for -c and -h at least), and wouldn't buy us much.

Quoted 10 lines

scripts/qapi2texi.py line 316

Quoted 5 lines
scripts/qapi2texi.py new file +5 -0
+    print texi(docs)
+
+
+if __name__ == "__main__":
+    main(sys.argv)

Ignorant question: why is this __name__ == "__main__" raindance better than the stupid way the qapi-{commands,event,introspect,types,visit}.py work?

I have always used __name__ == "__main__", see:

http://stackoverflow.com/questions/419163/what-does-if-name-main-do

Quoted 29 lines

docs/qapi-code-gen.txt QAPI parser does not). At present, there is no

Quoted 6 lines
docs/qapi-code-gen.txt +0 -0
index 2841c51..d82e251 100644
@@ -45,16 +45,13 @@ QAPI parser does not).  At present, there is no

place where a QAPI

Quoted 22 lines
docs/qapi-code-gen.txt +7 -10
 schema requires the use of JSON numbers or null.
 
 Comments are allowed; anything between an unquoted # and the following
-newline is ignored.  Although there is not yet a documentation
-generator, a form of stylized comments has developed for consistently
-documenting details about an expression and when it was added to the
-schema.  The documentation is delimited between two lines of ##, then
-the first line names the expression, an optional overview is provided,
-then individual documentation about each member of 'data' is provided,
-and finally, a 'Since: x.y.z' tag lists the release that introduced
-the expression.  Optional members are tagged with the phrase
-'#optional', often with their default value; and extensions added
-after the expression was first released are also given a '(since
+newline is ignored.  The documentation is delimited between two lines
+of ##, then the first line names the expression, an optional overview
+is provided, then individual documentation about each member of 'data'
+is provided, and finally, a 'Since: x.y.z' tag lists the release that
+introduced the expression.  Optional members are tagged with the
+phrase '#optional', often with their default value; and extensions
+added after the expression was first released are also given a '(since
 x.y.z)' comment.  For example:
 
Quoted 18 lines
Quoted 4 lines
docs/qapi-code-gen.txt +0 -0
     ##
@@ -73,12 +70,39 @@ x.y.z)' comment.  For example:
     #           (Since 2.0)
     #

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 81

Quoted 10 lines
docs/qapi-code-gen.txt +9 -0
     # Since: 0.14.0
+    #
+    # Notes: You can also make a list:
+    #        - with items
+    #        - like this
+    #
+    # Example:
+    #
+    # -> { "execute": ... }
+    # <- { "return": ... }

Err, 'BlockStats' is a *type*, not a command.

It could be returned/used in an example, it fits also this example.

Quoted 19 lines
Quoted 19 lines
docs/qapi-code-gen.txt +13 -0
+    #
     ##
     { 'struct': 'BlockStats',
       'data': {'*device': 'str', 'stats': 'BlockDeviceStats',
                '*parent': 'BlockStats',
                '*backing': 'BlockStats'} }
 
+It's also possible to create documentation sections, such as:
+
+    ##
+    # = Section
+    # == Subsection
+    #
+    # Some text foo with *emphasis*
+    # 1. with a list
+    # 2. like that
+    #
+    # And some code:
+    # | $ echo foo
Quoted 10 lines

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 105

Quoted 5 lines
docs/qapi-code-gen.txt +5 -0
+    # | -> do this
+    # | <- get that
+    #
+    ##
+

This suggests various kinds of markup, including section headers, emphasis, numbered lists. But what exactly is recognized?

Ok updated

Quoted 8 lines

docs/qapi-code-gen.txt x.y.z)' comment. For example: · line 108

Quoted 3 lines
docs/qapi-code-gen.txt +0 -0
 The schema sets up a series of types, as well as commands and events
 that will use those types.  Forward references are allowed: the parser
 scans in two passes, where the first pass learns all type names, and

As discussed in my review of the cover letter, we have some additional documentation work to do.

sure, but it's already 175 patches to review ;)

Quoted 10 lines

Also missing: tests. A first cut should have a negative test for each error qapi2texi.py can report, plus a modest suite of positive tests. A negative test consists of tests/qapi-schema/NAME.{json,out,err,exit}. Positive tests can be added to tests/qapi-schema/qapi-schema-test.json, or to a separate test schema, in case that's more convenient.

To get the most mileage out of positive tests, test-qapi.py should be extended to show the resulting QAPIDoc. Sketch appended.

Thanks a lot for the feedback, I have done many changes based on it.

I'll work on adding some tests and send the new version, hopefully this week.

If you have further comments based on this reply, I'll try to take them as well with the next iteration.

Quoted 11 lines
tests/qapi-schema/test-qapi.py +2 -0
index ef74e2c..93cc709 100644
@@ -55,3 +55,13 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
 
 schema = QAPISchema(sys.argv[1])
 schema.visit(QAPISchemaTestVisitor())
+
+for doc in schema.docs:

tests/qapi-schema/test-qapi.py class QAPISchemaTestVisitor(QAPISchemaVisitor):

Quoted 10 lines
tests/qapi-schema/test-qapi.py +8 -1
+    expr_elem = doc.expr_elem
+    expr_info = expr_elem and expr_elem['info']
+    print 'doc %s %s' % (doc.symbol, expr_info)
+    for arg, text in doc.args.iteritems():
+        print '    arg=%s %s' % (arg, text)
+    for key, text in doc.meta:
+        print '    meta %s %s' % (key, text)
+    print '    body=%s' % doc.body
 
--

Marc-André Lureau

#25 lore raw

PATCH v3 12/14 texi2pod: learn quotation, deftp and deftypefn

In reply to Marc-André Lureau

Learn a few more markups used for API documentation.

---
 scripts/texi2pod.pl | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
scripts/texi2pod.pl +43 -1
index 8767662..5df4b5f 100755
@@ -37,6 +37,7 @@ $inf = "";
 $ibase = "";
 @ipath = ();
 $encoding = undef;
+@args = ();
 
 while ($_ = shift) {
     if (/^-D(.*)$/) {
@@ -162,7 +163,8 @@ while(<$inf>) {
 	if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
 	    $skipping = pop @skstack;
 	    next;
-	} elsif ($ended =~ /^(?:example|smallexample|display)$/) {
+	} elsif ($ended =~ /^(?:example|smallexample|display
+                            |quotation|deftp|deftypefn)$/x) {
 	    $shift = "";
 	    $_ = "";	# need a paragraph break
 	} elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
@@ -323,6 +325,46 @@ while(<$inf>) {
 	$_ = "\n=item ".join (" : ", @columns)."\n";
     };
 
+    /^\@(quotation)\s*(.+)?$/ and do {
+        push @endwstack, $endw;
+        $endw = $1;
+        $_ = "\n$2:"
+    };
+
+    /^{(.*)}$|^(.*)$/ and $#args > 0 and do {
+        $kind = $args[0];
+        $arguments = $1 // "";
+        if ($endw eq "deftypefn") {
+            $ret = $args[1];
+            $fname = "B<$args[2]>";
+            $_ = $ret ? "$ret " : "";
+            $_ .= "$fname $arguments ($kind)";
+        } else {
+            $_ = "B<$args[1]> ($kind)\n\n$arguments";
+        }
+        @args = ();
+    };
+
+    /^\@(deftp)\s*(.+)?$/ and do {
+        push @endwstack, $endw;
+        $endw = $1;
+        $arg = $2;
+        $arg =~ s/{([^}]*)}/$1/g;
+        $arg =~ s/\@$//;
+        @args = split (/ /, $arg);
+        $_ = "";
+    };
+
+    /^\@(deftypefn)\s*(.+)?$/ and do {
+        push @endwstack, $endw;
+        $endw = $1;
+        $arg = $2;
+        $arg =~ s/{([^}]*)}/$1/g;
+        $arg =~ s/\@$//;
+        @args = split (/ /, $arg);
+        $_ = "";
+    };
+
     /^\@itemx?\s*(.+)?$/ and do {
 	if (defined $1) {
 	    # Entity escapes prevent munging by the <> processing below.
Signature · 1 line
2.10.0
#26 lore raw

PATCH v3 13/14 qmp-commands: (SQUASHED) move doc to schema

In reply to Marc-André Lureau
---
 Makefile              |    1 -
 docs/qmp-commands.txt | 3824 -------------------------------------------------
 docs/qmp-events.txt   |  731 ----------
 qapi-schema.json      | 1279 ++++++++++++++++-
 qapi/block-core.json  |  679 ++++++++-
 qapi/block.json       |   56 +-
 qapi/common.json      |   32 +
 qapi/event.json       |  240 ++++
 qapi/rocker.json      |   57 +-
 qapi/trace.json       |   14 +
 10 files changed, 2309 insertions(+), 4604 deletions(-)
 delete mode 100644 docs/qmp-commands.txt
 delete mode 100644 docs/qmp-events.txt
Makefile +0 -1
index 474cc5e..3617736 100644
@@ -431,7 +431,6 @@ endif
 install-doc: $(DOCS)
 	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
 	$(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)"
-	$(INSTALL_DATA) $(SRC_PATH)/docs/qmp-commands.txt "$(DESTDIR)$(qemu_docdir)"
 ifdef CONFIG_POSIX
 	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
 	$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
docs/qmp-commands.txt deleted +0 -3824

2,993 lines not on this page · raw message

docs/qmp-events.txt deleted +0 -731

731 lines not on this page · raw message

qapi-schema.json +1254 -25

1,279 lines not on this page · raw message

qapi/block-core.json +664 -15

679 lines not on this page · raw message

qapi/block.json +52 -4

56 lines not on this page · raw message

qapi/common.json +32 -0
index d93f159..b626647 100644

Lines of this file are not shown. View the raw message.

qapi/event.json +240 -0

240 lines not on this page · raw message

qapi/rocker.json +53 -4

57 lines not on this page · raw message

qapi/trace.json +14 -0
index 3ad7df7..2bfda7a 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.10.0

Part of the diff is not shown here. View the raw message.

#27 lore raw

PATCH v3 14/14 build-sys: add qapi doc generation targets

In reply to Marc-André Lureau

Generate and install the man and html version of QAPI documentation.

Add it also to optional pdf/dvi/info targets.

Also support plain-text targets docs/qemu-ga-ref.txt & docs/qemu-qmp-ref.txt.

---
 Makefile   | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 .gitignore | 11 ++++++++++-
 2 files changed, 59 insertions(+), 8 deletions(-)
Makefile +49 -7
index 3617736..cc1c46e 100644
@@ -91,6 +91,8 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
 ifdef BUILD_DOCS
 DOCS=qemu-doc.html qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8
+DOCS+=docs/qemu-qmp-ref.html docs/qemu-qmp-ref.7
+DOCS+=docs/qemu-ga-ref.html docs/qemu-ga-ref.7
 ifdef CONFIG_VIRTFS
 DOCS+=fsdev/virtfs-proxy-helper.1
 endif
@@ -266,6 +268,7 @@ qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
 gen-out-type = $(subst .,-,$(suffix $@))
 
 qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
+qapi-py += $(SRC_PATH)/scripts/qapi2texi.py
 
 qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\
 $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
@@ -395,6 +398,11 @@ distclean: clean
 	rm -f qemu-doc.vr
 	rm -f config.log
 	rm -f linux-headers/asm
+	rm -f qemu-ga-qapi.texi qemu-qapi.texi
+	rm -f docs/qemu-qmp-ref.7 docs/qemu-ga-ref.7
+	rm -f docs/qemu-qmp-ref.txt docs/qemu-ga-ref.txt
+	rm -f docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
+	rm -f docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
 	for d in $(TARGET_DIRS); do \
 	rm -rf $$d || exit 1 ; \
         done
@@ -431,9 +439,12 @@ endif
 install-doc: $(DOCS)
 	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
 	$(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)"
+	$(INSTALL_DATA) docs/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)"
 ifdef CONFIG_POSIX
 	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1"
 	$(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
+	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
+	$(INSTALL_DATA) docs/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
 ifneq ($(TOOLS),)
 	$(INSTALL_DATA) qemu-img.1 "$(DESTDIR)$(mandir)/man1"
 	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
@@ -441,6 +452,8 @@ ifneq ($(TOOLS),)
 endif
 ifneq (,$(findstring qemu-ga,$(TOOLS)))
 	$(INSTALL_DATA) qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
+	$(INSTALL_DATA) docs/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)"
+	$(INSTALL_DATA) docs/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
 endif
 endif
 ifdef CONFIG_VIRTFS
@@ -528,9 +541,9 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \
 	ui/shader/texture-blit-vert.h ui/shader/texture-blit-frag.h
 
 # documentation
-MAKEINFO=makeinfo
+MAKEINFO=makeinfo -D 'VERSION $(VERSION)'
 MAKEINFOFLAGS=--no-headers --no-split --number-sections
-TEXIFLAG=$(if $(V),,--quiet)
+TEXIFLAG=$(if $(V),,--quiet) --command='@set VERSION $(VERSION)'
 %.dvi: %.texi
 	$(call quiet-command,texi2dvi $(TEXIFLAG) -I . $<,"GEN","$@")
 
@@ -542,7 +555,11 @@ TEXIFLAG=$(if $(V),,--quiet)
 	$(call quiet-command,$(MAKEINFO) $< -o $@,"GEN","$@")
 
 %.pdf: %.texi
-	$(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<,"GEN","$@")
+	$(call quiet-command,texi2pdf $(TEXIFLAG) -I . $< -o $@,"GEN","$@")
+
+%.txt: %.texi
+	$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --plaintext $< -o $@,\
+	"  GEN   $@")
 
 qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
@@ -556,6 +573,12 @@ qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxt
 qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
 
+qemu-qapi.texi: $(qapi-modules) $(qapi-py)
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN" "$@")
+
+qemu-ga-qapi.texi: $(SRC_PATH)/qga/qapi-schema.json $(qapi-py)
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
+
 qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
 	$(call quiet-command, \
 	  perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu.pod && \
@@ -587,16 +610,35 @@ qemu-ga.8: qemu-ga.texi
 	  $(POD2MAN) --section=8 --center=" " --release=" " qemu-ga.pod > $@, \
 	  "GEN","$@")
 
-dvi: qemu-doc.dvi
-html: qemu-doc.html
-info: qemu-doc.info
-pdf: qemu-doc.pdf
+docs/qemu-qmp-ref.7:
+	$(call quiet-command, \
+	 perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-qmp-ref.pod && \
+	 $(POD2MAN) --section=7 --center=" " --release=" " qemu-qmp-ref.pod > $@, \
+	 "GEN","$@")
+
+docs/qemu-ga-ref.7:
+	$(call quiet-command, \
+	 perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-ga-ref.pod && \
+	 $(POD2MAN) --section=7 --center=" " --release=" " qemu-ga-ref.pod > $@, \
+	 "GEN","$@")
+
+dvi: qemu-doc.dvi docs/qemu-qmp-ref.dvi docs/qemu-ga-ref.dvi
+html: qemu-doc.html docs/qemu-qmp-ref.html docs/qemu-ga-ref.html
+info: qemu-doc.info docs/qemu-qmp-ref.info docs/qemu-ga-ref.info
+pdf: qemu-doc.pdf docs/qemu-qmp-ref.pdf docs/qemu-ga-ref.pdf
 
 qemu-doc.dvi qemu-doc.html qemu-doc.info qemu-doc.pdf: \
 	qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \
 	qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \
 	qemu-monitor-info.texi
 
+docs/qemu-ga-ref.dvi docs/qemu-ga-ref.html docs/qemu-ga-ref.info docs/qemu-ga-ref.pdf docs/qemu-ga-ref.txt docs/qemu-ga-ref.7: \
+docs/qemu-ga-ref.texi qemu-ga-qapi.texi
+
+docs/qemu-qmp-ref.dvi docs/qemu-qmp-ref.html docs/qemu-qmp-ref.info docs/qemu-qmp-ref.pdf docs/qemu-qmp-ref.txt docs/qemu-qmp-ref.7: \
+docs/qemu-qmp-ref.texi qemu-qapi.texi
+
+
 ifdef CONFIG_WIN32
 
 INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
.gitignore +10 -1
index 3d7848c..d0905c3 100644
@@ -39,7 +39,7 @@
 /qmp-introspect.[ch]
 /qmp-marshal.c
 /qemu-doc.html
-/qemu-doc.info
+/qemu-doc.info*
 /qemu-img
 /qemu-nbd
 /qemu-options.def
@@ -109,6 +109,15 @@
 /pc-bios/optionrom/kvmvapic.img
 /pc-bios/s390-ccw/s390-ccw.elf
 /pc-bios/s390-ccw/s390-ccw.img
+/docs/qemu-ga-ref.html
+/docs/qemu-ga-ref.txt
+/docs/qemu-qmp-ref.html
+/docs/qemu-qmp-ref.txt
+docs/qemu-ga-ref.info*
+docs/qemu-qmp-ref.info*
+/qemu-ga-qapi.texi
+/qemu-qapi.texi
+*.tps
 .stgit-*
 cscope.*
 tags
Signature · 1 line
2.10.0