All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, eblake@redhat.com,
	mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH for-2.9 02/47] qapi: Make doc comments optional where we don't need them
Date: Mon, 13 Mar 2017 07:18:02 +0100	[thread overview]
Message-ID: <1489385927-6735-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1489385927-6735-1-git-send-email-armbru@redhat.com>

Since we added the documentation generator in commit 3313b61, doc
comments are mandatory.  That's a very good idea for a schema that
needs to be documented, but has proven to be annoying for testing.

Make doc comments optional again, but add a new directive

    { 'pragma': { 'doc-required': true } }

to let a QAPI schema require them.

Require documentation in the schemas we actually want documented:
qapi-schema.json and qga/qapi-schema.json.

We could probably make qapi2texi.py cope with incomplete
documentation, but for now, simply make it refuse to run unless the
schema has 'doc-required': true.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 docs/qapi-code-gen.txt             | 40 +++++++++++++++++++++++++-------------
 qapi-schema.json                   |  2 ++
 qga/qapi-schema.json               |  2 ++
 scripts/qapi.py                    | 20 ++++++++++++++++++-
 scripts/qapi2texi.py               |  3 +++
 tests/Makefile.include             |  1 +
 tests/qapi-schema/doc-missing.err  |  1 +
 tests/qapi-schema/doc-missing.exit |  1 +
 tests/qapi-schema/doc-missing.json |  5 +++++
 tests/qapi-schema/doc-missing.out  |  0
 10 files changed, 61 insertions(+), 14 deletions(-)
 create mode 100644 tests/qapi-schema/doc-missing.err
 create mode 100644 tests/qapi-schema/doc-missing.exit
 create mode 100644 tests/qapi-schema/doc-missing.json
 create mode 100644 tests/qapi-schema/doc-missing.out

diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 9514d93..88de5c7 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -117,10 +117,13 @@ Example:
 
 ==== Expression documentation ====
 
-Each expression that isn't an include directive must be preceded by a
+Each expression that isn't an include directive may be preceded by a
 documentation block.  Such blocks are called expression documentation
 blocks.
 
+When documentation is required (see pragma 'doc-required'), expression
+documentation blocks are mandatory.
+
 The documentation block consists of a first line naming the
 expression, an optional overview, a description of each argument (for
 commands and events) or member (for structs, unions and alternates),
@@ -204,17 +207,17 @@ once.  It is permissible for the schema to contain additional types
 not used by any commands or events in the Client JSON Protocol, for
 the side effect of generated C code used internally.
 
-There are seven top-level expressions recognized by the parser:
-'include', 'command', 'struct', 'enum', 'union', 'alternate', and
-'event'.  There are several groups of types: simple types (a number of
-built-in types, such as 'int' and 'str'; as well as enumerations),
-complex types (structs and two flavors of unions), and alternate types
-(a choice between other types).  The 'command' and 'event' expressions
-can refer to existing types by name, or list an anonymous type as a
-dictionary. Listing a type name inside an array refers to a
-single-dimension array of that type; multi-dimension arrays are not
-directly supported (although an array of a complex struct that
-contains an array member is possible).
+There are eight top-level expressions recognized by the parser:
+'include', 'pragma', 'command', 'struct', 'enum', 'union',
+'alternate', and 'event'.  There are several groups of types: simple
+types (a number of built-in types, such as 'int' and 'str'; as well as
+enumerations), complex types (structs and two flavors of unions), and
+alternate types (a choice between other types).  The 'command' and
+'event' expressions can refer to existing types by name, or list an
+anonymous type as a dictionary. Listing a type name inside an array
+refers to a single-dimension array of that type; multi-dimension
+arrays are not directly supported (although an array of a complex
+struct that contains an array member is possible).
 
 All names must begin with a letter, and contain only ASCII letters,
 digits, hyphen, and underscore.  There are two exceptions: enum values
@@ -282,7 +285,7 @@ The following types are predefined, and map to C as follows:
   QType     QType      JSON string matching enum QType values
 
 
-=== Includes ===
+=== Include directives ===
 
 Usage: { 'include': STRING }
 
@@ -302,6 +305,17 @@ an outer file.  The parser may be made stricter in the future to
 prevent incomplete include files.
 
 
