qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 17/36] qapi/common.py: move build_params into gen.py


From: John Snow
Subject: Re: [PATCH v5 17/36] qapi/common.py: move build_params into gen.py
Date: Wed, 7 Oct 2020 11:26:45 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 10/7/20 5:21 AM, Markus Armbruster wrote:
John Snow <jsnow@redhat.com> writes:

Including it in common.py creates a circular import dependency; schema
relies on common, but common.build_params requires a type annotation
from schema. To type this properly, it needs to be moved outside the
cycle.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
---
  scripts/qapi/commands.py |  9 +++++++--
  scripts/qapi/common.py   | 23 -----------------------
  scripts/qapi/events.py   |  9 ++-------
  scripts/qapi/gen.py      | 31 +++++++++++++++++++++++++++++--
  4 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 5dc2f5a9fa8..f67393f8713 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -13,8 +13,13 @@
  See the COPYING file in the top-level directory.
  """
-from .common import build_params, c_name, mcgen
-from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext
+from .common import c_name, mcgen
+from .gen import (
+    QAPIGenCCode,
+    QAPISchemaModularCVisitor,
+    build_params,
+    ifcontext,
+)
def gen_command_decl(name, arg_type, boxed, ret_type):
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 0ef38ea5fe0..9ab0685cc51 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -209,26 +209,3 @@ def gen_endif(ifcond: Sequence[str]) -> str:
  #endif /* %(cond)s */
  ''', cond=ifc)
      return ret
-
-
-def build_params(arg_type,
-                 boxed: bool,
-                 extra: Optional[str] = None) -> str:
-    ret = ''
-    sep = ''
-    if boxed:
-        assert arg_type
-        ret += '%s arg' % arg_type.c_param_type()
-        sep = ', '
-    elif arg_type:
-        assert not arg_type.variants
-        for memb in arg_type.members:
-            ret += sep
-            sep = ', '
-            if memb.optional:
-                ret += 'bool has_%s, ' % c_name(memb.name)
-            ret += '%s %s' % (memb.type.c_param_type(),
-                              c_name(memb.name))
-    if extra:
-        ret += sep + extra
-    return ret if ret else 'void'
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index 6b3afa14d72..f840a62ed92 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -12,13 +12,8 @@
  See the COPYING file in the top-level directory.
  """
-from .common import (
-    build_params,
-    c_enum_const,
-    c_name,
-    mcgen,
-)
-from .gen import QAPISchemaModularCVisitor, ifcontext
+from .common import c_enum_const, c_name, mcgen
+from .gen import QAPISchemaModularCVisitor, build_params, ifcontext
  from .schema import QAPISchemaEnumMember
  from .types import gen_enum, gen_enum_lookup
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 1fed712b43b..f2e2746fea5 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -2,9 +2,11 @@
  #
  # QAPI code generation
  #
-# Copyright (c) 2018-2019 Red Hat Inc.
+# Copyright IBM, Corp. 2011
+# Copyright (c) 2013-2019 Red Hat Inc.
  #
  # Authors:
+#  Anthony Liguori <aliguori@us.ibm.com>
  #  Markus Armbruster <armbru@redhat.com>
  #  Marc-André Lureau <marcandre.lureau@redhat.com>
  #

The code you move into this file is actually Red Hat's:

$ git-log -L174,193:scripts/qapi/common.py master| egrep 'Author|Date'
Author: Markus Armbruster <armbru@redhat.com>
Date:   Wed Aug 15 21:37:36 2018 +0800
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date:   Thu Jun 1 16:41:41 2017 +0400
Author: Eric Blake <eblake@redhat.com>
Date:   Wed Jul 13 21:50:20 2016 -0600
Author: Eric Blake <eblake@redhat.com>
Date:   Wed Jul 13 21:50:19 2016 -0600
Author: Eric Blake <eblake@redhat.com>
Date:   Thu Mar 17 16:48:28 2016 -0600
Author: Markus Armbruster <armbru@redhat.com>
Date:   Wed Sep 16 13:06:20 2015 +0200

So the correct update is simply

    #
    # QAPI code generation
    #
   -# Copyright (c) 2018-2019 Red Hat Inc.
   +# Copyright (c) 2015-2019 Red Hat Inc.
    #
    # Authors:
    #  Markus Armbruster <armbru@redhat.com>
    #  Marc-André Lureau <marcandre.lureau@redhat.com>
    #


OK, thank you. I did the dumbest possibly correct thing. My appetite for doing line ownership analysis is ... low.

@@ -15,16 +17,18 @@
  import errno
  import os
  import re
+from typing import Optional
from .common import (
      c_fname,
+    c_name,
      gen_endif,
      gen_if,
      guardend,
      guardstart,
      mcgen,
  )
-from .schema import QAPISchemaVisitor
+from .schema import QAPISchemaObjectType, QAPISchemaVisitor
class QAPIGen:
@@ -90,6 +94,29 @@ def _wrap_ifcond(ifcond, before, after):
      return out
+def build_params(arg_type: Optional[QAPISchemaObjectType],
+                 boxed: bool,
+                 extra: Optional[str] = None) -> str:
+    ret = ''
+    sep = ''
+    if boxed:
+        assert arg_type
+        ret += '%s arg' % arg_type.c_param_type()
+        sep = ', '
+    elif arg_type:
+        assert not arg_type.variants
+        for memb in arg_type.members:
+            ret += sep
+            sep = ', '
+            if memb.optional:
+                ret += 'bool has_%s, ' % c_name(memb.name)
+            ret += '%s %s' % (memb.type.c_param_type(),
+                              c_name(memb.name))
+    if extra:
+        ret += sep + extra
+    return ret if ret else 'void'
+
+
  class QAPIGenCCode(QAPIGen):
def __init__(self, fname):




reply via email to

[Prev in Thread] Current Thread [Next in Thread]