diff mbox

[for-2.9,27/47] qapi2texi: Generate documentation for variant members

Message ID 1489385927-6735-28-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster March 13, 2017, 6:18 a.m. UTC
A flat union's branch brings in the members of another type.  Generate
a suitable reference to that type.

Example change (qemu-qmp-ref.txt):

  -- Flat Union: QCryptoBlockOpenOptions

      The options that are available for all encryption formats when
      opening an existing volume

      Members:
      The members of 'QCryptoBlockOptionsBase'
+     The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow"
+     The members of 'QCryptoBlockOptionsLUKS' when 'format' is "luks"

      Since: 2.6

A simple union's branch adds a member 'data' of some other type.
Generate documentation for that member.

Example change (qemu-qmp-ref.txt):

  -- Simple Union: SocketAddress

      Captures the address of a socket, which could also be a named file
      descriptor

      Members:
      'type'
	   Not documented
+     'data: InetSocketAddress' when 'type' is "inet"
+     'data: UnixSocketAddress' when 'type' is "unix"
+     'data: VsockSocketAddress' when 'type' is "vsock"
+     'data: String' when 'type' is "fd"

      Since: 1.3

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi2texi.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

Comments

Eric Blake March 14, 2017, 7:36 p.m. UTC | #1
On 03/13/2017 01:18 AM, Markus Armbruster wrote:
> A flat union's branch brings in the members of another type.  Generate
> a suitable reference to that type.
> 
> Example change (qemu-qmp-ref.txt):
> 
>   -- Flat Union: QCryptoBlockOpenOptions
> 
>       The options that are available for all encryption formats when
>       opening an existing volume
> 
>       Members:
>       The members of 'QCryptoBlockOptionsBase'
> +     The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow"

Relies on the implied knowledge that 'format' is a member of
'QCryptoBlockOptionsBase'. Does that mean references to another type
might usefully want to do a list of member names, to avoid having to
follow the hyperlink, while still leaving the hyperlink when searching
for full details on that member?  As in:

Members:
The members of 'QCryptoBlockOptionsBase' ('format')
The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow"
('key-secret')

But it could get noisy (the example here only adds one member; other
unions add lots of members), and I'm also okay if you don't like the
idea or would rather do it as a followup.

> +     The members of 'QCryptoBlockOptionsLUKS' when 'format' is "luks"
> 
>       Since: 2.6
> 
> A simple union's branch adds a member 'data' of some other type.
> Generate documentation for that member.
> 
> Example change (qemu-qmp-ref.txt):
> 
>   -- Simple Union: SocketAddress
> 
>       Captures the address of a socket, which could also be a named file
>       descriptor
> 
>       Members:
>       'type'
> 	   Not documented
> +     'data: InetSocketAddress' when 'type' is "inet"
> +     'data: UnixSocketAddress' when 'type' is "unix"
> +     'data: VsockSocketAddress' when 'type' is "vsock"
> +     'data: String' when 'type' is "fd"

Looks reasonable.

> 
>       Since: 1.3
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  scripts/qapi2texi.py | 27 ++++++++++++++++++++-------
>  1 file changed, 20 insertions(+), 7 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Markus Armbruster March 15, 2017, 7:36 a.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> On 03/13/2017 01:18 AM, Markus Armbruster wrote:
>> A flat union's branch brings in the members of another type.  Generate
>> a suitable reference to that type.
>> 
>> Example change (qemu-qmp-ref.txt):
>> 
>>   -- Flat Union: QCryptoBlockOpenOptions
>> 
>>       The options that are available for all encryption formats when
>>       opening an existing volume
>> 
>>       Members:
>>       The members of 'QCryptoBlockOptionsBase'
>> +     The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow"
>
> Relies on the implied knowledge that 'format' is a member of
> 'QCryptoBlockOptionsBase'. Does that mean references to another type
> might usefully want to do a list of member names, to avoid having to
> follow the hyperlink, while still leaving the hyperlink when searching