+=== Pragma directives ===
+
+Usage: { 'pragma': DICT }
+
+The pragma directive lets you control optional generator behavior.
+The dictionary's entries are pragma names and values.
+
+Pragma 'doc-required' takes a boolean value.  If true, documentation
+is required.  Default is false.
+
+
 === Struct types ===
 
 Usage: { 'struct': STRING, 'data': DICT, '*base': STRUCT-NAME }
diff --git a/qapi-schema.json b/qapi-schema.json
index 32b4a4b..d5438ee 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -49,6 +49,8 @@
 #
 ##
 
+{ 'pragma': { 'doc-required': true } }
+
 # QAPI common definitions
 { 'include': 'qapi/common.json' }
 
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index d421609..3f3d428 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -11,6 +11,8 @@
 #
 ##
 
+{ 'pragma': { 'doc-required': true } }
+
 ##
 # @guest-sync-delimited:
 #
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 345cde1..29a8b77 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -37,6 +37,9 @@ builtin_types = {
     'QType':    'QTYPE_QSTRING',
 }
 
+# Are documentation comments required?
+doc_required = False
+
 # Whitelist of commands allowed to return a non-dictionary
 returns_whitelist = [
     # From QMP:
@@ -277,6 +280,11 @@ class QAPISchemaParser(object):
                                        "Value of 'include' must be a string")
                 self._include(include, info, os.path.dirname(abs_fname),
                               previously_included)
+            elif "pragma" in expr:
+                if len(expr) != 1:
+                    raise QAPISemError(info, "Invalid 'pragma' directive")
+                for name, value in expr['pragma'].iteritems():
+                    self._pragma(name, value, info)
             else:
                 expr_elem = {'expr': expr,
                              'info': info}
@@ -308,6 +316,16 @@ class QAPISchemaParser(object):
         self.exprs.extend(exprs_include.exprs)
         self.docs.extend(exprs_include.docs)
 
+    def _pragma(self, name, value, info):
+        global doc_required
+        if name == 'doc-required':
+            if not isinstance(value, bool):
+                raise QAPISemError(info,
+                                   "Pragma 'doc-required' must be boolean")
+            doc_required = value
+        else:
+            raise QAPISemError(info, "Unknown pragma '%s'" % name)
+
     def accept(self, skip_comment=True):
         while True:
             self.tok = self.src[self.cursor]
@@ -863,7 +881,7 @@ def check_exprs(exprs):
         expr = expr_elem['expr']
         info = expr_elem['info']
 
-        if 'doc' not in expr_elem:
+        if 'doc' not in expr_elem and doc_required:
             raise QAPISemError(info,
                                "Expression missing documentation comment")
 
diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py
index 69f5edc..06d6abf 100755
--- a/scripts/qapi2texi.py
+++ b/scripts/qapi2texi.py
@@ -254,6 +254,9 @@ def main(argv):
         sys.exit(1)
 
     schema = qapi.QAPISchema(argv[1])
+    if not qapi.doc_required:
+        print >>sys.stderr, ("%s: need pragma 'doc-required' "
+                             "to generate documentation" % argv[0])
     print texi(schema.docs)
 
 
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 346345e..736dd15 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -381,6 +381,7 @@ qapi-schema += doc-invalid-end2.json
 qapi-schema += doc-invalid-return.json
 qapi-schema += doc-invalid-section.json
 qapi-schema += doc-invalid-start.json
+qapi-schema += doc-missing.json
 qapi-schema += doc-missing-colon.json
 qapi-schema += doc-missing-expr.json
 qapi-schema += doc-missing-space.json
diff --git a/tests/qapi-schema/doc-missing.err b/tests/qapi-schema/doc-missing.err
new file mode 100644
index 0000000..7f2f326
--- /dev/null
+++ b/tests/qapi-schema/doc-missing.err
@@ -0,0 +1 @@
+tests/qapi-schema/doc-missing.json:5: Expression missing documentation comment
diff --git a/tests/qapi-schema/doc-missing.exit b/tests/qapi-schema/doc-missing.exit
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/tests/qapi-schema/doc-missing.exit
@@ -0,0 +1 @@
+1
diff --git a/tests/qapi-schema/doc-missing.json b/tests/qapi-schema/doc-missing.json
new file mode 100644
index 0000000..5956709
--- /dev/null
+++ b/tests/qapi-schema/doc-missing.json
@@ -0,0 +1,5 @@
+# Expression documentation required
+
+{ 'pragma': { 'doc-required': true } }
+
+{ 'command': 'undocumented' }
diff --git a/tests/qapi-schema/doc-missing.out b/tests/qapi-schema/doc-missing.out
new file mode 100644
index 0000000..e69de29
-- 
2.7.4

  parent reply	other threads:[~2017-03-13  6:18 UTC|newest]

