From nobody Thu Nov 6 16:03:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489386306493812.642287546164; Sun, 12 Mar 2017 23:25:06 -0700 (PDT) Received: from localhost ([::1]:50376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJPl-0003M7-2t for importer@patchew.org; Mon, 13 Mar 2017 02:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJJm-0007XQ-9B for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnJJj-0003Yc-SO for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnJJj-0003XO-Jb for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:51 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C779B7E9C9; Mon, 13 Mar 2017 06:18:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2D6IoxS023380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 02:18:51 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2CA8A11386DC; Mon, 13 Mar 2017 07:18:47 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 13 Mar 2017 07:18:06 +0100 Message-Id: <1489385927-6735-7-git-send-email-armbru@redhat.com> In-Reply-To: <1489385927-6735-1-git-send-email-armbru@redhat.com> References: <1489385927-6735-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 13 Mar 2017 06:18:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 06/47] qapi: Have each QAPI schema declare its name rule violations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake --- docs/qapi-code-gen.txt | 6 ++++++ qapi-schema.json | 11 ++++++++++- scripts/qapi.py | 22 ++++++++++------------ tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/enum-member-case.json | 1 + 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index e907e57..349dc02 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -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. =20 +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 @@ -318,6 +321,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. =20 +Pragma 'name-case-whitelist' takes a list of names that may violate +rules on use of upper- vs. lower-case letters. Default is none. + =20 =3D=3D=3D Struct types =3D=3D=3D =20 diff --git a/qapi-schema.json b/qapi-schema.json index 93e9e98..17c766e 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -61,7 +61,16 @@ 'query-migrate-cache-size', 'query-tpm-models', 'query-tpm-types', - 'ringbuf-read' ] } } + 'ringbuf-read' ], + 'name-case-whitelist': [ + 'ACPISlotType', # DIMM, visible through query-acpi-ospm-st= atus + '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 + ] } } =20 # QAPI common definitions { 'include': 'qapi/common.json' } diff --git a/scripts/qapi.py b/scripts/qapi.py index a90b682..e98fd0c 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -44,16 +44,7 @@ doc_required =3D False returns_whitelist =3D [] =20 # Whitelist of entities allowed to violate case conventions -case_whitelist =3D [ - # 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 =3D [] =20 enum_types =3D [] struct_types =3D [] @@ -298,7 +289,7 @@ class QAPISchemaParser(object): self.docs.extend(exprs_include.docs) =20 def _pragma(self, name, value, info): - global doc_required, returns_whitelist + global doc_required, returns_whitelist, name_case_whitelist if name =3D=3D 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, @@ -311,6 +302,13 @@ class QAPISchemaParser(object): "Pragma returns-whitelist must be" " a list of strings") returns_whitelist =3D value + elif name =3D=3D '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 =3D value else: raise QAPISemError(info, "Unknown pragma '%s'" % name) =20 @@ -1283,7 +1281,7 @@ class QAPISchemaMember(object): =20 def check_clash(self, info, seen): cname =3D c_name(self.name) - if cname.lower() !=3D cname and self.owner not in case_whitelist: + if cname.lower() !=3D cname and self.owner not in name_case_whitel= ist: raise QAPISemError(info, "%s should not use uppercase" % self.descri= be()) if cname in seen: diff --git a/tests/qapi-schema/enum-member-case.err b/tests/qapi-schema/enu= m-member-case.err index b652e9a..3c67a3a 100644 --- a/tests/qapi-schema/enum-member-case.err +++ b/tests/qapi-schema/enum-member-case.err @@ -1 +1 @@ -tests/qapi-schema/enum-member-case.json:3: 'Value' (member of NoWayThisWil= lGetWhitelisted) should not use uppercase +tests/qapi-schema/enum-member-case.json:4: 'Value' (member of NoWayThisWil= lGetWhitelisted) should not use uppercase diff --git a/tests/qapi-schema/enum-member-case.json b/tests/qapi-schema/en= um-member-case.json index 2096b35..f8af3e4 100644 --- a/tests/qapi-schema/enum-member-case.json +++ b/tests/qapi-schema/enum-member-case.json @@ -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' ] } --=20 2.7.4