Apropos link: 'format' in 'format is "qcow" could be made one.

> for full details on that member?  As in:
>
> Members:
> The members of 'QCryptoBlockOptionsBase' ('format')
> The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow"
> ('key-secret')
>
> But it could get noisy (the example here only adds one member; other
> unions add lots of members), and I'm also okay if you don't like the
> idea or would rather do it as a followup.

I figure more than a few members would be too noisy.  Which ones to omit
then?  I'm open to ideas, but it needs to be done as a follow-up, to
give us a chance to fix the QMP documentation regression in time for
2.9.

>> +     The members of 'QCryptoBlockOptionsLUKS' when 'format' is "luks"
>> 
>>       Since: 2.6
>> 
>> A simple union's branch adds a member 'data' of some other type.
>> Generate documentation for that member.
>> 
>> Example change (qemu-qmp-ref.txt):
>> 
>>   -- Simple Union: SocketAddress
>> 
>>       Captures the address of a socket, which could also be a named file
>>       descriptor
>> 
>>       Members:
>>       'type'
>> 	   Not documented
>> +     'data: InetSocketAddress' when 'type' is "inet"
>> +     'data: UnixSocketAddress' when 'type' is "unix"
>> +     'data: VsockSocketAddress' when 'type' is "vsock"
>> +     'data: String' when 'type' is "fd"
>
> Looks reasonable.
>
>> 
>>       Since: 1.3
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  scripts/qapi2texi.py | 27 ++++++++++++++++++++-------
>>  1 file changed, 20 insertions(+), 7 deletions(-)
>> 
>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!
diff mbox

Patch

diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py
index 7083d0c..ab6b6cd 100755
--- a/scripts/qapi2texi.py
+++ b/scripts/qapi2texi.py
@@ -133,17 +133,18 @@  def texi_enum_value(value):
     return '@item @code{%s}\n' % value.name
 
 
-def texi_member(member):
+def texi_member(member, suffix=''):
     """Format a table of members item for an object type member"""
     typ = member.type.doc_type()
-    return '@item @code{%s%s%s}%s\n' % (
+    return '@item @code{%s%s%s}%s%s\n' % (
         member.name,
         ': ' if typ else '',
         typ if typ else '',
-        ' (optional)' if member.optional else '')
+        ' (optional)' if member.optional else '',
+        suffix)
 
 
-def texi_members(doc, what, base, member_func):
+def texi_members(doc, what, base, variants, member_func):
     """Format the table of members"""
     items = ''
     for section in doc.args.itervalues():
@@ -154,6 +155,17 @@  def texi_members(doc, what, base, member_func):
         items += member_func(section.member) + texi_format(desc) + '\n'
     if base:
         items += '@item The members of @code{%s}\n' % base.doc_type()
+    if variants:
+        for v in variants.variants:
+            when = ' when @code{%s} is @t{"%s"}' % (
+                variants.tag_member.name, v.name)
+            if v.type.is_implicit():
+                assert not v.type.base and not v.type.variants
+                for m in v.type.local_members:
+                    items += member_func(m, when)
+            else:
+                items += '@item The members of @code{%s}%s\n' % (
+                    v.type.doc_type(), when)
     if not items:
         return ''
     return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items)
@@ -176,9 +188,10 @@  def texi_sections(doc):
     return body
 
 
-def texi_entity(doc, what, base=None, member_func=texi_member):
+def texi_entity(doc, what, base=None, variants=None,
+                member_func=texi_member):
     return (texi_body(doc)
-            + texi_members(doc, what, base, member_func)
+            + texi_members(doc, what, base, variants, member_func)
             + texi_sections(doc))
 
 
@@ -213,7 +226,7 @@  class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor):
             self.out += '\n'
         self.out += TYPE_FMT(type=typ,
                              name=doc.symbol,
-                             body=texi_entity(doc, 'Members', base))
+                             body=texi_entity(doc, 'Members', base, variants))
 
     def visit_alternate_type(self, name, info, variants):
         doc = self.cur_doc