Thread overview: 137+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13  6:18 [Qemu-devel] [PATCH for-2.9 00/47] qapi: Put type information back into QMP documentation Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 01/47] qapi: Factor QAPISchemaParser._include() out of .__init__() Markus Armbruster
2017-03-13 19:34   ` Eric Blake
2017-03-14  8:28   ` Marc-André Lureau
2017-03-13  6:18 ` Markus Armbruster [this message]
2017-03-13 21:00   ` [Qemu-devel] [PATCH for-2.9 02/47] qapi: Make doc comments optional where we don't need them Eric Blake
2017-03-14  7:21     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 03/47] qapi: Back out doc comments added just to please qapi.py Markus Armbruster
2017-03-13 21:13   ` Eric Blake
2017-03-14  7:26     ` Markus Armbruster
2017-03-14  8:28   ` Marc-André Lureau
2017-03-14  9:45     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 04/47] docs/qapi-code-gen.txt: Drop confusing reference to 'gen' Markus Armbruster
2017-03-13 22:17   ` Eric Blake
2017-03-14  8:30   ` Marc-André Lureau
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 05/47] qapi: Have each QAPI schema declare its returns white-list Markus Armbruster
2017-03-13 22:41   ` Eric Blake
2017-03-14  7:40     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 06/47] qapi: Have each QAPI schema declare its name rule violations Markus Armbruster
2017-03-13 22:46   ` Eric Blake
2017-03-14  7:51     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 07/47] qapi: Clean up build of generated documentation Markus Armbruster
2017-03-14 15:55   ` Eric Blake
2017-03-15  7:08     ` Markus Armbruster
2017-03-15 11:53       ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 08/47] tests/qapi-schema: Cover empty union base Markus Armbruster
2017-03-14  8:41   ` Marc-André Lureau
2017-03-14 15:56   ` Eric Blake
2017-03-15  7:11     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 09/47] qapi: Fix to reject empty union base gracefully Markus Armbruster
2017-03-14  8:40   ` Marc-André Lureau
2017-03-14 15:58   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 10/47] qapi2texi: Fix up output around #optional Markus Armbruster
2017-03-14  8:37   ` Marc-André Lureau
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 11/47] qapi: Avoid unwanted blank lines in QAPIDoc Markus Armbruster
2017-03-14  8:46   ` Marc-André Lureau
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 12/47] qapi/rocker: Fix up doc comment notes on optional members Markus Armbruster
2017-03-14  8:49   ` Marc-André Lureau
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 13/47] qapi: Fix QAPISchemaEnumType.is_implicit() for 'QType' Markus Armbruster
2017-03-14 16:03   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 14/47] qapi: Prepare for requiring more complete documentation Markus Armbruster
2017-03-14 16:08   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 15/47] qapi: Conjure up QAPIDoc.ArgSection for undocumented members Markus Armbruster
2017-03-14 17:16   ` Eric Blake
2017-03-15  7:12     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 16/47] qapi2texi: Convert to QAPISchemaVisitor Markus Armbruster
2017-03-14 17:31   ` Eric Blake
2017-03-15  7:14     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 17/47] qapi: The #optional tag is redundant, drop Markus Armbruster
2017-03-14 17:59   ` Eric Blake
2017-03-15  7:22     ` Markus Armbruster
2017-03-14 20:14   ` Eric Blake
2017-03-15  7:15     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 18/47] qapi: Use raw strings for regular expressions consistently Markus Armbruster
2017-03-14 18:00   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 19/47] qapi: Prefer single-quoted strings more consistently Markus Armbruster
2017-03-14 18:05   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 20/47] qapi2texi: Plainer enum value and member name formatting Markus Armbruster
2017-03-14 18:06   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 21/47] qapi2texi: Present the table of members more clearly Markus Armbruster
2017-03-14 18:08   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 22/47] qapi2texi: Explain enum value undocumentedness " Markus Armbruster
2017-03-14 19:00   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 23/47] qapi2texi: Don't hide undocumented members and arguments Markus Armbruster
2017-03-14 19:02   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 24/47] qapi2texi: Implement boxed argument documentation Markus Armbruster
2017-03-14 19:12   ` Eric Blake
2017-03-15  7:23     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 25/47] qapi2texi: Include member type in generated documentation Markus Armbruster
2017-03-14 12:42   ` Marc-André Lureau
2017-03-14 15:16     ` Markus Armbruster
2017-03-14 19:16   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 26/47] qapi2texi: Generate reference to base type members Markus Armbruster
2017-03-14 19:29   ` Eric Blake
2017-03-15  7:30     ` Markus Armbruster
2017-03-15 12:13       ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 27/47] qapi2texi: Generate documentation for variant members Markus Armbruster
2017-03-14 19:36   ` Eric Blake
2017-03-15  7:36     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 28/47] qapi2texi: Generate descriptions for simple union tags Markus Armbruster
2017-03-14 19:54   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 29/47] qapi2texi: Use category "Object" for all object types Markus Armbruster
2017-03-14 19:56   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 30/47] tests/qapi-schema: Improve doc / expression mismatch coverage Markus Armbruster
2017-03-14 20:02   ` Eric Blake
2017-03-14 20:36   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 31/47] qapi: Fix detection of doc / expression mismatch Markus Armbruster
2017-03-14 20:35   ` Eric Blake
2017-03-15  7:39     ` Markus Armbruster
2017-03-15 12:14       ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 32/47] qapi: Move detection of doc / expression name mismatch Markus Armbruster
2017-03-14 20:43   ` Eric Blake
2017-03-15  7:39     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 33/47] qapi: Improve error message on @NAME: in free-form doc Markus Armbruster
2017-03-14 20:46   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 34/47] qapi: Move empty doc section checking to doc parser Markus Armbruster
2017-03-13  6:23   ` Markus Armbruster
2017-03-15  1:40     ` Eric Blake
2017-03-15  7:44       ` Markus Armbruster
2017-03-15  1:37   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 35/47] tests/qapi-schema: Rename doc-bad-args to doc-bad-command-arg Markus Armbruster
2017-03-14 20:47   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 36/47] tests/qapi-schema: Improve coverage of bogus member docs Markus Armbruster
2017-03-14 20:55   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 37/47] qapi: Fix detection of bogus member documentation Markus Armbruster
2017-03-14 20:58   ` Eric Blake
2017-03-15  7:46     ` Markus Armbruster
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 38/47] qapi: Eliminate check_docs() and drop QAPIDoc.expr Markus Armbruster
2017-03-14 21:00   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 39/47] qapi: Drop unused variable events Markus Armbruster
2017-03-14 21:02   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 40/47] qapi: Simplify what gets stored in enum_types Markus Armbruster
2017-03-15  0:34   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 41/47] qapi: Factor add_name() calls out of the meta conditional Markus Armbruster
2017-03-15  0:39   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 42/47] qapi: enum_types is a list used like a dict, make it one Markus Armbruster
2017-03-15  0:47   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 43/47] qapi: struct_types " Markus Armbruster
2017-03-15  1:31   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 44/47] qapi: union_types " Markus Armbruster
2017-03-15  1:34   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 45/47] qapi: Drop unused .check_clash() parameter schema Markus Armbruster
2017-03-15  1:46   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 46/47] qapi: Make pylint a bit happier Markus Armbruster
2017-03-15  1:47   ` Eric Blake
2017-03-13  6:18 ` [Qemu-devel] [PATCH for-2.9 47/47] qapi: Fix a misleading parser error message Markus Armbruster
2017-03-15  1:48   ` Eric Blake
2017-03-13 10:32 ` [Qemu-devel] [PATCH for-2.9 00/47] qapi: Put type information back into QMP documentation Marc-André Lureau
2017-03-13 12:14   ` Markus Armbruster
2017-03-13 12:21     ` Marc-André Lureau
2017-03-13 13:12       ` Markus Armbruster
2017-03-14 13:22         ` Marc-André Lureau
2017-03-14 16:14           ` Markus Armbruster
2017-03-15 14:00             ` Marc-André Lureau
2017-03-14 13:24 ` Marc-André Lureau
2017-03-15 13:06   ` Markus Armbruster
2017-04-27 18:16 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489385927-6735-3-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.