]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qapi: Have each QAPI schema declare its name rule violations
authorMarkus Armbruster <armbru@redhat.com>
Wed, 15 Mar 2017 12:56:55 +0000 (13:56 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 16 Mar 2017 06:13:02 +0000 (07:13 +0100)
qapi.py has a hardcoded white-list of type names that may violate the
rule on use of upper and lower case.  Add a new pragma directive
'name-case-whitelist', and use it to replace the hard-coded
white-list.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1489582656-31133-7-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
docs/qapi-code-gen.txt
qapi-schema.json
scripts/qapi.py
tests/Makefile.include
tests/qapi-schema/enum-member-case.err
tests/qapi-schema/enum-member-case.json
tests/qapi-schema/pragma-name-case-whitelist-crap.err [new file with mode: 0644]
tests/qapi-schema/pragma-name-case-whitelist-crap.exit [new file with mode: 0644]
tests/qapi-schema/pragma-name-case-whitelist-crap.json [new file with mode: 0644]
tests/qapi-schema/pragma-name-case-whitelist-crap.out [new file with mode: 0644]

index 3d17005cf6c4404757fd66bc79255009c4e6e933..2f67900b4c02025293f8e01eae18c5ddd31c8dbc 100644 (file)
@@ -252,6 +252,9 @@ Any name (command, event, type, member, or enum value) beginning with
 "x-" is marked experimental, and may be withdrawn or changed
 incompatibly in a future release.
 
+Pragma 'name-case-whitelist' lets you violate the rules on use of
+upper and lower case.  Use for new code is strongly discouraged.
+
 In the rest of this document, usage lines are given for each
 expression type, with literal strings written in lower case and
 placeholders written in capitals.  If a literal string includes a
@@ -321,6 +324,9 @@ is required.  Default is false.
 Pragma 'returns-whitelist' takes a list of command names that may
 violate the rules on permitted return types.  Default is none.
 
+Pragma 'name-case-whitelist' takes a list of names that may violate
+rules on use of upper- vs. lower-case letters.  Default is none.
+
 
 === Struct types ===
 
index 93e9e98b0b62ef0fe3969eaa6eec95eb3f9ddebd..17c766ee3b3c21304ac1f011be3a90a613a79ee6 100644 (file)
         'query-migrate-cache-size',
         'query-tpm-models',
         'query-tpm-types',
-        'ringbuf-read' ] } }
+        'ringbuf-read' ],
+    'name-case-whitelist': [
+        'ACPISlotType',         # DIMM, visible through query-acpi-ospm-status
+        'CpuInfoMIPS',          # PC, visible through query-cpu
+        'CpuInfoTricore',       # PC, visible through query-cpu
+        'QapiErrorClass',       # all members, visible through errors
+        'UuidInfo',             # UUID, visible through query-uuid
+        'X86CPURegister32',     # all members, visible indirectly through qom-get
+        'q_obj_CpuInfo-base'    # CPU, visible through query-cpu
+    ] } }
 
 # QAPI common definitions
 { 'include': 'qapi/common.json' }
index 1d86d85d495768d1b26b46227c45b5778705eacc..78db319831c802fd3610d36faeee656e8905fa08 100644 (file)
@@ -44,16 +44,7 @@ doc_required = False
 returns_whitelist = []
 
 # Whitelist of entities allowed to violate case conventions
-case_whitelist = [
-    # From QMP:
-    'ACPISlotType',         # DIMM, visible through query-acpi-ospm-status
-    'CpuInfoMIPS',          # PC, visible through query-cpu
-    'CpuInfoTricore',       # PC, visible through query-cpu
-    'QapiErrorClass',       # all members, visible through errors
-    'UuidInfo',             # UUID, visible through query-uuid
-    'X86CPURegister32',     # all members, visible indirectly through qom-get
-    'q_obj_CpuInfo-base',   # CPU, visible through query-cpu
-]
+name_case_whitelist = []
 
 enum_types = []
 struct_types = []
@@ -302,7 +293,7 @@ class QAPISchemaParser(object):
         self.docs.extend(exprs_include.docs)
 
     def _pragma(self, name, value, info):
-        global doc_required, returns_whitelist
+        global doc_required, returns_whitelist, name_case_whitelist
         if name == 'doc-required':
             if not isinstance(value, bool):
                 raise QAPISemError(info,
@@ -315,6 +306,13 @@ class QAPISchemaParser(object):
                                    "Pragma returns-whitelist must be"
                                    " a list of strings")
             returns_whitelist = value
+        elif name == 'name-case-whitelist':
+            if (not isinstance(value, list)
+                    or any([not isinstance(elt, str) for elt in value])):
+                raise QAPISemError(info,
+                                   "Pragma name-case-whitelist must be"
+                                   " a list of strings")
+            name_case_whitelist = value
         else:
             raise QAPISemError(info, "Unknown pragma '%s'" % name)
 
@@ -1287,7 +1285,7 @@ class QAPISchemaMember(object):
 
     def check_clash(self, info, seen):
         cname = c_name(self.name)
-        if cname.lower() != cname and self.owner not in case_whitelist:
+        if cname.lower() != cname and self.owner not in name_case_whitelist:
             raise QAPISemError(info,
                                "%s should not use uppercase" % self.describe())
         if cname in seen:
index f9da3aa2d47b9d9b42a5ed9c9037e5635cd8e6ec..16e0a9f615b8b3fddbb29903ef0958485d7e4548 100644 (file)
@@ -443,6 +443,7 @@ qapi-schema += nested-struct-data.json
 qapi-schema += non-objects.json
 qapi-schema += pragma-doc-required-crap.json
 qapi-schema += pragma-extra-junk.json
+qapi-schema += pragma-name-case-whitelist-crap.json
 qapi-schema += pragma-non-dict.json
 qapi-schema += pragma-returns-whitelist-crap.json
 qapi-schema += qapi-schema-test.json
index b652e9aacc10c9dd261404919138468934510223..3c67a3a067e47ae6b85408778e6ba1d8de08156a 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/enum-member-case.json:3: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase
+tests/qapi-schema/enum-member-case.json:4: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase
index 2096b350cae9f9ccad1a64aa462a604d017c7a4e..f8af3e4622e4c02bf979916a120eb05d0dc2c0b2 100644 (file)
@@ -1,3 +1,4 @@
 # Member names should be 'lower-case' unless the enum is whitelisted
+{ 'pragma': { 'name-case-whitelist': [ 'UuidInfo' ] } }
 { 'enum': 'UuidInfo', 'data': [ 'Value' ] } # UuidInfo is whitelisted
 { 'enum': 'NoWayThisWillGetWhitelisted', 'data': [ 'Value' ] }
diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.err b/tests/qapi-schema/pragma-name-case-whitelist-crap.err
new file mode 100644 (file)
index 0000000..f83b97e
--- /dev/null
@@ -0,0 +1 @@
+tests/qapi-schema/pragma-name-case-whitelist-crap.json:3: Pragma name-case-whitelist must be a list of strings
diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.exit b/tests/qapi-schema/pragma-name-case-whitelist-crap.exit
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.json b/tests/qapi-schema/pragma-name-case-whitelist-crap.json
new file mode 100644 (file)
index 0000000..58382bf
--- /dev/null
@@ -0,0 +1,3 @@
+# 'name-case-whitelist' must be list of strings
+
+{ 'pragma': { 'name-case-whitelist': null } }
diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.out b/tests/qapi-schema/pragma-name-case-whitelist-crap.out
new file mode 100644 (file)
index 0000000..e69de29