From nobody Mon Feb 9 14:38:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815659; cv=none; d=zohomail.com; s=zohoarc; b=SvqmkOj3E809k6BK2xcrySlbjOP3E/Yj9xXAE+6GbD5sLsS5Wv3t2iVdSTu9G5TH4FLp8fYI5NNLc8tpy/URr6+WAnjqUNnXCFtKTP65Q6GxZx77LqzXRDN7ukgvbNVJK/I/ckPCdwc6a0OXevHzJ9YkRffRGLXnGRU/U6vvw08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815659; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h2lG645VUDvw4MeZiKdOV5d8kEiTYqWGbD4d/AaUV/Y=; b=Y6sDfRqSvZ32v59a98Ie2NnSnO554M9XAE+VHhJYgzY2vjt8XAMP6+ybjzDw5Vj5YC+REzcaihaEasfZ+xSaE7S53eOKYxE0RQfJLfG9ugjKJKjYsKtTqkpoTkdMKnk/CxZ4yrQCynLhECNhfPJX15EGEj+SiowuxJYIGGp8VeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16128156594535.79547320682093; Mon, 8 Feb 2021 12:20:59 -0800 (PST) Received: from localhost ([::1]:36068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9D1m-0007nt-7o for importer@patchew.org; Mon, 08 Feb 2021 15:20:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974Q-0005cU-Nl for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44429) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0001dJ-P4 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-531-w5nQwg0XN2OssL2q-3wt0w-1; Mon, 08 Feb 2021 08:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1AED107ACE3; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D62E101E243; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 646A41132CB1; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h2lG645VUDvw4MeZiKdOV5d8kEiTYqWGbD4d/AaUV/Y=; b=IeupjSoitiBbBP/mXEzT5ferEHMW/JYGeyQt7phaGTqrA1D13ulf+qzLoU1ibTDCyAdv7q fvJMu+lOQLnFNECS9/KpW9w+tN96eAdvq+VNNlUeT/4aXg6fyzwa4Tg8QYO9OUTdFadwGA PoR0nWXv6xr6FOgfQAckGlnN8BwMKcw= X-MC-Unique: w5nQwg0XN2OssL2q-3wt0w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/16] qapi: use './builtin' as the built-in module name Date: Mon, 8 Feb 2021 14:58:38 +0100 Message-Id: <20210208135846.3707170-9-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Use './builtin' as the built-in module name instead of None. Clarify the typing that this is now always a string. Signed-off-by: John Snow Message-Id: <20210201193747.2169670-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/gen.py | 18 +++++++++--------- scripts/qapi/schema.py | 20 ++++++++++---------- tests/qapi-schema/comments.out | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/empty.out | 2 +- tests/qapi-schema/event-case.out | 2 +- tests/qapi-schema/include-repetition.out | 2 +- tests/qapi-schema/include-simple.out | 2 +- tests/qapi-schema/indented-expr.out | 2 +- tests/qapi-schema/qapi-schema-test.out | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index da9d4d2d37..9352d79c3a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -246,16 +246,16 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._pydoc =3D pydoc self._genc: Optional[QAPIGenC] =3D None self._genh: Optional[QAPIGenH] =3D None - self._module: Dict[Optional[str], Tuple[QAPIGenC, QAPIGenH]] =3D {} + self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] =3D {} self._main_module: Optional[str] =3D None =20 @staticmethod - def _module_dirname(name: Optional[str]) -> str: + def _module_dirname(name: str) -> str: if QAPISchemaModule.is_user_module(name): return os.path.dirname(name) return '' =20 - def _module_basename(self, what: str, name: Optional[str]) -> str: + def _module_basename(self, what: str, name: str) -> str: ret =3D '' if QAPISchemaModule.is_builtin_module(name) else self._= prefix if QAPISchemaModule.is_user_module(name): basename =3D os.path.basename(name) @@ -263,15 +263,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): if name !=3D self._main_module: ret +=3D '-' + os.path.splitext(basename)[0] else: - name =3D name[2:] if name else 'builtin' - ret +=3D re.sub(r'-', '-' + name + '-', what) + assert QAPISchemaModule.is_system_module(name) + ret +=3D re.sub(r'-', '-' + name[2:] + '-', what) return ret =20 - def _module_filename(self, what: str, name: Optional[str]) -> str: + def _module_filename(self, what: str, name: str) -> str: return os.path.join(self._module_dirname(name), self._module_basename(what, name)) =20 - def _add_module(self, name: Optional[str], blurb: str) -> None: + def _add_module(self, name: str, blurb: str) -> None: basename =3D self._module_filename(self._what, name) genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) @@ -284,7 +284,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._main_module =3D name self._add_module(name, blurb) =20 - def _add_system_module(self, name: Optional[str], blurb: str) -> None: + def _add_system_module(self, name: str, blurb: str) -> None: assert QAPISchemaModule.is_system_module(name) self._add_module(name, blurb) =20 @@ -302,7 +302,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): def _begin_user_module(self, name: str) -> None: pass =20 - def visit_module(self, name: Optional[str]) -> None: + def visit_module(self, name: str) -> None: if QAPISchemaModule.is_builtin_module(name): if self._builtin_blurb: self._add_system_module(name, self._builtin_blurb) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index e80d9320ed..14cf9da784 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,8 @@ class QAPISchemaEntity: =20 def _set_module(self, schema, info): assert self._checked - self._module =3D schema.module_by_fname(info and info.fname) + fname =3D info.fname if info else './builtin' + self._module =3D schema.module_by_fname(fname) self._module.add_entity(self) =20 def set_module(self, schema): @@ -142,16 +143,16 @@ class QAPISchemaModule: self._entity_list =3D [] =20 @staticmethod - def is_system_module(name: Optional[str]) -> bool: + def is_system_module(name: str) -> bool: """ System modules are internally defined modules. =20 Their names start with the "./" prefix. """ - return name is None or name.startswith('./') + return name.startswith('./') =20 @classmethod - def is_user_module(cls, name: Optional[str]) -> bool: + def is_user_module(cls, name: str) -> bool: """ User modules are those defined by the user in qapi JSON files. =20 @@ -160,13 +161,13 @@ class QAPISchemaModule: return not cls.is_system_module(name) =20 @staticmethod - def is_builtin_module(name: Optional[str]) -> bool: + def is_builtin_module(name: str) -> bool: """ The built-in module is a single System module for the built-in typ= es. =20 - It is presently always the value 'None'. + It is always "./builtin". """ - return name is None + return name =3D=3D './builtin' =20 def add_entity(self, ent): self._entity_list.append(ent) @@ -852,7 +853,7 @@ class QAPISchema: self._entity_dict =3D {} self._module_dict =3D OrderedDict() self._schema_dir =3D os.path.dirname(fname) - self._make_module(None) # built-ins + self._make_module('./builtin') self._make_module(fname) self._predefining =3D True self._def_predefineds() @@ -897,7 +898,7 @@ class QAPISchema: info, "%s uses unknown type '%s'" % (what, name)) return typ =20 - def _module_name(self, fname): + def _module_name(self, fname: str) -> str: if QAPISchemaModule.is_system_module(fname): return fname return os.path.relpath(fname, self._schema_dir) @@ -910,7 +911,6 @@ class QAPISchema: =20 def module_by_fname(self, fname): name =3D self._module_name(fname) - assert name in self._module_dict return self._module_dict[name] =20 def _def_include(self, expr, info, doc): diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 273f0f54e1..ce4f6a4f0f 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 419284dae2..715b0bbc1a 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 69666c39ad..3feb3f69d3 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-cas= e.out index 42ae519656..9ae44052ac 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/i= nclude-repetition.out index 0b654ddebb..16dbd9b819 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/inclu= de-simple.out index 061f81e509..48e923bfbc 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indent= ed-expr.out index 04356775cd..6a30ded3fa 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8868ca0dca..3b1387d9f1 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE --=20 2.26.2