From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"John Snow" <jsnow@redhat.com>
Subject: [PATCH v2 09/12] qapi/gen: move write method to QAPIGenC, make fname a str
Date: Wed, 16 Dec 2020 20:59:24 -0500 [thread overview]
Message-ID: <20201217015927.197287-10-jsnow@redhat.com> (raw)
In-Reply-To: <20201217015927.197287-1-jsnow@redhat.com>
QAPIGenC and QAPIGenH in particular depend on fname being defined, but
we have a usage of QAPIGenCCode that isn't intended to be associated
with a particular file.
No problem, move the write method down to the class that actually needs
it, and keep QAPIGenCCode more abstract.
Signed-off-by: John Snow <jsnow@redhat.com>
---
Possibly un-needed in concert with a forthcoming patch by Markus, but I
didn't have it in my hands at time of publishing.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/commands.py | 2 +-
scripts/qapi/gen.py | 54 ++++++++++++++++++++--------------------
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 71744f48a35..b346676d15a 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -258,7 +258,7 @@ def __init__(self, prefix: str):
super().__init__(
prefix, 'qapi-commands',
' * Schema-defined QAPI/QMP commands', None, __doc__)
- self._regy = QAPIGenCCode(None)
+ self._regy = QAPIGenCCode()
self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {}
def _begin_user_module(self, name: str) -> None:
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 12ea98fb61e..2dd99635e74 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -36,8 +36,7 @@
class QAPIGen:
- def __init__(self, fname: Optional[str]):
- self.fname = fname
+ def __init__(self) -> None:
self._preamble = ''
self._body = ''
@@ -58,28 +57,6 @@ def _bottom(self) -> str:
# pylint: disable=no-self-use
return ''
- def write(self, output_dir: str) -> None:
- # Include paths starting with ../ are used to reuse modules of the main
- # schema in specialised schemas. Don't overwrite the files that are
- # already generated for the main schema.
- if self.fname.startswith('../'):
- return
- pathname = os.path.join(output_dir, self.fname)
- odir = os.path.dirname(pathname)
-
- if odir:
- os.makedirs(odir, exist_ok=True)
-
- # use os.open for O_CREAT to create and read a non-existant file
- fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666)
- with os.fdopen(fd, 'r+', encoding='utf-8') as fp:
- text = self.get_content()
- oldtext = fp.read(len(text) + 1)
- if text != oldtext:
- fp.seek(0)
- fp.truncate(0)
- fp.write(text)
-
def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str:
if before == after:
@@ -121,8 +98,8 @@ def build_params(arg_type: Optional[QAPISchemaObjectType],
class QAPIGenCCode(QAPIGen):
- def __init__(self, fname: Optional[str]):
- super().__init__(fname)
+ def __init__(self) -> None:
+ super().__init__()
self._start_if: Optional[Tuple[List[str], str, str]] = None
def start_if(self, ifcond: List[str]) -> None:
@@ -147,11 +124,34 @@ def get_content(self) -> str:
class QAPIGenC(QAPIGenCCode):
def __init__(self, fname: str, blurb: str, pydoc: str):
- super().__init__(fname)
+ super().__init__()
+ self.fname = fname
self._blurb = blurb
self._copyright = '\n * '.join(re.findall(r'^Copyright .*', pydoc,
re.MULTILINE))
+ def write(self, output_dir: str) -> None:
+ # Include paths starting with ../ are used to reuse modules of the main
+ # schema in specialised schemas. Don't overwrite the files that are
+ # already generated for the main schema.
+ if self.fname.startswith('../'):
+ return
+ pathname = os.path.join(output_dir, self.fname)
+ odir = os.path.dirname(pathname)
+
+ if odir:
+ os.makedirs(odir, exist_ok=True)
+
+ # use os.open for O_CREAT to create and read a non-existant file
+ fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666)
+ with os.fdopen(fd, 'r+', encoding='utf-8') as fp:
+ text = self.get_content()
+ oldtext = fp.read(len(text) + 1)
+ if text != oldtext:
+ fp.seek(0)
+ fp.truncate(0)
+ fp.write(text)
+
def _top(self) -> str:
return mcgen('''
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
--
2.26.2
next prev parent reply other threads:[~2020-12-17 2:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 1:59 [PATCH v2 00/12] qapi: static typing conversion, pt1.5 John Snow
2020-12-17 1:59 ` [PATCH v2 01/12] qapi/commands: assert arg_type is not None John Snow
2020-12-17 1:59 ` [PATCH v2 02/12] qapi/events: fix visit_event typing John Snow
2020-12-17 1:59 ` [PATCH v2 03/12] qapi/main: handle theoretical None-return from re.match() John Snow
2020-12-17 1:59 ` [PATCH v2 04/12] qapi/gen: assert that _start_if is not None in _wrap_ifcond John Snow
2021-01-13 15:14 ` Markus Armbruster
2021-01-13 21:34 ` John Snow
2020-12-17 1:59 ` [PATCH v2 05/12] qapi/gen: use './builtin' for the built-in module name John Snow
2020-12-17 1:59 ` [PATCH v2 06/12] qapi/source: Add builtin null-object sentinel John Snow
2021-01-13 15:39 ` Markus Armbruster
2021-01-13 22:30 ` John Snow
2021-01-14 13:39 ` Markus Armbruster
2021-01-18 18:36 ` Eduardo Habkost
2021-01-19 10:21 ` Markus Armbruster
2021-01-19 16:10 ` Eduardo Habkost
2020-12-17 1:59 ` [PATCH v2 07/12] qapi/schema: make QAPISourceInfo mandatory John Snow
2021-01-13 16:12 ` Markus Armbruster
2021-01-13 23:04 ` John Snow
2021-01-14 0:29 ` Eduardo Habkost
2021-01-14 0:47 ` John Snow
2020-12-17 1:59 ` [PATCH v2 08/12] qapi/gen: write _genc/_genh access shims John Snow
2020-12-17 1:59 ` John Snow [this message]
2020-12-17 1:59 ` [PATCH v2 10/12] tests/qapi-schema: Add quotes to module name in test output John Snow
2020-12-17 1:59 ` [PATCH v2 11/12] qapi/schema: Name the builtin module "" instead of None John Snow
2020-12-17 1:59 ` [PATCH v2 12/12] qapi: enable strict-optional checks John Snow
2021-01-13 16:23 ` [PATCH v2 00/12] qapi: static typing conversion, pt1.5 Markus Armbruster
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=20201217015927.197287-10-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.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.